File tree 2 files changed +47
-4
lines changed 2 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -493,7 +493,31 @@ describe('SFC style preprocessors', () => {
493
493
}"
494
494
` )
495
495
expect ( compileScoped ( `.foo * { color: red; }` ) ) . toMatchInlineSnapshot ( `
496
- ".foo[data-v-test] * { color: red;
496
+ ".foo[data-v-test] [data-v-test] { color: red;
497
+ }"
498
+ ` )
499
+ expect ( compileScoped ( `.foo :active { color: red; }` ) )
500
+ . toMatchInlineSnapshot ( `
501
+ ".foo[data-v-test] :active { color: red;
502
+ }"
503
+ ` )
504
+ expect ( compileScoped ( `.foo *:active { color: red; }` ) )
505
+ . toMatchInlineSnapshot ( `
506
+ ".foo[data-v-test] [data-v-test]:active { color: red;
507
+ }"
508
+ ` )
509
+ expect ( compileScoped ( `.foo * .bar { color: red; }` ) ) . toMatchInlineSnapshot ( `
510
+ ".foo * .bar[data-v-test] { color: red;
511
+ }"
512
+ ` )
513
+ expect ( compileScoped ( `:last-child * { color: red; }` ) )
514
+ . toMatchInlineSnapshot ( `
515
+ "[data-v-test]:last-child [data-v-test] { color: red;
516
+ }"
517
+ ` )
518
+ expect ( compileScoped ( `:last-child *:active { color: red; }` ) )
519
+ . toMatchInlineSnapshot ( `
520
+ "[data-v-test]:last-child [data-v-test]:active { color: red;
497
521
}"
498
522
` )
499
523
} )
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ function rewriteSelector(
102
102
slotted = false ,
103
103
) {
104
104
let node : selectorParser . Node | null = null
105
+ let starNode : selectorParser . Node | null = null
105
106
let shouldInject = ! deep
106
107
// find the last child node to insert attribute selector
107
108
selector . each ( n => {
@@ -216,17 +217,21 @@ function rewriteSelector(
216
217
return false
217
218
}
218
219
}
219
- // .foo * -> .foo[xxxxxxx] *
220
- if ( node ) return
220
+ // store the universal selector so it can be rewritten later
221
+ // .foo * -> .foo[xxxxxxx] [xxxxxxx]
222
+ starNode = n
221
223
}
222
224
223
225
if (
224
- ( n . type !== 'pseudo' && n . type !== 'combinator' ) ||
226
+ ( n . type !== 'pseudo' &&
227
+ n . type !== 'combinator' &&
228
+ n . type !== 'universal' ) ||
225
229
( n . type === 'pseudo' &&
226
230
( n . value === ':is' || n . value === ':where' ) &&
227
231
! node )
228
232
) {
229
233
node = n
234
+ starNode = null
230
235
}
231
236
} )
232
237
@@ -274,6 +279,20 @@ function rewriteSelector(
274
279
quoteMark : `"` ,
275
280
} ) ,
276
281
)
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
+ }
277
296
}
278
297
}
279
298
You can’t perform that action at this time.
0 commit comments