Skip to content

Commit

Permalink
fix: exclude member expressions from unary operator check
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed May 9, 2022
1 parent c5bbf11 commit 1f2c9b0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/light-trees-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

When parsing unenclosed expressions we look backwards for unary operators preceded by a word break. This caused a false positive when a member expression was found with the operator name, eg `input.new`. Now we ensure that these operators are not in a member expression like this.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1╭─ div a=class Test extends Other { hello() {} }
│ │ ││╰─ attrValue.value "class Test extends Other { hello() {} }"
│ │ │╰─ attrValue "=class Test extends Other { hello() {} }"
│ │ ╰─ attrName
╰─ ╰─ tagName "div"
2╭─ div a=input.class Test extends Other { hello() {} }
│ │ │││ │ │ │ │ ├─ closeTag(div)
│ │ │││ │ │ │ │ ╰─ openTagEnd
│ │ │││ │ │ │ ╰─ attrName "{ hello() {} }"
│ │ │││ │ │ ╰─ attrName "Other"
│ │ │││ │ ╰─ attrName "extends"
│ │ │││ ╰─ attrName "Test"
│ │ ││╰─ attrValue.value "input.class"
│ │ │╰─ attrValue "=input.class"
│ │ ╰─ attrName
│ ├─ closeTag(div)
│ ├─ openTagEnd
╰─ ╰─ tagName "div"
2 changes: 2 additions & 0 deletions src/__tests__/fixtures/unary-as-member-expression/input.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
div a=class Test extends Other { hello() {} }
div a=input.class Test extends Other { hello() {} }
2 changes: 1 addition & 1 deletion src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function buildOperatorPattern(isConcise: boolean) {
`|>${isConcise ? "+" : "{2,}"}` + // in html mode only consume closing angle brackets if it is >>
"|\\b(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])"; // We only continue after word operators (instanceof/in) when they are not followed by a terminator
const unary =
"\\b(?:" +
"\\b(?<![.]\\s*)(?:" +
"a(?:sync|wait)" +
"|keyof" +
"|class" +
Expand Down

0 comments on commit 1f2c9b0

Please sign in to comment.