Skip to content

Commit 5692de7

Browse files
committed
fix: don't mark selector lists inside :global with multiple items as unused
Regression from #15762 Fixes #15816
1 parent bfb969a commit 5692de7

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

.changeset/wild-actors-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't mark selector lists inside `:global` with multiple items as unused

packages/svelte/src/compiler/phases/3-transform/css/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ const visitors = {
196196
next();
197197
},
198198
SelectorList(node, { state, next, path }) {
199+
const parent = path.at(-1);
200+
199201
// Only add comments if we're not inside a complex selector that itself is unused or a global block
200202
if (
201-
(!is_in_global_block(path) || node.children.length > 1) &&
203+
(!is_in_global_block(path) ||
204+
(node.children.length > 1 && parent?.type === 'Rule' && parent.metadata.is_global_block)) &&
202205
!path.find((n) => n.type === 'ComplexSelector' && !n.metadata.used)
203206
) {
204207
const children = node.children;
@@ -260,7 +263,6 @@ const visitors = {
260263

261264
// if this selector list belongs to a rule, require a specificity bump for the
262265
// first scoped selector but only if we're at the top level
263-
let parent = path.at(-1);
264266
if (parent?.type === 'Rule') {
265267
specificity = { bumped: false };
266268

@@ -376,7 +378,6 @@ const visitors = {
376378
};
377379

378380
/**
379-
*
380381
* @param {Array<AST.CSS.Node>} path
381382
*/
382383
function is_in_global_block(path) {

packages/svelte/tests/css/samples/global-block/_config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ export default test({
77
code: 'css_unused_selector',
88
message: 'Unused CSS selector ".unused :global"',
99
start: {
10-
line: 69,
10+
line: 73,
1111
column: 1,
12-
character: 917
12+
character: 964
1313
},
1414
end: {
15-
line: 69,
15+
line: 73,
1616
column: 16,
17-
character: 932
17+
character: 979
1818
}
1919
},
2020
{
2121
code: 'css_unused_selector',
2222
message: 'Unused CSS selector "unused :global"',
2323
start: {
24-
line: 100,
24+
line: 104,
2525
column: 29,
26-
character: 1223
26+
character: 1270
2727
},
2828
end: {
29-
line: 100,
29+
line: 104,
3030
column: 43,
31-
character: 1237
31+
character: 1284
3232
}
3333
}
3434
]

packages/svelte/tests/css/samples/global-block/expected.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.x {
44
color: green;
55
}
6+
7+
.a, .selector, .list {
8+
color: green;
9+
}
610
/*}*/
711

812
div.svelte-xyz {

packages/svelte/tests/css/samples/global-block/input.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
.x {
66
color: green;
77
}
8+
9+
.a, .selector, .list {
10+
color: green;
11+
}
812
}
913
1014
div :global {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy