Skip to content

Commit 1351a34

Browse files
authored
Fix crash with empty style attr (#159)
* Fix crash with empty style attr * add boolean attr test and update
1 parent 6c9eec8 commit 1351a34

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

src/rules/require-optimized-style-attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default createRule("require-optimized-style-attribute", {
3232
})
3333
},
3434
SvelteAttribute(node) {
35-
if (node.key.name !== "style") {
35+
if (node.key.name !== "style" || !node.value?.length) {
3636
return
3737
}
3838
const root = parseStyleAttributeValue(node, context)

src/utils/css-utils/style-attribute.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export function parseStyleAttributeValue(
3232
return cache.get(node) || null
3333
}
3434
cache.set(node, null)
35+
if (!node.value?.length) {
36+
return null
37+
}
3538
const startOffset = node.value[0].range[0]
3639
const sourceCode = context.getSourceCode()
3740
const cssCode = node.value.map((value) => sourceCode.getText(value)).join("")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
</script>
3+
4+
<div style="">...</div>
5+
<div style>...</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
</script>
3+
4+
<div style="">...</div>
5+
<div style>...</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
</script>
3+
4+
<div style="">...</div>
5+
<div style>...</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
</script>
3+
4+
<div style="">...</div>
5+
<div style>...</div>

0 commit comments

Comments
 (0)