Skip to content

Commit 8c34227

Browse files
authored
fix: issue with parsing division followed by encloused code (#138)
1 parent 6b7373f commit 8c34227

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

.changeset/mean-buses-mate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Fixes a parse error where division is immediately followed by enclosed code.

src/__tests__/fixtures/attr-method-shorthand/__snapshots__/attr-method-shorthand.expected.txt

+15-3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@
173173
╰─ ╰─ tagName "foo"
174174
59├─ console.log("hello");
175175
60├─ event.preventDefault();
176-
61╭─ }
177-
│ ├─ closeTagEnd(foo)
178-
╰─ ╰─ openTagEnd
176+
61├─ }
177+
62╭─
178+
╰─ ╰─ openTagEnd
179+
63╭─ <a b() { c / (d) }/>
180+
│ ││ │││ ││ ╰─ openTagEnd:selfClosed "/>"
181+
│ ││ │││ │╰─ attrMethod.body.value " c / (d) "
182+
│ ││ │││ ╰─ attrMethod.body "{ c / (d) }"
183+
│ ││ ││╰─ attrMethod.params.value
184+
│ ││ │├─ attrMethod.params "()"
185+
│ ││ │╰─ attrMethod "() { c / (d) }"
186+
│ ││ ╰─ attrName
187+
│ │╰─ tagName
188+
│ ├─ closeTagEnd(foo)
189+
╰─ ╰─ openTagStart
190+
64╰─

src/__tests__/fixtures/attr-method-shorthand/input.marko

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ foo(event) {
5858
foo (event) {
5959
console.log("hello");
6060
event.preventDefault();
61-
}
61+
}
62+
63+
<a b() { c / (d) }/>

src/__tests__/fixtures/attr-operators-space-between/__snapshots__/attr-operators-space-between.expected.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,11 @@
10321032
│ ││├─ attrValue "= async function (x) { console.log(\"y\") }"
10331033
│ ││╰─ attrName
10341034
│ │╰─ tagName
1035+
╰─ ╰─ openTagStart
1036+
128╭─ <a= x / (y[z])/>
1037+
│ │││ │ ╰─ openTagEnd:selfClosed "/>"
1038+
│ │││ ╰─ attrValue.value "x / (y[z])"
1039+
│ ││├─ attrValue "= x / (y[z])"
1040+
│ ││╰─ attrName
1041+
│ │╰─ tagName
10351042
╰─ ╰─ openTagStart

src/__tests__/fixtures/attr-operators-space-between/input.marko

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ a = async function (x) { console.log("y") } a
124124
<a= async x => { console.log("y") } a/>
125125
<a= function (x) { console.log("y") } a/>
126126
<a= x => { console.log("y") } a/>
127-
<a= async function (x) { console.log("y") } a/>
127+
<a= async function (x) { console.log("y") } a/>
128+
<a= x / (y[z])/>

src/states/EXPRESSION.ts

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
9090
default: {
9191
if (canFollowDivision(this.getPreviousNonWhitespaceCharCode())) {
9292
this.pos++;
93+
this.forward = 0;
9394
this.consumeWhitespace();
9495
} else {
9596
this.enterState(STATE.REGULAR_EXPRESSION);

0 commit comments

Comments
 (0)