fix: correctly prune CSS for elements inside snippets (#14494)

fixes #14483
pull/14499/head
Rich Harris 9 months ago committed by GitHub
parent 99b4cfbb51
commit 1f25bd4f47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly prune CSS for elements inside snippets

@ -201,16 +201,19 @@ function apply_combinator(relative_selector, parent_selectors, rule, node) {
const parent = path[i];
if (parent.type === 'SnippetBlock') {
if (seen.has(parent)) return true;
seen.add(parent);
if (seen.has(parent)) {
parent_matched = true;
} else {
seen.add(parent);
for (const site of parent.metadata.sites) {
if (apply_combinator(relative_selector, parent_selectors, rule, site)) {
return true;
for (const site of parent.metadata.sites) {
if (apply_combinator(relative_selector, parent_selectors, rule, site)) {
parent_matched = true;
}
}
}
return false;
break;
}
if (parent.type === 'RegularElement' || parent.type === 'SvelteElement') {

@ -1,5 +1,5 @@
div div.svelte-xyz {
div.svelte-xyz div:where(.svelte-xyz) {
color: green;
}
/* (unused) div + div {

@ -0,0 +1,4 @@
x.svelte-xyz y:where(.svelte-xyz) {
color: green;
}

@ -0,0 +1,13 @@
{#snippet foo()}
<x>
<y></y>
</x>
{/snippet}
{@render foo()}
<style>
x y {
color: green;
}
</style>
Loading…
Cancel
Save