fix: do not comment out unused selectors that are inside an unused selector (#13746)

fixes #13680
pull/13750/head
Simon H 11 months ago committed by GitHub
parent 2efae794b8
commit 28c8d2b95d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: do not comment out unused selectors that are inside an unused selector

@ -159,6 +159,8 @@ const visitors = {
next(); next();
}, },
SelectorList(node, { state, next, path }) { SelectorList(node, { state, next, path }) {
// Only add comments if we're not inside a complex selector that itself is unused
if (!path.find((n) => n.type === 'ComplexSelector' && !n.metadata.used)) {
let pruning = false; let pruning = false;
let last = node.children[0].start; let last = node.children[0].start;
@ -188,6 +190,7 @@ const visitors = {
if (pruning) { if (pruning) {
state.code.appendLeft(last, '*/'); state.code.appendLeft(last, '*/');
} }
}
// if we're in a `:is(...)` or whatever, keep existing specificity bump state // if we're in a `:is(...)` or whatever, keep existing specificity bump state
let specificity = state.specificity; let specificity = state.specificity;

@ -86,18 +86,32 @@ export default test({
line: 81 line: 81
} }
}, },
{
code: 'css_unused_selector',
message: 'Unused CSS selector ".unused:has(.unused)"',
start: {
line: 84,
column: 1,
character: 934
},
end: {
line: 84,
column: 21,
character: 954
}
},
{ {
code: 'css_unused_selector', code: 'css_unused_selector',
message: 'Unused CSS selector "x:has(> z)"', message: 'Unused CSS selector "x:has(> z)"',
start: { start: {
line: 88, line: 91,
column: 1, column: 1,
character: 968 character: 1021
}, },
end: { end: {
line: 88, line: 91,
column: 11, column: 11,
character: 978 character: 1031
} }
} }
] ]

@ -75,6 +75,9 @@
/* (unused) .unused x:has(y) { /* (unused) .unused x:has(y) {
color: red; color: red;
}*/ }*/
/* (unused) .unused:has(.unused)*/ x.svelte-xyz:has(y:where(.svelte-xyz)) {
color: green;
}
x.svelte-xyz:has(> y:where(.svelte-xyz)) { x.svelte-xyz:has(> y:where(.svelte-xyz)) {
color: green; color: green;

@ -81,6 +81,9 @@
.unused x:has(y) { .unused x:has(y) {
color: red; color: red;
} }
.unused:has(.unused), x:has(y) {
color: green;
}
x:has(> y) { x:has(> y) {
color: green; color: green;

Loading…
Cancel
Save