Skip to content

fix: parsing error when <script> has attribute with empty value #220

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Sep 16, 2022
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