@@ -147,43 +147,45 @@ function getClasses(selector, mutate) {
147
147
return parser . transformSync ( selector )
148
148
}
149
149
150
+ /**
151
+ * Ignore everything inside a :not(...). This allows you to write code like
152
+ * `div:not(.foo)`. If `.foo` is never found in your code, then we used to
153
+ * not generated it. But now we will ignore everything inside a `:not`, so
154
+ * that it still gets generated.
155
+ *
156
+ * @param {selectorParser.Root } selectors
157
+ */
158
+ function ignoreNot ( selectors ) {
159
+ selectors . walkPseudos ( ( pseudo ) => {
160
+ if ( pseudo . value === ':not' ) {
161
+ pseudo . remove ( )
162
+ }
163
+ } )
164
+ }
165
+
150
166
function extractCandidates ( node , state = { containsNonOnDemandable : false } , depth = 0 ) {
151
167
let classes = [ ]
168
+ let selectors = [ ]
152
169
153
- // Handle normal rules
154
170
if ( node . type === 'rule' ) {
155
- // Ignore everything inside a :not(...). This allows you to write code like
156
- // `div:not(.foo)`. If `.foo` is never found in your code, then we used to
157
- // not generated it. But now we will ignore everything inside a `:not`, so
158
- // that it still gets generated.
159
- function ignoreNot ( selectors ) {
160
- selectors . walkPseudos ( ( pseudo ) => {
161
- if ( pseudo . value === ':not' ) {
162
- pseudo . remove ( )
163
- }
164
- } )
165
- }
171
+ // Handle normal rules
172
+ selectors . push ( ...node . selectors )
173
+ } else if ( node . type === 'atrule' ) {
174
+ // Handle at-rules (which contains nested rules)
175
+ node . walkRules ( ( rule ) => selectors . push ( ...rule . selectors ) )
176
+ }
166
177
167
- for ( let selector of node . selectors ) {
168
- let classCandidates = getClasses ( selector , ignoreNot )
169
- // At least one of the selectors contains non-"on-demandable" candidates.
170
- if ( classCandidates . length === 0 ) {
171
- state . containsNonOnDemandable = true
172
- }
178
+ for ( let selector of selectors ) {
179
+ let classCandidates = getClasses ( selector , ignoreNot )
173
180
174
- for ( let classCandidate of classCandidates ) {
175
- classes . push ( classCandidate )
176
- }
181
+ // At least one of the selectors contains non-"on-demandable" candidates.
182
+ if ( classCandidates . length === 0 ) {
183
+ state . containsNonOnDemandable = true
177
184
}
178
- }
179
185
180
- // Handle at-rules (which contains nested rules)
181
- else if ( node . type === 'atrule' ) {
182
- node . walkRules ( ( rule ) => {
183
- for ( let classCandidate of rule . selectors . flatMap ( ( selector ) => getClasses ( selector ) ) ) {
184
- classes . push ( classCandidate )
185
- }
186
- } )
186
+ for ( let classCandidate of classCandidates ) {
187
+ classes . push ( classCandidate )
188
+ }
187
189
}
188
190
189
191
if ( depth === 0 ) {
0 commit comments