@@ -38,8 +38,12 @@ export class Variants {
38
38
*/
39
39
private lastOrder = 0
40
40
41
- static ( name : string , applyFn : VariantFn < 'static' > , { compounds } : { compounds ?: boolean } = { } ) {
42
- this . set ( name , { kind : 'static' , applyFn, compounds : compounds ?? true } )
41
+ static (
42
+ name : string ,
43
+ applyFn : VariantFn < 'static' > ,
44
+ { compounds, order } : { compounds ?: boolean ; order ?: number } = { } ,
45
+ ) {
46
+ this . set ( name , { kind : 'static' , applyFn, compounds : compounds ?? true , order } )
43
47
}
44
48
45
49
fromAst ( name : string , ast : AstNode [ ] ) {
@@ -53,17 +57,17 @@ export class Variants {
53
57
functional (
54
58
name : string ,
55
59
applyFn : VariantFn < 'functional' > ,
56
- { compounds } : { compounds ?: boolean } = { } ,
60
+ { compounds, order } : { compounds ?: boolean ; order ?: number } = { } ,
57
61
) {
58
- this . set ( name , { kind : 'functional' , applyFn, compounds : compounds ?? true } )
62
+ this . set ( name , { kind : 'functional' , applyFn, compounds : compounds ?? true , order } )
59
63
}
60
64
61
65
compound (
62
66
name : string ,
63
67
applyFn : VariantFn < 'compound' > ,
64
- { compounds } : { compounds ?: boolean } = { } ,
68
+ { compounds, order } : { compounds ?: boolean ; order ?: number } = { } ,
65
69
) {
66
- this . set ( name , { kind : 'compound' , applyFn, compounds : compounds ?? true } )
70
+ this . set ( name , { kind : 'compound' , applyFn, compounds : compounds ?? true , order } )
67
71
}
68
72
69
73
group ( fn : ( ) => void , compareFn ?: CompareFn ) {
@@ -136,17 +140,25 @@ export class Variants {
136
140
137
141
private set < T extends Variant [ 'kind' ] > (
138
142
name : string ,
139
- { kind, applyFn, compounds } : { kind : T ; applyFn : VariantFn < T > ; compounds : boolean } ,
143
+ {
144
+ kind,
145
+ applyFn,
146
+ compounds,
147
+ order,
148
+ } : { kind : T ; applyFn : VariantFn < T > ; compounds : boolean ; order ?: number } ,
140
149
) {
141
150
let existing = this . variants . get ( name )
142
151
if ( existing ) {
143
152
Object . assign ( existing , { kind, applyFn, compounds } )
144
153
} else {
145
- this . lastOrder = this . nextOrder ( )
154
+ if ( order === undefined ) {
155
+ this . lastOrder = this . nextOrder ( )
156
+ order = this . lastOrder
157
+ }
146
158
this . variants . set ( name , {
147
159
kind,
148
160
applyFn,
149
- order : this . lastOrder ,
161
+ order,
150
162
compounds,
151
163
} )
152
164
}
0 commit comments