Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-boats-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: parsing error when `<script>` has attribute with empty value
3 changes: 3 additions & 0 deletions src/parser/converts/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export function* convertChildren(
continue;
}
if (child.type === "Text") {
if (!child.data && child.start === child.end) {
continue;
}
yield convertText(child, parent, ctx);
continue;
}
Expand Down
11 changes: 11 additions & 0 deletions src/parser/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ function parseAttributeValue(
index,
};
}
if (valueFirstChar === quote) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wil id="'"(single quote in double quotes) be a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
value: {
value: "",
quote,
start: startIndex,
end: index + 1,
},
index: index + 1,
};
}
const value: AttributeValueToken = {
value: valueFirstChar,
quote,
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/parser/ast/script-tag-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<head>
<script type="text/javascript" id="" src="/some-script.js"></script>
<link href="/style.css" rel="stylesheet">
<script>console.log('foo')</script>
</head>
Loading