Skip to content

Commit 660cadc

Browse files
authored
fix(compiler-sfc): :is() and :where() in compound selectors (#10522)
Co-authored-by: Haoqun Jiang <[email protected]> Closes #10511
1 parent caeb8a6 commit 660cadc

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

packages/compiler-sfc/__tests__/compileStyle.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,45 @@ describe('SFC scoped CSS', () => {
161161
`)
162162
})
163163

164+
// #10511
165+
test(':is() and :where() in compound selectors', () => {
166+
expect(
167+
compileScoped(`.div { color: red; } .div:where(:hover) { color: blue; }`),
168+
).toMatchInlineSnapshot(`
169+
".div[data-v-test] { color: red;
170+
}
171+
.div[data-v-test]:where(:hover) { color: blue;
172+
}"`)
173+
174+
expect(
175+
compileScoped(`.div { color: red; } .div:is(:hover) { color: blue; }`),
176+
).toMatchInlineSnapshot(`
177+
".div[data-v-test] { color: red;
178+
}
179+
.div[data-v-test]:is(:hover) { color: blue;
180+
}"`)
181+
182+
expect(
183+
compileScoped(
184+
`.div { color: red; } .div:where(.foo:hover) { color: blue; }`,
185+
),
186+
).toMatchInlineSnapshot(`
187+
".div[data-v-test] { color: red;
188+
}
189+
.div[data-v-test]:where(.foo:hover) { color: blue;
190+
}"`)
191+
192+
expect(
193+
compileScoped(
194+
`.div { color: red; } .div:is(.foo:hover) { color: blue; }`,
195+
),
196+
).toMatchInlineSnapshot(`
197+
".div[data-v-test] { color: red;
198+
}
199+
.div[data-v-test]:is(.foo:hover) { color: blue;
200+
}"`)
201+
})
202+
164203
test('media query', () => {
165204
expect(compileScoped(`@media print { .foo { color: red }}`))
166205
.toMatchInlineSnapshot(`

packages/compiler-sfc/src/style/pluginScoped.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ function rewriteSelector(
172172

173173
if (
174174
(n.type !== 'pseudo' && n.type !== 'combinator') ||
175-
(n.type === 'pseudo' && (n.value === ':is' || n.value === ':where'))
175+
(n.type === 'pseudo' &&
176+
(n.value === ':is' || n.value === ':where') &&
177+
!node)
176178
) {
177179
node = n
178180
}

0 commit comments

Comments
 (0)