소스 검색

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

Cong 2 년 전
부모
커밋
3227e50b32
2개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      packages/compiler-sfc/__tests__/compileStyle.spec.ts
  2. 5 0
      packages/compiler-sfc/src/style/pluginScoped.ts

+ 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;
       ".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', () => {
   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') {
     if (n.type !== 'pseudo' && n.type !== 'combinator') {
       node = n
       node = n
     }
     }
+
+    if (n.type === 'pseudo' && (n.value === ':is' || n.value === ':where')) {
+      rewriteSelector(id, n.nodes[0], selectorRoot, slotted)
+      shouldInject = false
+    }
   })
   })
 
 
   if (node) {
   if (node) {