Browse Source

test: add more tests

daiwei 11 tháng trước cách đây
mục cha
commit
8d9f49c965

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

@@ -249,6 +249,24 @@ color: red
       "#app :is(.foo[data-v-test]) { color: red;
       }"
     `)
+
+    expect(compileScoped(`#app :is(:is(.foo)) { color: red; }`))
+      .toMatchInlineSnapshot(`
+        "#app :is(:is(.foo[data-v-test])) { color: red;
+        }"
+      `)
+
+    expect(compileScoped(`#app :where(.foo) { color: red; }`))
+      .toMatchInlineSnapshot(`
+      "#app :where(.foo[data-v-test]) { color: red;
+      }"
+    `)
+
+    expect(compileScoped(`#app :where(:where(.foo)) { color: red; }`))
+      .toMatchInlineSnapshot(`
+        "#app :where(:where(.foo[data-v-test])) { color: red;
+        }"
+      `)
   })
 
   test('media query', () => {

+ 8 - 1
packages/compiler-sfc/src/style/pluginScoped.ts

@@ -225,7 +225,14 @@ function rewriteSelector(
       (n.type !== 'pseudo' && n.type !== 'combinator') ||
       (n.type === 'pseudo' &&
         (n.value === ':is' || n.value === ':where') &&
-        (!node || !n.nodes.some(n => n.nodes.some(x => x.type === 'pseudo'))))
+        (!node ||
+          n.nodes.some(
+            s =>
+              // has nested :is or :where
+              s.nodes.some(x => x.type === n.type && x.value === n.value) ||
+              // has non-pseudo selector
+              !s.nodes.some(x => x.type === 'pseudo'),
+          )))
     ) {
       node = n
     }