@@ -82,81 +82,96 @@ function parseRules(rule, cache, options = {}) {
82
82
return [ cache . get ( rule ) , options ]
83
83
}
84
84
85
- function generateRules ( tailwindConfig , candidates , context ) {
86
- let { candidateRuleMap, classCache, notClassCache, postCssNodeCache } = context
87
- let allRules = [ ]
85
+ function resolveMatchedPlugins ( classCandidate , context ) {
86
+ if ( context . candidateRuleMap . has ( classCandidate ) ) {
87
+ return [ context . candidateRuleMap . get ( classCandidate ) , 'DEFAULT' ]
88
+ }
88
89
89
- for ( let candidate of candidates ) {
90
- if ( notClassCache . has ( candidate ) ) {
91
- continue
92
- }
90
+ let candidatePrefix = classCandidate
91
+ let negative = false
93
92
94
- if ( classCache . has ( candidate ) ) {
95
- allRules . push ( classCache . get ( candidate ) )
96
- continue
93
+ if ( candidatePrefix [ 0 ] === '-' ) {
94
+ negative = true
95
+ candidatePrefix = candidatePrefix . slice ( 1 )
96
+ }
97
+
98
+ for ( let [ prefix , modifier ] of candidatePermutations ( candidatePrefix ) ) {
99
+ if ( context . candidateRuleMap . has ( prefix ) ) {
100
+ return [ context . candidateRuleMap . get ( prefix ) , negative ? `-${ modifier } ` : modifier ]
97
101
}
102
+ }
98
103
99
- let [ classCandidate , ... variants ] = candidate . split ( ':' ) . reverse ( )
100
- let matchedPlugins = null
104
+ return null
105
+ }
101
106
102
- if ( candidateRuleMap . has ( classCandidate ) ) {
103
- matchedPlugins = [ candidateRuleMap . get ( classCandidate ) , 'DEFAULT' ]
104
- } else {
105
- let candidatePrefix = classCandidate
106
- let negative = false
107
+ function resolveMatches ( candidate , context ) {
108
+ let [ classCandidate , ...variants ] = candidate . split ( ':' ) . reverse ( )
109
+ let matchedPlugins = resolveMatchedPlugins ( classCandidate , context )
107
110
108
- if ( candidatePrefix [ 0 ] === '-' ) {
109
- negative = true
110
- candidatePrefix = candidatePrefix . slice ( 1 )
111
- }
111
+ if ( matchedPlugins === null ) {
112
+ return [ ]
113
+ }
114
+
115
+ let pluginHelpers = {
116
+ candidate : classCandidate ,
117
+ theme : context . tailwindConfig . theme ,
118
+ }
112
119
113
- for ( let [ prefix , modifier ] of candidatePermutations ( candidatePrefix ) ) {
114
- if ( candidateRuleMap . has ( prefix ) ) {
115
- matchedPlugins = [ candidateRuleMap . get ( prefix ) , negative ? `-${ modifier } ` : modifier ]
116
- break
120
+ let matches = [ ]
121
+ let [ plugins , modifier ] = matchedPlugins
122
+
123
+ for ( let [ sort , plugin ] of plugins ) {
124
+ if ( typeof plugin === 'function' ) {
125
+ for ( let ruleSet of [ ] . concat ( plugin ( modifier , pluginHelpers ) ) ) {
126
+ let [ rules , options ] = parseRules ( ruleSet , context . postCssNodeCache )
127
+ for ( let rule of rules ) {
128
+ matches . push ( [ { ...sort , options } , rule ] )
117
129
}
118
130
}
131
+ } else {
132
+ let ruleSet = plugin
133
+ let [ rules , options ] = parseRules ( ruleSet , context . postCssNodeCache )
134
+ for ( let rule of rules ) {
135
+ matches . push ( [ { ...sort , options } , rule ] )
136
+ }
119
137
}
138
+ }
139
+
140
+ for ( let variant of variants ) {
141
+ matches = applyVariant ( variant , matches , context )
142
+ }
143
+
144
+ return matches
145
+ }
146
+
147
+ function generateRules ( candidates , context ) {
148
+ let allRules = [ ]
120
149
121
- if ( matchedPlugins === null ) {
122
- notClassCache . add ( candidate )
150
+ for ( let candidate of candidates ) {
151
+ if ( context . notClassCache . has ( candidate ) ) {
123
152
continue
124
153
}
125
154
126
- let pluginHelpers = {
127
- candidate : classCandidate ,
128
- theme : tailwindConfig . theme ,
155
+ if ( context . classCache . has ( candidate ) ) {
156
+ allRules . push ( context . classCache . get ( candidate ) )
157
+ continue
129
158
}
130
159
131
- let matches = [ ]
132
- let [ plugins , modifier ] = matchedPlugins
160
+ let matches = resolveMatches ( candidate , context )
133
161
134
- for ( let [ sort , plugin ] of plugins ) {
135
- if ( typeof plugin === 'function' ) {
136
- for ( let ruleSet of [ ] . concat ( plugin ( modifier , pluginHelpers ) ) ) {
137
- let [ rules , options ] = parseRules ( ruleSet , context . newPostCssNodeCache )
138
- for ( let rule of rules ) {
139
- matches . push ( [ { ...sort , options } , rule ] )
140
- }
141
- }
142
- } else {
143
- let ruleSet = plugin
144
- let [ rules , options ] = parseRules ( ruleSet , context . newPostCssNodeCache )
145
- for ( let rule of rules ) {
146
- matches . push ( [ { ...sort , options } , rule ] )
147
- }
148
- }
149
- }
150
-
151
- for ( let variant of variants ) {
152
- matches = applyVariant ( variant , matches , context )
162
+ if ( matches . length === 0 ) {
163
+ context . notClassCache . add ( candidate )
164
+ continue
153
165
}
154
166
155
- classCache . set ( candidate , matches )
167
+ context . classCache . set ( candidate , matches )
156
168
allRules . push ( matches )
157
169
}
158
170
159
171
return allRules . flat ( 1 ) . map ( ( [ { sort, layer } , rule ] ) => [ sort | context . layerOrder [ layer ] , rule ] )
160
172
}
161
173
162
- module . exports = generateRules
174
+ module . exports = {
175
+ resolveMatches,
176
+ generateRules,
177
+ }
0 commit comments