Skip to content

Commit

Permalink
fix: issue with parsing division followed by encloused code (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Oct 9, 2022
1 parent 6b7373f commit 8c34227
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-buses-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fixes a parse error where division is immediately followed by enclosed code.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@
╰─ ╰─ tagName "foo"
59├─ console.log("hello");
60├─ event.preventDefault();
61╭─ }
│ ├─ closeTagEnd(foo)
╰─ ╰─ openTagEnd
61├─ }
62╭─
╰─ ╰─ openTagEnd
63╭─ <a b() { c / (d) }/>
│ ││ │││ ││ ╰─ openTagEnd:selfClosed "/>"
│ ││ │││ │╰─ attrMethod.body.value " c / (d) "
│ ││ │││ ╰─ attrMethod.body "{ c / (d) }"
│ ││ ││╰─ attrMethod.params.value
│ ││ │├─ attrMethod.params "()"
│ ││ │╰─ attrMethod "() { c / (d) }"
│ ││ ╰─ attrName
│ │╰─ tagName
│ ├─ closeTagEnd(foo)
╰─ ╰─ openTagStart
64╰─
4 changes: 3 additions & 1 deletion src/__tests__/fixtures/attr-method-shorthand/input.marko
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ foo(event) {
foo (event) {
console.log("hello");
event.preventDefault();
}
}

<a b() { c / (d) }/>
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,11 @@
│ ││├─ attrValue "= async function (x) { console.log(\"y\") }"
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
128╭─ <a= x / (y[z])/>
│ │││ │ ╰─ openTagEnd:selfClosed "/>"
│ │││ ╰─ attrValue.value "x / (y[z])"
│ ││├─ attrValue "= x / (y[z])"
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ a = async function (x) { console.log("y") } a
<a= async x => { console.log("y") } a/>
<a= function (x) { console.log("y") } a/>
<a= x => { console.log("y") } a/>
<a= async function (x) { console.log("y") } a/>
<a= async function (x) { console.log("y") } a/>
<a= x / (y[z])/>
1 change: 1 addition & 0 deletions src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const EXPRESSION: StateDefinition<ExpressionMeta> = {
default: {
if (canFollowDivision(this.getPreviousNonWhitespaceCharCode())) {
this.pos++;
this.forward = 0;
this.consumeWhitespace();
} else {
this.enterState(STATE.REGULAR_EXPRESSION);
Expand Down

0 comments on commit 8c34227

Please sign in to comment.