Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark pseudo classes nested inside :not as used #14303

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading