File tree Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -489,7 +489,31 @@ describe('SFC style preprocessors', () => {
489489 }"
490490 ` )
491491 expect ( compileScoped ( `.foo * { color: red; }` ) ) . toMatchInlineSnapshot ( `
492- ".foo[data-v-test] * { color: red;
492+ ".foo[data-v-test] [data-v-test] { color: red;
493+ }"
494+ ` )
495+ expect ( compileScoped ( `.foo :active { color: red; }` ) )
496+ . toMatchInlineSnapshot ( `
497+ ".foo[data-v-test] :active { color: red;
498+ }"
499+ ` )
500+ expect ( compileScoped ( `.foo *:active { color: red; }` ) )
501+ . toMatchInlineSnapshot ( `
502+ ".foo[data-v-test] [data-v-test]:active { color: red;
503+ }"
504+ ` )
505+ expect ( compileScoped ( `.foo * .bar { color: red; }` ) ) . toMatchInlineSnapshot ( `
506+ ".foo * .bar[data-v-test] { color: red;
507+ }"
508+ ` )
509+ expect ( compileScoped ( `:last-child * { color: red; }` ) )
510+ . toMatchInlineSnapshot ( `
511+ "[data-v-test]:last-child [data-v-test] { color: red;
512+ }"
513+ ` )
514+ expect ( compileScoped ( `:last-child *:active { color: red; }` ) )
515+ . toMatchInlineSnapshot ( `
516+ "[data-v-test]:last-child [data-v-test]:active { color: red;
493517 }"
494518 ` )
495519 } )
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ function rewriteSelector(
102102 slotted = false ,
103103) {
104104 let node : selectorParser . Node | null = null
105+ let starNode : selectorParser . Node | null = null
105106 let shouldInject = ! deep
106107 // find the last child node to insert attribute selector
107108 selector . each ( n => {
@@ -216,17 +217,21 @@ function rewriteSelector(
216217 return false
217218 }
218219 }
219- // .foo * -> .foo[xxxxxxx] *
220- if ( node ) return
220+ // v- store this
221+ // .foo * -> .foo[xxxxxxx] *[xxxxxxx]
222+ starNode = n
221223 }
222224
223225 if (
224- ( n . type !== 'pseudo' && n . type !== 'combinator' ) ||
226+ ( n . type !== 'pseudo' &&
227+ n . type !== 'combinator' &&
228+ n . type !== 'universal' ) ||
225229 ( n . type === 'pseudo' &&
226230 ( n . value === ':is' || n . value === ':where' ) &&
227231 ! node )
228232 ) {
229233 node = n
234+ starNode = null
230235 }
231236 } )
232237
@@ -274,6 +279,20 @@ function rewriteSelector(
274279 quoteMark : `"` ,
275280 } ) ,
276281 )
282+ // Used for trailing universal selectors (#12906)
283+ // `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
284+ if ( starNode ) {
285+ selector . insertBefore (
286+ starNode ,
287+ selectorParser . attribute ( {
288+ attribute : idToAdd ,
289+ value : idToAdd ,
290+ raws : { } ,
291+ quoteMark : `"` ,
292+ } ) ,
293+ )
294+ selector . removeChild ( starNode )
295+ }
277296 }
278297}
279298
You can’t perform that action at this time.
0 commit comments