@@ -126,9 +126,7 @@ const visitors = {
126
126
return ;
127
127
}
128
128
129
- const used = node . prelude . children . filter ( ( s ) => s . metadata . used ) ;
130
-
131
- if ( used . length === 0 ) {
129
+ if ( ! node . prelude . children . some ( ( s ) => s . metadata . used ) ) {
132
130
state . code . prependRight ( node . start , '/* (unused) ' ) ;
133
131
state . code . appendLeft ( node . end , '*/' ) ;
134
132
escape_comment_close ( node , state . code ) ;
@@ -139,45 +137,38 @@ const visitors = {
139
137
next ( ) ;
140
138
} ,
141
139
SelectorList ( node , { state, next, path } ) {
142
- const used = node . children . filter ( ( s ) => s . metadata . used ) ;
143
-
144
- if ( used . length < node . children . length ) {
145
- let pruning = false ;
146
- let last = node . children [ 0 ] . start ;
140
+ let pruning = false ;
141
+ let last = node . children [ 0 ] . start ;
147
142
148
- for ( let i = 0 ; i < node . children . length ; i += 1 ) {
149
- const selector = node . children [ i ] ;
143
+ for ( let i = 0 ; i < node . children . length ; i += 1 ) {
144
+ const selector = node . children [ i ] ;
150
145
151
- if ( selector . metadata . used === pruning ) {
152
- if ( pruning ) {
153
- let i = selector . start ;
154
- while ( state . code . original [ i ] !== ',' ) i -- ;
146
+ if ( selector . metadata . used === pruning ) {
147
+ if ( pruning ) {
148
+ let i = selector . start ;
149
+ while ( state . code . original [ i ] !== ',' ) i -- ;
155
150
156
- state . code . overwrite ( i , i + 1 , '*/' ) ;
151
+ state . code . overwrite ( i , i + 1 , '*/' ) ;
152
+ } else {
153
+ if ( i === 0 ) {
154
+ state . code . prependRight ( selector . start , '/* (unused) ' ) ;
157
155
} else {
158
- if ( i === 0 ) {
159
- state . code . prependRight ( selector . start , '/* (unused) ' ) ;
160
- } else {
161
- state . code . overwrite ( last , selector . start , ' /* (unused) ' ) ;
162
- }
156
+ state . code . overwrite ( last , selector . start , ' /* (unused) ' ) ;
163
157
}
164
-
165
- pruning = ! pruning ;
166
158
}
167
159
168
- last = selector . end ;
160
+ pruning = ! pruning ;
169
161
}
170
162
171
- if ( pruning ) {
172
- state . code . appendLeft ( last , '*/' ) ;
173
- }
163
+ last = selector . end ;
164
+ }
165
+
166
+ if ( pruning ) {
167
+ state . code . appendLeft ( last , '*/' ) ;
174
168
}
175
169
176
- const parent = /** @type {import('#compiler').Css.Node } */ ( path . at ( - 1 ) ) ;
177
- next ( {
178
- ...state ,
179
- specificity : parent . type === 'Rule' ? { bumped : false } : state . specificity
180
- } ) ;
170
+ const specificity = path . at ( - 1 ) ?. type === 'Rule' ? { bumped : false } : state . specificity ;
171
+ next ( { ...state , specificity } ) ;
181
172
} ,
182
173
ComplexSelector ( node , context ) {
183
174
/** @param {import('#compiler').Css.SimpleSelector } selector */
0 commit comments