Skip to content

Commit 3a696d0

Browse files
committed
fix: improve detection of regexp vs division
1 parent 4b2b199 commit 3a696d0

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

.changeset/heavy-stingrays-invite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
When the preceding character of an expression is a quote, prefer division over regexp state. This improves parsing for inline css grid properties.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1╭─ style.scss {
2+
│ │ ││ ╰─ attrName "{\n .foo {\n grid: \"left right\" / 3fr 7fr;\n }\n}"
3+
│ │ │╰─ tagShorthandClass.quasis[0] "scss"
4+
│ │ ╰─ tagShorthandClass ".scss"
5+
╰─ ╰─ tagName "style"
6+
2├─ .foo {
7+
3├─ grid: "left right" / 3fr 7fr;
8+
4├─ }
9+
5├─ }
10+
6╭─
11+
│ ├─ openTagEnd
12+
╰─ ╰─ closeTagEnd(style)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
style.scss {
2+
.foo {
3+
grid: "left right" / 3fr 7fr;
4+
}
5+
}

src/states/EXPRESSION.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,21 @@ function lookAheadForOperator(data: string, pos: number): number {
390390
}
391391

392392
function canFollowDivision(code: number) {
393-
return (
394-
isWordCode(code) ||
395-
code === CODE.PERCENT ||
396-
code === CODE.CLOSE_PAREN ||
397-
code === CODE.PERIOD ||
398-
code === CODE.OPEN_ANGLE_BRACKET ||
399-
code === CODE.CLOSE_SQUARE_BRACKET ||
400-
code === CODE.CLOSE_CURLY_BRACE
401-
);
393+
if (isWordCode(code)) return true;
394+
switch (code) {
395+
case CODE.BACKTICK:
396+
case CODE.SINGLE_QUOTE:
397+
case CODE.DOUBLE_QUOTE:
398+
case CODE.PERCENT:
399+
case CODE.CLOSE_PAREN:
400+
case CODE.PERIOD:
401+
case CODE.OPEN_ANGLE_BRACKET:
402+
case CODE.CLOSE_SQUARE_BRACKET:
403+
case CODE.CLOSE_CURLY_BRACE:
404+
return true;
405+
default:
406+
return false;
407+
}
402408
}
403409

404410
function isWordCode(code: number) {

0 commit comments

Comments
 (0)