Skip to content

Commit f19019b

Browse files
authored
fix: parsing error when <script> has attribute with empty value (#220)
* fix: parsing error when `<script>` has attribute with empty value * Create sweet-boats-exist.md * fix for empty text and add quote tests
1 parent 534e885 commit f19019b

File tree

8 files changed

+1762
-0
lines changed

8 files changed

+1762
-0
lines changed

.changeset/sweet-boats-exist.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: parsing error when `<script>` has attribute with empty value

src/parser/converts/element.ts

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export function* convertChildren(
7878
continue;
7979
}
8080
if (child.type === "Text") {
81+
if (!child.data && child.start === child.end) {
82+
continue;
83+
}
8184
yield convertText(child, parent, ctx);
8285
continue;
8386
}

src/parser/html.ts

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ function parseAttributeValue(
157157
index,
158158
};
159159
}
160+
if (valueFirstChar === quote) {
161+
return {
162+
value: {
163+
value: "",
164+
quote,
165+
start: startIndex,
166+
end: index + 1,
167+
},
168+
index: index + 1,
169+
};
170+
}
160171
const value: AttributeValueToken = {
161172
value: valueFirstChar,
162173
quote,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<head>
2+
<script type="text/javascript" id="" src="/some-script.js"></script>
3+
<link href="/style.css" rel="stylesheet">
4+
<script>console.log('foo')</script>
5+
</head>

0 commit comments

Comments
 (0)