mirror of https://github.com/sveltejs/svelte
optimise for ternary expressions when excluding unused css (#696)
parent
608f8943f3
commit
4daa57c67b
@ -0,0 +1,18 @@
|
|||||||
|
import { Node } from '../interfaces';
|
||||||
|
|
||||||
|
export const UNKNOWN = {};
|
||||||
|
|
||||||
|
export function gatherPossibleValues(node: Node, set: Set<string|{}>) {
|
||||||
|
if (node.type === 'Literal') {
|
||||||
|
set.add(node.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (node.type === 'ConditionalExpression') {
|
||||||
|
gatherPossibleValues(node.consequent, set);
|
||||||
|
gatherPossibleValues(node.alternate, set);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
set.add(UNKNOWN);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
export default {
|
||||||
|
cascade: false,
|
||||||
|
|
||||||
|
data: {
|
||||||
|
active: true
|
||||||
|
},
|
||||||
|
|
||||||
|
warnings: [{
|
||||||
|
filename: "SvelteComponent.html",
|
||||||
|
message: "Unused CSS selector",
|
||||||
|
loc: {
|
||||||
|
line: 12,
|
||||||
|
column: 1
|
||||||
|
},
|
||||||
|
pos: 125,
|
||||||
|
frame: `
|
||||||
|
10: }
|
||||||
|
11:
|
||||||
|
12: .maybeactive {
|
||||||
|
^
|
||||||
|
13: color: green;
|
||||||
|
14: }`
|
||||||
|
}]
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
.active[svelte-xyz]{color:red}.inactive[svelte-xyz]{color:blue}
|
@ -0,0 +1 @@
|
|||||||
|
<div svelte-xyz="" class="active"></div>
|
@ -0,0 +1,15 @@
|
|||||||
|
<div class='{{active ? "active": "inactive"}}'></div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.active {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inactive {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.maybeactive {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,10 +0,0 @@
|
|||||||
[{
|
|
||||||
"filename": "SvelteComponent.html",
|
|
||||||
"message": "Unused CSS selector",
|
|
||||||
"loc": {
|
|
||||||
"line": 8,
|
|
||||||
"column": 1
|
|
||||||
},
|
|
||||||
"pos": 61,
|
|
||||||
"frame": " 6: }\n 7: \n 8: .bar {\n ^\n 9: color: blue;\n10: }"
|
|
||||||
}]
|
|
Loading…
Reference in new issue