Skip to content

Commit

Permalink
refactor: avoid regexp parsing for expression continuations
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 5, 2022
1 parent 250c17b commit 08bdb4e
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 104 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-geese-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Switch from regexp based parsing for the expression continuations. This slightly improves performance and more importantly fixes usage of the parser in safari.
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,23 @@
│ ││ │ ╰─ attrValue "= 'foo'"
│ ││ ╰─ attrName
│ │╰─ tagName "tag"
╰─ ╰─ openTagStart
╰─ ╰─ openTagStart
12├─
13╭─ tag a = 'foo' instanceofthing String
│ │ │ │ │ │ ╰─ attrName "String"
│ │ │ │ │ ╰─ attrName "instanceofthing"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
╰─ ╰─ tagName "tag"
14╭─
╰─ ╰─ openTagEnd
15╭─ tag a = 'foo' instanceof
│ │ │ │ │ │ ├─ closeTagEnd(tag)
│ │ │ │ │ │ ╰─ openTagEnd
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
│ ├─ closeTagEnd(tag)
╰─ ╰─ tagName "tag"
6 changes: 5 additions & 1 deletion src/__tests__/fixtures/attr-complex-instanceof/input.marko
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ tag a = 'foo' instanceof;
tag a = 'foo' instanceof, b

<tag a = 'foo' instanceof></tag>
<tag a = 'foo' instanceof/>
<tag a = 'foo' instanceof/>

tag a = 'foo' instanceofthing String

tag a = 'foo' instanceof
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1╭─ tag a = 'foo' instanceof
│ │ │ │ │ ╰─ attrName "instanceof"
│ │ │ │ ╰─ attrValue.value "'foo'"
│ │ │ ╰─ attrValue "= 'foo'"
│ │ ╰─ attrName
╰─ ╰─ tagName "tag"
2╭─
│ ├─ openTagEnd
╰─ ╰─ closeTagEnd(tag)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag a = 'foo' instanceof
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,10 @@
│ ├─ openTagEnd
╰─ ╰─ tagName
49╭─ a=x ++ y a
│ │││ │ │ ╰─ attrName
│ │││ │ ╰─ attrName
│ │││ ╰─ attrName "++"
│ ││╰─ attrValue.value
│ │├─ attrValue "=x"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrName
│ ││╰─ attrValue.value "x ++"
│ │├─ attrValue "=x ++"
│ │╰─ attrName
│ ├─ closeTagEnd(a)
│ ├─ openTagEnd
Expand Down Expand Up @@ -879,17 +878,32 @@
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
111╭─ <a=x ++ y a/>
│ ││││ │ │ │╰─ openTagEnd:selfClosed "/>"
│ ││││ │ │ ╰─ attrName
│ ││││ │ ╰─ attrName
│ ││││ ╰─ attrName "++"
│ │││╰─ attrValue.value
│ ││├─ attrValue "=x"
111╭─ <a=typeof ++ y a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "typeof ++ y"
│ ││├─ attrValue "=typeof ++ y"
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
112╭─ <a=typeof y ++ a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "typeof y ++"
│ ││├─ attrValue "=typeof y ++"
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
113╭─ <a=x ++ y a/>
│ ││││ │ │╰─ openTagEnd:selfClosed "/>"
│ ││││ │ ╰─ attrName
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x ++"
│ ││├─ attrValue "=x ++"
│ ││╰─ attrName
│ │╰─ tagName
╰─ ╰─ openTagStart
112╭─ <a=x > y <a/>
114╭─ <a=x > y <a/>
│ ││││ ││ ││╰─ openTagEnd:selfClosed "/>"
│ ││││ ││ │╰─ tagName
│ ││││ ││ ╰─ openTagStart
Expand All @@ -901,7 +915,7 @@
│ │╰─ tagName
│ ├─ error(MISSING_END_TAG:Missing ending "a" tag) "<a=x >"
╰─ ╰─ openTagStart
113╭─ <a=x >> y a/>
115╭─ <a=x >> y a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x >> y"
Expand All @@ -910,7 +924,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
114╭─ <a=x >>> y a/>
116╭─ <a=x >>> y a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x >>> y"
Expand All @@ -919,7 +933,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
115╭─ <a=x ( y ) a/>
117╭─ <a=x ( y ) a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x ( y )"
Expand All @@ -928,7 +942,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
116╭─ <a=x { y } a/>
118╭─ <a=x { y } a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x { y }"
Expand All @@ -937,7 +951,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
117╭─ <a=x => y a/>
119╭─ <a=x => y a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x => y"
Expand All @@ -946,7 +960,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
118╭─ <a=x => ( y ) a/>
120╭─ <a=x => ( y ) a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x => ( y )"
Expand All @@ -955,7 +969,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
119╭─ <a=x => { y } a/>
121╭─ <a=x => { y } a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "x => { y }"
Expand All @@ -964,7 +978,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
120╭─ <a=( x ) { y } a/>
122╭─ <a=( x ) { y } a/>
│ ││││ │╰─ openTagEnd:selfClosed "/>"
│ ││││ ╰─ attrName
│ │││╰─ attrValue.value "( x ) { y }"
Expand All @@ -973,7 +987,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
121╭─ <a= (x) => { console.log("y") } a/>
123╭─ <a= (x) => { console.log("y") } a/>
│ │││ │ │╰─ openTagEnd:selfClosed "/>"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrValue.value "(x) => { console.log(\"y\") }"
Expand All @@ -982,7 +996,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
122╭─ <a= async x => { console.log("y") } a/>
124╭─ <a= async x => { console.log("y") } a/>
│ │││ │ │╰─ openTagEnd:selfClosed "/>"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrValue.value "async x => { console.log(\"y\") }"
Expand All @@ -991,7 +1005,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
123╭─ <a= function (x) { console.log("y") } a/>
125╭─ <a= function (x) { console.log("y") } a/>
│ │││ │ │╰─ openTagEnd:selfClosed "/>"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrValue.value "function (x) { console.log(\"y\") }"
Expand All @@ -1000,7 +1014,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
124╭─ <a= x => { console.log("y") } a/>
126╭─ <a= x => { console.log("y") } a/>
│ │││ │ │╰─ openTagEnd:selfClosed "/>"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrValue.value "x => { console.log(\"y\") }"
Expand All @@ -1009,7 +1023,7 @@
│ │╰─ tagName
│ ├─ text "\n"
╰─ ╰─ openTagStart
125╭─ <a= async function (x) { console.log("y") } a/>
127╭─ <a= async function (x) { console.log("y") } a/>
│ │││ │ │╰─ openTagEnd:selfClosed "/>"
│ │││ │ ╰─ attrName
│ │││ ╰─ attrValue.value "async function (x) { console.log(\"y\") }"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ a = async function (x) { console.log("y") } a
<a=x instanceof y a/>
<a=x ++ + y a/>
<a=x + ++ y a/>
<a=typeof ++ y a/>
<a=typeof y ++ a/>
<a=x ++ y a/>
<a=x > y <a/>
<a=x >> y a/>
Expand Down
Loading

0 comments on commit 08bdb4e

Please sign in to comment.