@@ -78,7 +78,7 @@ const visitors = {
7878 context . state . code . addSourcemapLocation ( node . end ) ;
7979 context . next ( ) ;
8080 } ,
81- Atrule ( node , { state, next } ) {
81+ Atrule ( node , { state, next, path } ) {
8282 if ( is_keyframes_node ( node ) ) {
8383 let start = node . start + node . name . length + 1 ;
8484 while ( state . code . original [ start ] === ' ' ) start += 1 ;
@@ -87,7 +87,7 @@ const visitors = {
8787
8888 if ( node . prelude . startsWith ( '-global-' ) ) {
8989 state . code . remove ( start , start + 8 ) ;
90- } else {
90+ } else if ( ! is_in_global_block ( path ) ) {
9191 state . code . prependRight ( start , `${ state . hash } -` ) ;
9292 }
9393
@@ -134,7 +134,7 @@ const visitors = {
134134 }
135135 }
136136 } ,
137- Rule ( node , { state, next, visit } ) {
137+ Rule ( node , { state, next, visit, path } ) {
138138 if ( state . minify ) {
139139 remove_preceding_whitespace ( node . start , state ) ;
140140 remove_preceding_whitespace ( node . block . end - 1 , state ) ;
@@ -154,7 +154,7 @@ const visitors = {
154154 return ;
155155 }
156156
157- if ( ! is_used ( node ) ) {
157+ if ( ! is_used ( node ) && ! is_in_global_block ( path ) ) {
158158 if ( state . minify ) {
159159 state . code . remove ( node . start , node . end ) ;
160160 } else {
@@ -182,20 +182,20 @@ const visitors = {
182182 state . code . appendLeft ( node . block . end , '*/' ) ;
183183 }
184184
185- // don't recurse into selector or body
185+ // don't recurse into selectors but visit the body
186+ visit ( node . block ) ;
186187 return ;
187188 }
188-
189- // don't recurse into body
190- visit ( node . prelude ) ;
191- return ;
192189 }
193190
194191 next ( ) ;
195192 } ,
196193 SelectorList ( node , { state, next, path } ) {
197- // Only add comments if we're not inside a complex selector that itself is unused
198- if ( ! path . find ( ( n ) => n . type === 'ComplexSelector' && ! n . metadata . used ) ) {
194+ // Only add comments if we're not inside a complex selector that itself is unused or a global block
195+ if (
196+ ! is_in_global_block ( path ) &&
197+ ! path . find ( ( n ) => n . type === 'ComplexSelector' && ! n . metadata . used )
198+ ) {
199199 const children = node . children ;
200200 let pruning = false ;
201201 let prune_start = children [ 0 ] . start ;
@@ -359,6 +359,14 @@ const visitors = {
359359 }
360360} ;
361361
362+ /**
363+ *
364+ * @param {Array<Css.Node> } path
365+ */
366+ function is_in_global_block ( path ) {
367+ return path . some ( ( node ) => node . type === 'Rule' && node . metadata . is_global_block ) ;
368+ }
369+
362370/**
363371 * @param {Css.PseudoClassSelector } selector
364372 * @param {Css.Combinator | null } combinator
0 commit comments