Skip to content

Commit 6a4d1bb

Browse files
committed
this one aswell
1 parent b14b17f commit 6a4d1bb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ function relative_selector_might_apply_to_node(relative_selector, rule, element)
346346
descendant_elements.push(element);
347347
}
348348

349+
const seen = new Set();
350+
349351
/**
350352
* @param {Compiler.SvelteNode} node
351353
* @param {{ is_child: boolean }} state
@@ -366,6 +368,9 @@ function relative_selector_might_apply_to_node(relative_selector, rule, element)
366368
}
367369
} else if (node.type === 'RenderTag') {
368370
for (const snippet of node.metadata.snippets) {
371+
if (seen.has(snippet)) continue;
372+
373+
seen.add(snippet);
369374
walk_children(snippet.body, context.state);
370375
}
371376
} else {
@@ -629,6 +634,8 @@ function get_following_sibling_elements(element, include_self) {
629634
// ...then walk them, starting from the node after the one
630635
// containing the element in question
631636

637+
const seen = new Set();
638+
632639
/** @param {Compiler.SvelteNode} node */
633640
function get_siblings(node) {
634641
walk(node, null, {
@@ -640,6 +647,9 @@ function get_following_sibling_elements(element, include_self) {
640647
},
641648
RenderTag(node) {
642649
for (const snippet of node.metadata.snippets) {
650+
if (seen.has(snippet)) continue;
651+
652+
seen.add(snippet);
643653
get_siblings(snippet.body);
644654
}
645655
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

22
div.svelte-xyz div:where(.svelte-xyz) {
3-
color: red;
3+
color: green;
4+
}
5+
div.svelte-xyz:has(div:where(.svelte-xyz)) {
6+
color: green;
47
}

packages/svelte/tests/css/samples/render-tag-loop/input.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
<style>
1414
div div {
15-
color: red;
15+
color: green;
16+
}
17+
div:has(div) {
18+
color: green;
1619
}
1720
</style>

0 commit comments

Comments
 (0)