Skip to content

Commit

Permalink
fix: parsing error when <style lang="scss" global> (#222)
Browse files Browse the repository at this point in the history
* fix: parsing error when `<style lang="scss" global>`

* Create two-shrimps-suffer.md
  • Loading branch information
ota-meshi authored Sep 28, 2022
1 parent 98881d5 commit df22f7f
Show file tree
Hide file tree
Showing 10 changed files with 1,587 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-shrimps-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: parsing error when `<style lang="scss" global>`
9 changes: 6 additions & 3 deletions src/parser/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export function parseAttributes(
index++;
continue;
}
if (char === ">") break;
if (char === "/" && code[index + 1] === ">") break;
if (char === ">" || (char === "/" && code[index + 1] === ">")) break;
const attrData = parseAttribute(code, index);
attributes.push(attrData.attribute);
index = attrData.index;
Expand Down Expand Up @@ -96,7 +95,11 @@ function parseAttributeKey(
let index = key.end;
while (index < code.length) {
const char = code[index];
if (char === "=") {
if (
char === "=" ||
char === ">" ||
(char === "/" && code[index + 1] === ">")
) {
break;
}
if (spacePattern.test(char)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/parser/ast/style-global01-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div />
<!-- https://github.com/sveltejs/svelte-preprocess#global-style -->
<style global>
div {
color: red;
}
</style>
Loading

0 comments on commit df22f7f

Please sign in to comment.