Skip to content

Commit

Permalink
fix: mark pseudo classes nested inside :not as used (#14303)
Browse files Browse the repository at this point in the history
fixes the css bug part of #14299
  • Loading branch information
dummdidumm authored Nov 15, 2024
1 parent 6373641 commit efc65d4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-singers-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: mark pseudo classes nested inside `:not` as used
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ const css_visitors = {
// So that nested selectors like `:root:not(.x)` are not marked as unused
for (const child of node.selectors) {
walk(/** @type {Css.Node} */ (child), null, {
ComplexSelector(node) {
ComplexSelector(node, context) {
node.metadata.used = true;
context.next();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,12 @@ function relative_selector_might_apply_to_node(relative_selector, rule, element,
// with descendants, in which case we scope them all.
if (name === 'not' && selector.args) {
for (const complex_selector of selector.args.children) {
complex_selector.metadata.used = true;
walk(complex_selector, null, {
ComplexSelector(node, context) {
node.metadata.used = true;
context.next();
}
});
const relative = truncate(complex_selector);

if (complex_selector.children.length > 1) {
Expand Down
4 changes: 4 additions & 0 deletions packages/svelte/tests/css/samples/not-selector/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@
span.svelte-xyz:not(:focus) {
color: green;
}

p.svelte-xyz:not(:has(span)) {
color: green;
}
4 changes: 4 additions & 0 deletions packages/svelte/tests/css/samples/not-selector/input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@
span:not(:focus) {
color: green;
}
p:not(:has(span)) {
color: green;
}
</style>

0 comments on commit efc65d4

Please sign in to comment.