0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00

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

fixes #10540
This commit is contained in:
Simon H 2024-07-09 18:54:19 +02:00 committed by GitHub
parent 6ac1ae8a12
commit 529db97928
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 107 additions and 1 deletions

View File

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

View File

@ -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')
);

View File

@ -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
}
}
]
});

View File

@ -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;
}*/
}

View File

@ -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>