@@ -12,6 +12,8 @@ type Condition = {
1212 children : ConditionalRuleset ;
1313} ;
1414
15+ type RenderedConditionalRule = Record < string , Record < string , any > > ;
16+
1517export class ConditionalRuleset {
1618 ruleset : Map < Query , Condition > ;
1719
@@ -27,7 +29,7 @@ export class ConditionalRuleset {
2729 this . precedenceLookup = new Map ( ) ;
2830 }
2931
30- findOrCreateCondition ( conditionQuery : Query ) {
32+ findOrCreateCondition ( conditionQuery : Query ) : Condition {
3133 let targetCondition = this . ruleset . get ( conditionQuery ) ;
3234
3335 if ( ! targetCondition ) {
@@ -43,7 +45,7 @@ export class ConditionalRuleset {
4345 return targetCondition ;
4446 }
4547
46- getConditionalRulesetByPath ( conditionPath : Array < Query > ) {
48+ getConditionalRulesetByPath ( conditionPath : Array < Query > ) : ConditionalRuleset {
4749 let currRuleset : ConditionalRuleset = this ;
4850
4951 for ( const query of conditionPath ) {
@@ -55,7 +57,11 @@ export class ConditionalRuleset {
5557 return currRuleset ;
5658 }
5759
58- addRule ( rule : Rule , conditionQuery : Query , conditionPath : Array < Query > ) {
60+ addRule (
61+ rule : Rule ,
62+ conditionQuery : Query ,
63+ conditionPath : Array < Query > ,
64+ ) : void {
5965 const ruleset = this . getConditionalRulesetByPath ( conditionPath ) ;
6066 const targetCondition = ruleset . findOrCreateCondition ( conditionQuery ) ;
6167
@@ -69,7 +75,7 @@ export class ConditionalRuleset {
6975 addConditionPrecedence (
7076 conditionPath : Array < Query > ,
7177 conditionOrder : Array < Query > ,
72- ) {
78+ ) : void {
7379 const ruleset = this . getConditionalRulesetByPath ( conditionPath ) ;
7480
7581 for ( let i = 0 ; i < conditionOrder . length ; i ++ ) {
@@ -86,7 +92,7 @@ export class ConditionalRuleset {
8692 }
8793 }
8894
89- isCompatible ( incomingRuleset : ConditionalRuleset ) {
95+ isCompatible ( incomingRuleset : ConditionalRuleset ) : boolean {
9096 for ( const [
9197 condition ,
9298 orderPrecedence ,
@@ -117,7 +123,7 @@ export class ConditionalRuleset {
117123 return true ;
118124 }
119125
120- merge ( incomingRuleset : ConditionalRuleset ) {
126+ merge ( incomingRuleset : ConditionalRuleset ) : void {
121127 // Merge rulesets into one array
122128 for ( const { query, rules, children } of incomingRuleset . ruleset . values ( ) ) {
123129 const matchingCondition = this . ruleset . get ( query ) ;
@@ -150,7 +156,7 @@ export class ConditionalRuleset {
150156 *
151157 * @returns true if successful, false if the ruleset is incompatible
152158 */
153- mergeIfCompatible ( incomingRuleset : ConditionalRuleset ) {
159+ mergeIfCompatible ( incomingRuleset : ConditionalRuleset ) : boolean {
154160 if ( ! this . isCompatible ( incomingRuleset ) ) {
155161 return false ;
156162 }
@@ -160,7 +166,7 @@ export class ConditionalRuleset {
160166 return true ;
161167 }
162168
163- getSortedRuleset ( ) {
169+ getSortedRuleset ( ) : Condition [ ] {
164170 const sortedRuleset : Array < Condition > = [ ] ;
165171
166172 // Loop through all queries and add them to the sorted ruleset
@@ -189,11 +195,11 @@ export class ConditionalRuleset {
189195 return sortedRuleset ;
190196 }
191197
192- renderToArray ( ) {
193- const arr : any = [ ] ;
198+ renderToArray ( ) : RenderedConditionalRule [ ] {
199+ const arr : RenderedConditionalRule [ ] = [ ] ;
194200
195201 for ( const { query, rules, children } of this . getSortedRuleset ( ) ) {
196- const selectors : any = { } ;
202+ const selectors : Record < string , any > = { } ;
197203
198204 for ( const rule of rules ) {
199205 selectors [ rule . selector ] = {
0 commit comments