Ver Fonte

fix(compiler-sfc): support `:is` and `:where` selector in scoped css rewrite (#8929)

Cong há 2 anos atrás
pai
commit
3227e50b32

+ 10 - 0
packages/compiler-sfc/__tests__/compileStyle.spec.ts

@@ -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', () => {

+ 5 - 0
packages/compiler-sfc/src/style/pluginScoped.ts

@@ -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) {