]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): replace universal selector with :where([id]) in scoped styles edison/fix/13401 13404/head
authordaiwei <daiwei521@126.com>
Wed, 28 May 2025 14:10:05 +0000 (22:10 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 28 May 2025 14:10:05 +0000 (22:10 +0800)
packages/compiler-sfc/__tests__/compileStyle.spec.ts
packages/compiler-sfc/src/style/pluginScoped.ts

index 70c6af557abb592445b1f1c08554923282bc22d0..c35fcf55967aa93e2ca1ed9f4c91bded9e1b107a 100644 (file)
@@ -493,7 +493,7 @@ describe('SFC style preprocessors', () => {
       }"
     `)
     expect(compileScoped(`.foo * { color: red; }`)).toMatchInlineSnapshot(`
-      ".foo[data-v-test] [data-v-test] { color: red;
+      ".foo[data-v-test] :where([data-v-test]) { color: red;
       }"
     `)
     expect(compileScoped(`.foo :active { color: red; }`))
@@ -503,7 +503,7 @@ describe('SFC style preprocessors', () => {
     `)
     expect(compileScoped(`.foo *:active { color: red; }`))
       .toMatchInlineSnapshot(`
-      ".foo[data-v-test] [data-v-test]:active { color: red;
+      ".foo[data-v-test] :where([data-v-test]):active { color: red;
       }"
     `)
     expect(compileScoped(`.foo * .bar { color: red; }`)).toMatchInlineSnapshot(`
@@ -512,12 +512,12 @@ describe('SFC style preprocessors', () => {
     `)
     expect(compileScoped(`:last-child * { color: red; }`))
       .toMatchInlineSnapshot(`
-      "[data-v-test]:last-child [data-v-test] { color: red;
+      "[data-v-test]:last-child :where([data-v-test]) { color: red;
       }"
     `)
     expect(compileScoped(`:last-child *:active { color: red; }`))
       .toMatchInlineSnapshot(`
-      "[data-v-test]:last-child [data-v-test]:active { color: red;
+      "[data-v-test]:last-child :where([data-v-test]):active { color: red;
       }"
     `)
   })
index 4845d8eee39568b6e91aa49ece544740635ff7fe..9b7d237bae47b811f357e597d4a812f3d7a5c418 100644 (file)
@@ -218,7 +218,7 @@ function rewriteSelector(
         }
       }
       // store the universal selector so it can be rewritten later
-      // .foo * -> .foo[xxxxxxx] [xxxxxxx]
+      // .foo * -> .foo[xxxxxxx] :where([xxxxxxx])
       starNode = n
     }
 
@@ -280,15 +280,20 @@ function rewriteSelector(
       }),
     )
     // Used for trailing universal selectors (#12906)
-    // `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
+    // `.foo * {}` -> `.foo[xxxxxxx] :where([xxxxxxx]) {}`
     if (starNode) {
       selector.insertBefore(
         starNode,
-        selectorParser.attribute({
-          attribute: idToAdd,
-          value: idToAdd,
-          raws: {},
-          quoteMark: `"`,
+        selectorParser.pseudo({
+          value: ':where',
+          nodes: [
+            selectorParser.attribute({
+              attribute: idToAdd,
+              value: idToAdd,
+              raws: {},
+              quoteMark: `"`,
+            }),
+          ],
         }),
       )
       selector.removeChild(starNode)