Skip to content

Commit df22f7f

Browse files
authored
fix: parsing error when <style lang="scss" global> (#222)
* fix: parsing error when `<style lang="scss" global>` * Create two-shrimps-suffer.md
1 parent 98881d5 commit df22f7f

10 files changed

+1587
-7
lines changed

.changeset/two-shrimps-suffer.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 `<style lang="scss" global>`

src/parser/html.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export function parseAttributes(
3030
index++;
3131
continue;
3232
}
33-
if (char === ">") break;
34-
if (char === "/" && code[index + 1] === ">") break;
33+
if (char === ">" || (char === "/" && code[index + 1] === ">")) break;
3534
const attrData = parseAttribute(code, index);
3635
attributes.push(attrData.attribute);
3736
index = attrData.index;
@@ -96,7 +95,11 @@ function parseAttributeKey(
9695
let index = key.end;
9796
while (index < code.length) {
9897
const char = code[index];
99-
if (char === "=") {
98+
if (
99+
char === "=" ||
100+
char === ">" ||
101+
(char === "/" && code[index + 1] === ">")
102+
) {
100103
break;
101104
}
102105
if (spacePattern.test(char)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div />
2+
<!-- https://github.com/sveltejs/svelte-preprocess#global-style -->
3+
<style global>
4+
div {
5+
color: red;
6+
}
7+
</style>

0 commit comments

Comments
 (0)