@@ -116,7 +116,7 @@ const visitors = {
116
116
}
117
117
}
118
118
} ,
119
- Rule ( node , { state, next } ) {
119
+ Rule ( node , { state, next, visit } ) {
120
120
// keep empty rules in dev, because it's convenient to
121
121
// see them in devtools
122
122
if ( ! state . dev && is_empty ( node ) ) {
@@ -134,6 +134,26 @@ const visitors = {
134
134
return ;
135
135
}
136
136
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
+
137
157
next ( ) ;
138
158
} ,
139
159
SelectorList ( node , { state, next, path } ) {
@@ -275,6 +295,10 @@ const visitors = {
275
295
276
296
/** @param {import('#compiler').Css.Rule } rule */
277
297
function is_empty ( rule ) {
298
+ if ( rule . metadata . is_global_block ) {
299
+ return rule . block . children . length === 0 ;
300
+ }
301
+
278
302
for ( const child of rule . block . children ) {
279
303
if ( child . type === 'Declaration' ) {
280
304
return false ;
0 commit comments