Skip to content

Commit

Permalink
fix: improve detection of regexp vs division
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Nov 10, 2023
1 parent 4b2b199 commit 3a696d0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-stingrays-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

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 number Diff line number Diff line change
@@ -0,0 +1,12 @@
1╭─ style.scss {
│ │ ││ ╰─ attrName "{\n .foo {\n grid: \"left right\" / 3fr 7fr;\n }\n}"
│ │ │╰─ tagShorthandClass.quasis[0] "scss"
│ │ ╰─ tagShorthandClass ".scss"
╰─ ╰─ tagName "style"
2├─ .foo {
3├─ grid: "left right" / 3fr 7fr;
4├─ }
5├─ }
6╭─
│ ├─ openTagEnd
╰─ ╰─ closeTagEnd(style)
5 changes: 5 additions & 0 deletions src/__tests__/fixtures/css-grid/input.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
style.scss {
.foo {
grid: "left right" / 3fr 7fr;
}
}
24 changes: 15 additions & 9 deletions src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,21 @@ function lookAheadForOperator(data: string, pos: number): number {
}

function canFollowDivision(code: number) {
return (
isWordCode(code) ||
code === CODE.PERCENT ||
code === CODE.CLOSE_PAREN ||
code === CODE.PERIOD ||
code === CODE.OPEN_ANGLE_BRACKET ||
code === CODE.CLOSE_SQUARE_BRACKET ||
code === CODE.CLOSE_CURLY_BRACE
);
if (isWordCode(code)) return true;
switch (code) {
case CODE.BACKTICK:
case CODE.SINGLE_QUOTE:
case CODE.DOUBLE_QUOTE:
case CODE.PERCENT:
case CODE.CLOSE_PAREN:
case CODE.PERIOD:
case CODE.OPEN_ANGLE_BRACKET:
case CODE.CLOSE_SQUARE_BRACKET:
case CODE.CLOSE_CURLY_BRACE:
return true;
default:
return false;
}
}

function isWordCode(code: number) {
Expand Down

0 comments on commit 3a696d0

Please sign in to comment.