Skip to content

Commit f52a303

Browse files
authored
fix: ensure comma is also pruned if necessary (#14032)
immediately after merging #14006 I noticed there's a bug when pruning one selector in a list of several; this fixes it no changeset because not released yet
1 parent 435a9c1 commit f52a303

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,15 @@ const visitors = {
214214
state.code.overwrite(i, i + 1, '*/');
215215
}
216216
} else {
217-
prune_start = selector.start;
218-
219-
if (!state.minify) {
220-
if (i === 0) {
217+
if (i === 0) {
218+
if (state.minify) {
219+
prune_start = selector.start;
220+
} else {
221221
state.code.prependRight(selector.start, '/* (unused) ');
222+
}
223+
} else {
224+
if (state.minify) {
225+
prune_start = last;
222226
} else {
223227
state.code.overwrite(last, selector.start, ' /* (unused) ');
224228
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
// test checks that minification works correctly
5+
compileOptions: {
6+
css: 'external'
7+
}
8+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--[--><div class="foo svelte-mnmfn6">foo</div><!--]-->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<style id="svelte-mnmfn6">.foo.svelte-mnmfn6 {color:green;}.foo.svelte-mnmfn6 {color:green;}</style>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<svelte:options css="injected" />
2+
3+
<div class="foo">foo</div>
4+
5+
<style>
6+
.foo {
7+
color: green;
8+
}
9+
.unused {
10+
color: red;
11+
}
12+
.unused {
13+
.nested-unused {
14+
color: red;
15+
}
16+
}
17+
.unused:has(.unused) {
18+
color: red;
19+
}
20+
.foo, .unused {
21+
color: green;
22+
}
23+
</style>

packages/svelte/tests/server-side-rendering/samples/css-injected-options-nested/Nested.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,4 @@
66
.bar {
77
color: red;
88
}
9-
.unused {
10-
.also-unused {
11-
color: green;
12-
}
13-
}
149
</style>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!--[--><div class="bar svelte-1fs6vx">bar</div><!----> <div class="foo svelte-sg04hs">foo</div><!--]-->
1+
<!--[--><div class="bar svelte-ievf05">bar</div><!----> <div class="foo svelte-sg04hs">foo</div><!--]-->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<style id="svelte-1fs6vx">.bar.svelte-1fs6vx {color:red;}</style>
1+
<style id="svelte-ievf05">.bar.svelte-ievf05 {color:red;}</style>

0 commit comments

Comments
 (0)