@@ -17,17 +17,17 @@ function getClassNameFromSelector(selector) {
17
17
// ['ring-offset', 'blue-100']
18
18
// ['ring', 'offset-blue-100']
19
19
function * candidatePermutations ( prefix , modifier = '' ) {
20
- yield [ prefix , modifier ]
21
-
22
20
let dashIdx = prefix . lastIndexOf ( '-' )
23
21
if ( dashIdx === - 1 ) {
24
22
return
25
23
}
26
24
27
- yield * candidatePermutations (
28
- prefix . slice ( 0 , dashIdx ) ,
29
- [ prefix . slice ( dashIdx + 1 ) , modifier ] . filter ( Boolean ) . join ( '-' )
30
- )
25
+ modifier = [ prefix . slice ( dashIdx + 1 ) , modifier ] . filter ( Boolean ) . join ( '-' )
26
+ prefix = prefix . slice ( 0 , dashIdx )
27
+
28
+ yield [ prefix , modifier ]
29
+
30
+ yield * candidatePermutations ( prefix , modifier )
31
31
}
32
32
33
33
// Takes a list of rule tuples and applies a variant like `hover`, sm`,
@@ -109,9 +109,9 @@ function parseRules(rule, cache, options = {}) {
109
109
return [ cache . get ( rule ) , options ]
110
110
}
111
111
112
- function resolveMatchedPlugins ( classCandidate , context ) {
112
+ function * resolveMatchedPlugins ( classCandidate , context ) {
113
113
if ( context . candidateRuleMap . has ( classCandidate ) ) {
114
- return [ context . candidateRuleMap . get ( classCandidate ) , 'DEFAULT' ]
114
+ yield [ context . candidateRuleMap . get ( classCandidate ) , 'DEFAULT' ]
115
115
}
116
116
117
117
let candidatePrefix = classCandidate
@@ -124,11 +124,10 @@ function resolveMatchedPlugins(classCandidate, context) {
124
124
125
125
for ( let [ prefix , modifier ] of candidatePermutations ( candidatePrefix ) ) {
126
126
if ( context . candidateRuleMap . has ( prefix ) ) {
127
- return [ context . candidateRuleMap . get ( prefix ) , negative ? `-${ modifier } ` : modifier ]
127
+ yield [ context . candidateRuleMap . get ( prefix ) , negative ? `-${ modifier } ` : modifier ]
128
+ return
128
129
}
129
130
}
130
-
131
- return null
132
131
}
133
132
134
133
function sortAgainst ( toSort , against ) {
@@ -137,55 +136,53 @@ function sortAgainst(toSort, against) {
137
136
} )
138
137
}
139
138
140
- function resolveMatches ( candidate , context ) {
139
+ function * resolveMatches ( candidate , context ) {
141
140
let [ classCandidate , ...variants ] = candidate . split ( ':' ) . reverse ( )
142
141
143
142
// Strip prefix
144
143
// md:hover:tw-bg-black
145
144
146
- let matchedPlugins = resolveMatchedPlugins ( classCandidate , context )
147
-
148
145
// TODO: Reintroduce this in ways that doesn't break on false positives
149
146
// let sorted = sortAgainst(variants, context.variantMap)
150
147
// if (sorted.toString() !== variants.toString()) {
151
148
// let corrected = sorted.reverse().concat(classCandidate).join(':')
152
149
// throw new Error(`Class ${candidate} should be written as ${corrected}`)
153
150
// }
154
151
155
- if ( matchedPlugins === null ) {
156
- return [ ]
157
- }
158
-
159
- let pluginHelpers = {
160
- candidate : classCandidate ,
161
- theme : context . tailwindConfig . theme ,
162
- }
152
+ for ( let matchedPlugins of resolveMatchedPlugins ( classCandidate , context ) ) {
153
+ let pluginHelpers = {
154
+ candidate : classCandidate ,
155
+ theme : context . tailwindConfig . theme ,
156
+ }
163
157
164
- let matches = [ ]
165
- let [ plugins , modifier ] = matchedPlugins
158
+ let matches = [ ]
159
+ let [ plugins , modifier ] = matchedPlugins
166
160
167
- for ( let [ sort , plugin ] of plugins ) {
168
- if ( typeof plugin === 'function' ) {
169
- for ( let ruleSet of [ ] . concat ( plugin ( modifier , pluginHelpers ) ) ) {
161
+ for ( let [ sort , plugin ] of plugins ) {
162
+ if ( typeof plugin === 'function' ) {
163
+ for ( let ruleSet of [ ] . concat ( plugin ( modifier , pluginHelpers ) ) ) {
164
+ let [ rules , options ] = parseRules ( ruleSet , context . postCssNodeCache )
165
+ for ( let rule of rules ) {
166
+ matches . push ( [ { ...sort , options } , rule ] )
167
+ }
168
+ }
169
+ } else {
170
+ let ruleSet = plugin
170
171
let [ rules , options ] = parseRules ( ruleSet , context . postCssNodeCache )
171
172
for ( let rule of rules ) {
172
173
matches . push ( [ { ...sort , options } , rule ] )
173
174
}
174
175
}
175
- } else {
176
- let ruleSet = plugin
177
- let [ rules , options ] = parseRules ( ruleSet , context . postCssNodeCache )
178
- for ( let rule of rules ) {
179
- matches . push ( [ { ...sort , options } , rule ] )
180
- }
181
176
}
182
- }
183
177
184
- for ( let variant of variants ) {
185
- matches = applyVariant ( variant , matches , context )
186
- }
178
+ for ( let variant of variants ) {
179
+ matches = applyVariant ( variant , matches , context )
180
+ }
187
181
188
- return matches
182
+ for ( let match of matches ) {
183
+ yield match
184
+ }
185
+ }
189
186
}
190
187
191
188
function generateRules ( candidates , context ) {
@@ -201,7 +198,7 @@ function generateRules(candidates, context) {
201
198
continue
202
199
}
203
200
204
- let matches = resolveMatches ( candidate , context )
201
+ let matches = Array . from ( resolveMatches ( candidate , context ) )
205
202
206
203
// apply prefix and important here?
207
204
0 commit comments