mirror of https://github.com/sveltejs/svelte
We previously marked all `:root` selectors as global-like, which excempted them from further analysis. This causes problems: - things like `:not(...)` are never visited and therefore never marked as used -> we gotta do that directly when coming across this - `:has(...)` was never visited, too. Just marking it as used is not enough though, because we might need to scope its contents Therefore the logic is enhanced to account for these special cases. Fixes #14118pull/14229/head
parent
438de04fb2
commit
85a37de092
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: account for `:has(...)` as part of `:root`
|
@ -1,3 +1,34 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({});
|
||||
export default test({
|
||||
warnings: [
|
||||
{
|
||||
code: 'css_unused_selector',
|
||||
message: 'Unused CSS selector ":root .unused"',
|
||||
start: {
|
||||
line: 18,
|
||||
column: 2,
|
||||
character: 190
|
||||
},
|
||||
end: {
|
||||
line: 18,
|
||||
column: 15,
|
||||
character: 203
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 'css_unused_selector',
|
||||
message: 'Unused CSS selector ":root:has(.unused)"',
|
||||
start: {
|
||||
line: 25,
|
||||
column: 2,
|
||||
character: 269
|
||||
},
|
||||
end: {
|
||||
line: 25,
|
||||
column: 20,
|
||||
character: 287
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
@ -1,9 +1,31 @@
|
||||
|
||||
:root {
|
||||
color: red;
|
||||
color: green;
|
||||
}
|
||||
.foo:root {
|
||||
color: blue;
|
||||
color: green;
|
||||
}
|
||||
:root.foo {
|
||||
color: green;
|
||||
}
|
||||
:root.unknown {
|
||||
color: green;
|
||||
}
|
||||
|
||||
:root h1.svelte-xyz {
|
||||
color: green;
|
||||
}
|
||||
/* (unused) :root .unused {
|
||||
color: red;
|
||||
}*/
|
||||
|
||||
:root:has(h1:where(.svelte-xyz)) {
|
||||
color: green;
|
||||
}
|
||||
/* (unused) :root:has(.unused) {
|
||||
color: red;
|
||||
}*/
|
||||
|
||||
:root:not(.x) {
|
||||
color: green;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
<h1>Hello!</h1>
|
||||
<h1 class="svelte-xyz">Hello!</h1>
|
@ -1,13 +1,34 @@
|
||||
<style>
|
||||
:root {
|
||||
color: red;
|
||||
color: green;
|
||||
}
|
||||
.foo:root {
|
||||
color: blue;
|
||||
color: green;
|
||||
}
|
||||
:root.foo {
|
||||
color: green;
|
||||
}
|
||||
:root.unknown {
|
||||
color: green;
|
||||
}
|
||||
|
||||
:root h1 {
|
||||
color: green;
|
||||
}
|
||||
:root .unused {
|
||||
color: red;
|
||||
}
|
||||
|
||||
:root:has(h1) {
|
||||
color: green;
|
||||
}
|
||||
:root:has(.unused) {
|
||||
color: red;
|
||||
}
|
||||
|
||||
:root:not(.x) {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h1>Hello!</h1>
|
||||
|
Loading…
Reference in new issue