import { getRule } from './RulesRegistry' ; import flatten from './utils/flatten' ; import { RecursiveArray , Indexable } from './utils/types' ; import { Rule } from './Rule' ; export type Basic = string | boolean | null | undefined | number ; export default function resolveStyles ( styles , resolveMap = { } ) { let flatStyles = flatten ( Array . isArray ( styles ) ? styles : [ styles ] ) ; resolveMap = resolveMap || { } ; const rules = [ ] ; for ( let i = flatStyles . length - 1 ; i >= 0 ; i -- ) { const ruleId = flatStyles [ i ] ; if ( ruleId ) { if ( typeof ruleId !== 'string' ) { throw new Error ( 'TODO' ) ; } if ( ! resolveMap [ ruleId ] ) { resolveMap [ ruleId ] = true ; const rule = getRule ( ruleId ) ; if ( ! rule ) { throw new Error ( 'TODO' ) ; } rules . push ( rule ) ; if ( rule . dependencies ) { rules . push . apply ( rules , resolveStyles ( rule . dependencies , resolveMap ) . reverse ( ) ) ; } } } } return rules . reverse ( ) ; }