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
change-effect-sequence
Simon H 6 days ago committed by GitHub
parent 435a9c1cd0
commit f52a30347f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

@ -0,0 +1,8 @@
import { test } from '../../test';
export default test({
// test checks that minification works correctly
compileOptions: {
css: 'external'
}
});

@ -0,0 +1 @@
<style id="svelte-mnmfn6">.foo.svelte-mnmfn6 {color:green;}.foo.svelte-mnmfn6 {color:green;}</style>

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

@ -6,9 +6,4 @@
.bar {
color: red;
}
.unused {
.also-unused {
color: green;
}
}
</style>

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

@ -1 +1 @@
<style id="svelte-1fs6vx">.bar.svelte-1fs6vx {color:red;}</style>
<style id="svelte-ievf05">.bar.svelte-ievf05 {color:red;}</style>
Loading…
Cancel
Save