Skip to content

Commit

Permalink
feat: reduce greediness of readable binary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 18, 2022
1 parent a4cc2db commit f240b7e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
1╭─ var a = 'foo' instanceof String
│ │ │ │ │ ├─ closeTag(var)
│ │ │ │ │ ╰─ openTagEnd(var)
│ │ │ │ ╰─ attrValue.value "'foo' instanceof String"
│ │ │ ╰─ attrValue "= 'foo' instanceof String"
│ │ ╰─ attrName
╰─ ╰─ tagName "var"
╰─ ╰─ tagName "var"
2╭─
╰─ ╰─ openTagEnd(var)
3╭─ tag a = 'foo' instanceof = String
│ │ │ │ │ │ │ ╰─ attrValue.value "String"
│ │ │ │ │ │ ╰─ attrValue "= String"
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTag(var)
╰─ ╰─ tagName "tag"
4╭─ tag a = 'foo' instanceof := String
│ │ │ │ │ │ │ ╰─ attrValue:bound.value "String"
│ │ │ │ │ │ ╰─ attrValue:bound ":= String"
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTag(tag)
│ ├─ openTagEnd(tag)
╰─ ╰─ tagName "tag"
5╭─ tag a = 'foo' instanceof= String
│ │ │ │ │ │ │ ╰─ attrValue.value "String"
│ │ │ │ │ │ ╰─ attrValue "= String"
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTag(tag)
│ ├─ openTagEnd(tag)
╰─ ╰─ tagName "tag"
6╭─ tag a = 'foo' instanceof;
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTag(tag)
│ ├─ openTagEnd(tag)
╰─ ╰─ tagName "tag"
7╭─
╰─ ╰─ openTagEnd(tag)
8╭─ tag a = 'foo' instanceof, b
│ │ │ │ │ │ ╰─ attrName
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTag(tag)
╰─ ╰─ tagName "tag"
9╭─
╰─ ╰─ openTagEnd(tag)
10╭─ <tag a = 'foo' instanceof></tag>
│ ││ │ │ │ │ ││ ╰─ closeTag(tag).value "tag"
│ ││ │ │ │ │ │╰─ closeTag(tag) "</tag>"
│ ││ │ │ │ │ ╰─ openTagEnd(tag)
│ ││ │ │ │ ╰─ attrName "instanceof"
│ ││ │ │ ╰─ attrValue.value "'foo'"
│ ││ │ ╰─ attrValue "= 'foo'"
│ ││ ╰─ attrName
│ │╰─ tagName "tag"
╰─ ╰─ closeTag(tag)
11╭─ <tag a = 'foo' instanceof/>
│ │ │ │ │ │ │ ╰─ closeTag(tag)
│ │ │ │ │ │ ╰─ openTagEnd(tag) "/>"
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
╰─ ╰─ tagName "tag"
12 changes: 11 additions & 1 deletion src/__tests__/fixtures/attr-complex-instanceof/input.marko
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
var a = 'foo' instanceof String
var a = 'foo' instanceof String

tag a = 'foo' instanceof = String
tag a = 'foo' instanceof := String
tag a = 'foo' instanceof= String
tag a = 'foo' instanceof;

tag a = 'foo' instanceof, b

<tag a = 'foo' instanceof></tag>
<tag a = 'foo' instanceof/>
2 changes: 1 addition & 1 deletion src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function canCharCodeBeFollowedByDivision(code: number) {

function escapeOperator(str: string) {
if (/^[A-Z]+$/i.test(str)) {
return "\\b" + escapeNonAlphaNumeric(str) + "\\b";
return "\\b" + escapeNonAlphaNumeric(str) + "(?=\\s+[^=/,;:>])";
}
if (str === "/") {
return "\\/(?:\\b|\\s)"; //make sure this isn't a comment
Expand Down

0 comments on commit f240b7e

Please sign in to comment.