Skip to content

Commit a153f22

Browse files
committed
fix(compiler-sfc): replace universal selector with :where([id]) in scoped styles
1 parent d9bd436 commit a153f22

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/compiler-sfc/__tests__/compileStyle.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ describe('SFC style preprocessors', () => {
493493
}"
494494
`)
495495
expect(compileScoped(`.foo * { color: red; }`)).toMatchInlineSnapshot(`
496-
".foo[data-v-test] [data-v-test] { color: red;
496+
".foo[data-v-test] :where([data-v-test]) { color: red;
497497
}"
498498
`)
499499
expect(compileScoped(`.foo :active { color: red; }`))
@@ -503,7 +503,7 @@ describe('SFC style preprocessors', () => {
503503
`)
504504
expect(compileScoped(`.foo *:active { color: red; }`))
505505
.toMatchInlineSnapshot(`
506-
".foo[data-v-test] [data-v-test]:active { color: red;
506+
".foo[data-v-test] :where([data-v-test]):active { color: red;
507507
}"
508508
`)
509509
expect(compileScoped(`.foo * .bar { color: red; }`)).toMatchInlineSnapshot(`
@@ -512,12 +512,12 @@ describe('SFC style preprocessors', () => {
512512
`)
513513
expect(compileScoped(`:last-child * { color: red; }`))
514514
.toMatchInlineSnapshot(`
515-
"[data-v-test]:last-child [data-v-test] { color: red;
515+
"[data-v-test]:last-child :where([data-v-test]) { color: red;
516516
}"
517517
`)
518518
expect(compileScoped(`:last-child *:active { color: red; }`))
519519
.toMatchInlineSnapshot(`
520-
"[data-v-test]:last-child [data-v-test]:active { color: red;
520+
"[data-v-test]:last-child :where([data-v-test]):active { color: red;
521521
}"
522522
`)
523523
})

packages/compiler-sfc/src/style/pluginScoped.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function rewriteSelector(
218218
}
219219
}
220220
// store the universal selector so it can be rewritten later
221-
// .foo * -> .foo[xxxxxxx] [xxxxxxx]
221+
// .foo * -> .foo[xxxxxxx] :where([xxxxxxx])
222222
starNode = n
223223
}
224224

@@ -280,15 +280,20 @@ function rewriteSelector(
280280
}),
281281
)
282282
// Used for trailing universal selectors (#12906)
283-
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
283+
// `.foo * {}` -> `.foo[xxxxxxx] :where([xxxxxxx]) {}`
284284
if (starNode) {
285285
selector.insertBefore(
286286
starNode,
287-
selectorParser.attribute({
288-
attribute: idToAdd,
289-
value: idToAdd,
290-
raws: {},
291-
quoteMark: `"`,
287+
selectorParser.pseudo({
288+
value: ':where',
289+
nodes: [
290+
selectorParser.attribute({
291+
attribute: idToAdd,
292+
value: idToAdd,
293+
raws: {},
294+
quoteMark: `"`,
295+
}),
296+
],
292297
}),
293298
)
294299
selector.removeChild(starNode)

0 commit comments

Comments
 (0)