fix: allow for nesting selector in pseudoclasses (#13209)

Fixes #13203

The problem is that we were checking for NestingSelectors only in the selectors of the immediate child of the selectors. Since Nesting could be in selectors like :is or :where or :has that can also be nested i think we need to walk the selectors to find if there's a selector or not.
pull/13216/head
Paolo Ricciuti 1 week ago committed by GitHub
parent 91299b32ff
commit e9dc118eb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: allow for nesting selector in pseudoclasses

@ -73,9 +73,23 @@ const visitors = {
const inner = selectors[selectors.length - 1];
if (node.metadata.rule?.metadata.parent_rule && selectors.length > 0) {
const has_explicit_nesting_selector = selectors.some((selector) =>
selector.selectors.some((s) => s.type === 'NestingSelector')
);
let has_explicit_nesting_selector = false;
// nesting could be inside pseudo classes like :is, :has or :where
for (let selector of selectors) {
walk(
selector,
{},
{
// @ts-ignore
NestingSelector() {
has_explicit_nesting_selector = true;
}
}
);
// if we found one we can break from the others
if (has_explicit_nesting_selector) break;
}
if (!has_explicit_nesting_selector) {
selectors[0] = {

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
warnings: []
});

@ -0,0 +1,6 @@
nav.svelte-xyz{
header:where(.svelte-xyz):has(&){
color: red;
}
}

@ -0,0 +1 @@
<header class="svelte-xyz"><nav class="svelte-xyz"></nav></header>

@ -0,0 +1,11 @@
<header>
<nav></nav>
</header>
<style>
nav{
header:has(&){
color: red;
}
}
</style>
Loading…
Cancel
Save