@@ -103,8 +103,14 @@ function rewriteSelector(
103103) {
104104 let node : selectorParser . Node | null = null
105105 let shouldInject = ! deep
106+ let wrappedGlobal = false
106107 // find the last child node to insert attribute selector
107108 selector . each ( n => {
109+ if ( ( rule as any ) . __global ) {
110+ shouldInject = false
111+ return false
112+ }
113+
108114 // DEPRECATED ">>>" and "/deep/" combinator
109115 if (
110116 n . type === 'combinator' &&
@@ -189,8 +195,12 @@ function rewriteSelector(
189195 // global: replace with inner selector and do not inject [id].
190196 // ::v-global(.foo) -> .foo
191197 if ( value === ':global' || value === '::v-global' ) {
192- selector . replaceWith ( n . nodes [ 0 ] )
193- return false
198+ n . replaceWith ( ...n . nodes )
199+ if ( selector . nodes . length === 1 ) {
200+ shouldInject = false
201+ wrappedGlobal = true
202+ return false
203+ }
194204 }
195205 }
196206
@@ -233,7 +243,7 @@ function rewriteSelector(
233243 if ( rule . nodes . some ( node => node . type === 'rule' ) ) {
234244 const deep = ( rule as any ) . __deep
235245 if ( ! deep ) {
236- extractAndWrapNodes ( rule )
246+ extractAndWrapNodes ( rule , wrappedGlobal )
237247 const atruleNodes = rule . nodes . filter ( node => node . type === 'atrule' )
238248 for ( const atnode of atruleNodes ) {
239249 extractAndWrapNodes ( atnode )
@@ -281,7 +291,7 @@ function isSpaceCombinator(node: selectorParser.Node) {
281291 return node . type === 'combinator' && / ^ \s + $ / . test ( node . value )
282292}
283293
284- function extractAndWrapNodes ( parentNode : Rule | AtRule ) {
294+ function extractAndWrapNodes ( parentNode : Rule | AtRule , wrappedGlobal = false ) {
285295 if ( ! parentNode . nodes ) return
286296 const nodes = parentNode . nodes . filter (
287297 node => node . type === 'decl' || node . type === 'comment' ,
@@ -294,6 +304,7 @@ function extractAndWrapNodes(parentNode: Rule | AtRule) {
294304 nodes : nodes ,
295305 selector : '&' ,
296306 } )
307+ ; ( wrappedRule as any ) . __global = wrappedGlobal
297308 parentNode . prepend ( wrappedRule )
298309 }
299310}
0 commit comments