fix: disregard TypeScript nodes when pruning CSS

gh-14204
Rich Harris 10 months ago
parent 36ece1c381
commit 1aa87075e9

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: disregard TypeScript nodes when pruning CSS

@ -7,6 +7,13 @@ const UNKNOWN = {};
* @param {Set<any>} set * @param {Set<any>} set
*/ */
function gather_possible_values(node, set) { function gather_possible_values(node, set) {
// @ts-expect-error
if (node.type === 'TSAsExpression') {
// @ts-expect-error
gather_possible_values(node.expression, set);
return;
}
if (node.type === 'Literal') { if (node.type === 'Literal') {
set.add(String(node.value)); set.add(String(node.value));
} else if (node.type === 'ConditionalExpression') { } else if (node.type === 'ConditionalExpression') {

@ -0,0 +1,20 @@
import { test } from '../../test';
export default test({
warnings: [
{
code: 'css_unused_selector',
end: {
character: 127,
column: 28,
line: 10
},
message: 'Unused CSS selector "[data-active=\'true\'] > span"',
start: {
character: 100,
column: 1,
line: 10
}
}
]
});

@ -0,0 +1,4 @@
/* (unused) [data-active='true'] > span {
background-color: red;
}*/

@ -0,0 +1,13 @@
<script lang="ts">
//
</script>
<div data-active={false as true}>
<span></span>
</div>
<style>
[data-active='true'] > span {
background-color: red;
}
</style>
Loading…
Cancel
Save