Skip to content

fix: ensure comma is also pruned if necessary #14032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/svelte/src/compiler/phases/3-transform/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ const visitors = {
state.code.overwrite(i, i + 1, '*/');
}
} else {
prune_start = selector.start;

if (!state.minify) {
if (i === 0) {
if (i === 0) {
if (state.minify) {
prune_start = selector.start;
} else {
state.code.prependRight(selector.start, '/* (unused) ');
}
} else {
if (state.minify) {
prune_start = last;
} else {
state.code.overwrite(last, selector.start, ' /* (unused) ');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test } from '../../test';

export default test({
// test checks that minification works correctly
compileOptions: {
css: 'external'
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--[--><div class="foo svelte-mnmfn6">foo</div><!--]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<style id="svelte-mnmfn6">.foo.svelte-mnmfn6 {color:green;}.foo.svelte-mnmfn6 {color:green;}</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<svelte:options css="injected" />

<div class="foo">foo</div>

<style>
.foo {
color: green;
}
.unused {
color: red;
}
.unused {
.nested-unused {
color: red;
}
}
.unused:has(.unused) {
color: red;
}
.foo, .unused {
color: green;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
.bar {
color: red;
}
.unused {
.also-unused {
color: green;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!--[--><div class="bar svelte-1fs6vx">bar</div><!----> <div class="foo svelte-sg04hs">foo</div><!--]-->
<!--[--><div class="bar svelte-ievf05">bar</div><!----> <div class="foo svelte-sg04hs">foo</div><!--]-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<style id="svelte-1fs6vx">.bar.svelte-1fs6vx {color:red;}</style>
<style id="svelte-ievf05">.bar.svelte-ievf05 {color:red;}</style>