Skip to content

Commit

Permalink
fix: ensure keyword operators are always followed by a space (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Jan 24, 2023
1 parent b232aa2 commit bcfd809
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-seahorses-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fixes an issue where attribute names that started with a keyword (eg: `as-thing` or `instanceof-thing`) were incorrectly treated as an expression continuation.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,34 @@
╰─ ╰─ tagName "tag"
7╭─
╰─ ╰─ openTagEnd
8╭─ tag a = 'foo' instanceof, b
│ │ │ │ │ │ ╰─ attrName
│ │ │ │ │ ╰─ attrName "instanceof"
8╭─ tag a = 'foo' instanceof-test;
│ │ │ │ │ ╰─ attrName "instanceof-test"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTagEnd(tag)
╰─ ╰─ tagName "tag"
9╭─
╰─ ╰─ openTagEnd
10╭─ <tag a = 'foo' instanceof></tag>
9╭─ tag a = 'foo' instanceof_test;
│ │ │ │ │ ╰─ attrName "instanceof_test"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTagEnd(tag)
│ ├─ openTagEnd
╰─ ╰─ tagName "tag"
10╭─
╰─ ╰─ openTagEnd
11╭─ tag a = 'foo' instanceof, b
│ │ │ │ │ │ ╰─ attrName
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTagEnd(tag)
╰─ ╰─ tagName "tag"
12╭─
╰─ ╰─ openTagEnd
13╭─ <tag a = 'foo' instanceof></tag>
│ ││ │ │ │ │ ││ │ ╰─ closeTagEnd(tag)
│ ││ │ │ │ │ ││ ╰─ closeTagName "tag"
│ ││ │ │ │ │ │╰─ closeTagStart "</"
Expand All @@ -66,25 +83,25 @@
│ │╰─ tagName "tag"
│ ├─ closeTagEnd(tag)
╰─ ╰─ openTagStart
11╭─ <tag a = 'foo' instanceof/>
14╭─ <tag a = 'foo' instanceof/>
│ ││ │ │ │ │ ╰─ openTagEnd:selfClosed "/>"
│ ││ │ │ │ ╰─ attrName "instanceof"
│ ││ │ │ ╰─ attrValue.value "'foo'"
│ ││ │ ╰─ attrValue "= 'foo'"
│ ││ ╰─ attrName
│ │╰─ tagName "tag"
╰─ ╰─ openTagStart
12├─
13╭─ tag a = 'foo' instanceofthing String
15├─
16╭─ tag a = 'foo' instanceofthing String
│ │ │ │ │ │ ╰─ attrName "String"
│ │ │ │ │ ╰─ attrName "instanceofthing"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
╰─ ╰─ tagName "tag"
14╭─
17╭─
╰─ ╰─ openTagEnd
15╭─ tag a = 'foo' instanceof
18╭─ tag a = 'foo' instanceof
│ │ │ │ │ │ ├─ closeTagEnd(tag)
│ │ │ │ │ │ ╰─ openTagEnd
│ │ │ │ │ ╰─ attrName "instanceof"
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/attr-complex-instanceof/input.marko
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ tag a = 'foo' instanceof := String
tag a = 'foo' instanceof= String
tag a = 'foo' instanceof;

tag a = 'foo' instanceof-test;
tag a = 'foo' instanceof_test;

tag a = 'foo' instanceof, b

<tag a = 'foo' instanceof></tag>
Expand Down
4 changes: 2 additions & 2 deletions src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ function lookAheadForOperator(data: string, pos: number): number {
nextPos = lookAheadWhile(isWhitespaceCode, data, nextPos + 2);
if (nextPos === max) return -1;
nextCode = data.charCodeAt(nextPos);
} else if (isWordCode(nextCode)) {
// bail if we are continuing a word, eg "**in**teger"
} else {
// bail if we didn't match a space keyword.
return -1;
}

Expand Down

0 comments on commit bcfd809

Please sign in to comment.