]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): support `:is` and `:where` selector in scoped css rewrite (#8929)
authorCong <gucovip@gmail.com>
Fri, 10 Nov 2023 08:44:08 +0000 (16:44 +0800)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2023 08:44:08 +0000 (16:44 +0800)
packages/compiler-sfc/__tests__/compileStyle.spec.ts
packages/compiler-sfc/src/style/pluginScoped.ts

index b33dabfd2ce60acfcd4065f974460f1851f323e2..66fc201f5475706853a5f333270a6160c8b44822 100644 (file)
@@ -85,6 +85,16 @@ describe('SFC scoped CSS', () => {
       ".baz .qux[data-v-test] .foo .bar { color: red;
       }"
     `)
+    expect(compileScoped(`:is(.foo :deep(.bar)) { color: red; }`))
+      .toMatchInlineSnapshot(`
+      ":is(.foo[data-v-test] .bar) { color: red;
+      }"
+    `)
+    expect(compileScoped(`:where(.foo :deep(.bar)) { color: red; }`))
+      .toMatchInlineSnapshot(`
+      ":where(.foo[data-v-test] .bar) { color: red;
+      }"
+    `)
   })
 
   test('::v-slotted', () => {
index f6e9be2fde7e6859014ed95aecee9e7f1422dd11..5394b77743fc8463557d0f5e74a546c0bd4d35b8 100644 (file)
@@ -173,6 +173,11 @@ function rewriteSelector(
     if (n.type !== 'pseudo' && n.type !== 'combinator') {
       node = n
     }
+
+    if (n.type === 'pseudo' && (n.value === ':is' || n.value === ':where')) {
+      rewriteSelector(id, n.nodes[0], selectorRoot, slotted)
+      shouldInject = false
+    }
   })
 
   if (node) {