Skip to content

Commit ead2fe5

Browse files
committed
handle empty classes - fixes #978
1 parent cf94217 commit ead2fe5

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/css/Selector.ts

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function attributeMatches(node: Node, name: string, expectedValue: string, opera
229229
const pattern = operators[operator](expectedValue, caseInsensitive ? 'i' : '');
230230
const value = attr.value[0];
231231

232+
if (!value) return false;
232233
if (value.type === 'Text') return pattern.test(value.data);
233234

234235
const possibleValues = new Set();
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
cascade: false,
3+
4+
warnings: [{
5+
filename: "SvelteComponent.html",
6+
message: "Unused CSS selector",
7+
loc: {
8+
line: 4,
9+
column: 1
10+
},
11+
pos: 31,
12+
frame: `
13+
2:
14+
3: <style>
15+
4: .x {
16+
^
17+
5: color: red;
18+
6: }`
19+
}]
20+
};

test/css/samples/empty-class/expected.css

Whitespace-only changes.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class=""></div>
2+
3+
<style>
4+
.x {
5+
color: red;
6+
}
7+
</style>

0 commit comments

Comments
 (0)