@@ -116,7 +116,7 @@ const visitors = {
116116 }
117117 }
118118 } ,
119- Rule ( node , { state, next } ) {
119+ Rule ( node , { state, next, visit } ) {
120120 // keep empty rules in dev, because it's convenient to
121121 // see them in devtools
122122 if ( ! state . dev && is_empty ( node ) ) {
@@ -134,6 +134,26 @@ const visitors = {
134134 return ;
135135 }
136136
137+ if ( node . metadata . is_global_block ) {
138+ const selector = node . prelude . children [ 0 ] ;
139+
140+ if ( selector . children . length === 1 ) {
141+ // `:global {...}`
142+ state . code . prependRight ( node . start , '/* ' ) ;
143+ state . code . appendLeft ( node . block . start + 1 , '*/' ) ;
144+
145+ state . code . prependRight ( node . block . end - 1 , '/*' ) ;
146+ state . code . appendLeft ( node . block . end , '*/' ) ;
147+
148+ // don't recurse into selector or body
149+ return ;
150+ }
151+
152+ // don't recurse into body
153+ visit ( node . prelude ) ;
154+ return ;
155+ }
156+
137157 next ( ) ;
138158 } ,
139159 SelectorList ( node , { state, next, path } ) {
@@ -275,6 +295,10 @@ const visitors = {
275295
276296/** @param {import('#compiler').Css.Rule } rule */
277297function is_empty ( rule ) {
298+ if ( rule . metadata . is_global_block ) {
299+ return rule . block . children . length === 0 ;
300+ }
301+
278302 for ( const child of rule . block . children ) {
279303 if ( child . type === 'Declaration' ) {
280304 return false ;
0 commit comments