Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: improve detection of regexp vs division #168

Merged
merged 1 commit into from
Nov 10, 2023
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/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