fix: handle nested `:global(...)` selectors (#12365)

fixes #10540
pull/12368/head
Simon H 6 months ago committed by GitHub
parent 6ac1ae8a12
commit 529db97928
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: handle nested `:global(...)` selectors

@ -71,7 +71,7 @@ const visitors = {
const selectors = truncate(node);
const inner = selectors[selectors.length - 1];
if (node.metadata.rule?.metadata.parent_rule) {
if (node.metadata.rule?.metadata.parent_rule && selectors.length > 0) {
const has_explicit_nesting_selector = selectors.some((selector) =>
selector.selectors.some((s) => s.type === 'NestingSelector')
);

@ -0,0 +1,34 @@
import { test } from '../../test';
export default test({
warnings: [
{
code: 'css_unused_selector',
message: 'Unused CSS selector ".unused :global"',
start: {
line: 25,
column: 2,
character: 229
},
end: {
line: 25,
column: 17,
character: 244
}
},
{
code: 'css_unused_selector',
message: 'Unused CSS selector ".unused :global(.z)"',
start: {
line: 31,
column: 2,
character: 283
},
end: {
line: 31,
column: 21,
character: 302
}
}
]
});

@ -0,0 +1,32 @@
div.svelte-xyz {
/* :global {*/
.x {
color: green;
}
/*}*/
.x {
color: green;
}
p:where(.svelte-xyz) {
.y {
color: green;
}
}
p:where(.svelte-xyz) .y {
color: green;
}
/* (unused) .unused :global {
.z {
color: red;
}
}*/
/* (unused) .unused :global(.z) {
color: red;
}*/
}

@ -0,0 +1,35 @@
<div><p>{@html whatever}</p></div>
<style>
div {
:global {
.x {
color: green;
}
}
:global(.x) {
color: green;
}
p :global {
.y {
color: green;
}
}
p :global(.y) {
color: green;
}
.unused :global {
.z {
color: red;
}
}
.unused :global(.z) {
color: red;
}
}
</style>
Loading…
Cancel
Save