Skip to content

Commit ebc850f

Browse files
authored
Avoid regexp for expression continuations (#130)
* refactor: avoid regexp parsing for expression continuations
1 parent 250c17b commit ebc850f

File tree

28 files changed

+817
-421
lines changed

28 files changed

+817
-421
lines changed

.changeset/tame-geese-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Switch from regexp based parsing for the expression continuations. This slightly improves performance and more importantly fixes usage of the parser in safari.

src/__tests__/fixtures/attr-complex-functions/__snapshots__/attr-complex-functions.expected.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,39 @@
2020
│ ├─ closeTagEnd(tag)
2121
│ ├─ openTagEnd
2222
╰─ ╰─ tagName "tag"
23-
4╭─ tag a = async x => { console.log("y") } b
23+
4╭─ tag a = x => y b
24+
│ │ │ │ │ ╰─ attrName
25+
│ │ │ │ ╰─ attrValue.value "x => y"
26+
│ │ │ ╰─ attrValue "= x => y"
27+
│ │ ╰─ attrName
28+
│ ├─ closeTagEnd(tag)
29+
│ ├─ openTagEnd
30+
╰─ ╰─ tagName "tag"
31+
5╭─ tag a = x => y + 1 b
32+
│ │ │ │ │ ╰─ attrName
33+
│ │ │ │ ╰─ attrValue.value "x => y + 1"
34+
│ │ │ ╰─ attrValue "= x => y + 1"
35+
│ │ ╰─ attrName
36+
│ ├─ closeTagEnd(tag)
37+
│ ├─ openTagEnd
38+
╰─ ╰─ tagName "tag"
39+
6╭─ tag a = x => y = 1 b
40+
│ │ │ │ │ ╰─ attrName
41+
│ │ │ │ ╰─ attrValue.value "x => y = 1"
42+
│ │ │ ╰─ attrValue "= x => y = 1"
43+
│ │ ╰─ attrName
44+
│ ├─ closeTagEnd(tag)
45+
│ ├─ openTagEnd
46+
╰─ ╰─ tagName "tag"
47+
7╭─ tag a = async x => { console.log("y") } b
2448
│ │ │ │ │ ╰─ attrName
2549
│ │ │ │ ╰─ attrValue.value "async x => { console.log(\"y\") }"
2650
│ │ │ ╰─ attrValue "= async x => { console.log(\"y\") }"
2751
│ │ ╰─ attrName
2852
│ ├─ closeTagEnd(tag)
2953
│ ├─ openTagEnd
3054
╰─ ╰─ tagName "tag"
31-
5╭─ tag a = async function (x) { console.log("y") } b
55+
8╭─ tag a = async function (x) { console.log("y") } b
3256
│ │ │ │ │ │├─ closeTagEnd(tag)
3357
│ │ │ │ │ │╰─ openTagEnd
3458
│ │ │ │ │ ╰─ attrName
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
tag a = function (x) { console.log("y") } b
22
tag a = (x) => { console.log("y") } b
33
tag a = x => { console.log("y") } b
4+
tag a = x => y b
5+
tag a = x => y + 1 b
6+
tag a = x => y = 1 b
47
tag a = async x => { console.log("y") } b
58
tag a = async function (x) { console.log("y") } b

src/__tests__/fixtures/attr-complex-instanceof/__snapshots__/attr-complex-instanceof.expected.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,23 @@
7373
│ ││ │ ╰─ attrValue "= 'foo'"
7474
│ ││ ╰─ attrName
7575
│ │╰─ tagName "tag"
76-
╰─ ╰─ openTagStart
76+
╰─ ╰─ openTagStart
77+
12├─
78+
13╭─ tag a = 'foo' instanceofthing String
79+
│ │ │ │ │ │ ╰─ attrName "String"
80+
│ │ │ │ │ ╰─ attrName "instanceofthing"
81+
│ │ │ │ ╰─ attrValue.value "'foo'"
82+
│ │ │ ╰─ attrValue "= 'foo'"
83+
│ │ ╰─ attrName
84+
╰─ ╰─ tagName "tag"
85+
14╭─
86+
╰─ ╰─ openTagEnd
87+
15╭─ tag a = 'foo' instanceof
88+
│ │ │ │ │ │ ├─ closeTagEnd(tag)
89+
│ │ │ │ │ │ ╰─ openTagEnd
90+
│ │ │ │ │ ╰─ attrName "instanceof"
91+
│ │ │ │ ╰─ attrValue.value "'foo'"
92+
│ │ │ ╰─ attrValue "= 'foo'"
93+
│ │ ╰─ attrName
94+
│ ├─ closeTagEnd(tag)
95+
╰─ ╰─ tagName "tag"

src/__tests__/fixtures/attr-complex-instanceof/input.marko

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ tag a = 'foo' instanceof;
88
tag a = 'foo' instanceof, b
99

1010
<tag a = 'foo' instanceof></tag>
11-
<tag a = 'foo' instanceof/>
11+
<tag a = 'foo' instanceof/>
12+
13+
tag a = 'foo' instanceofthing String
14+
15+
tag a = 'foo' instanceof
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
1╭─ a b=c -- y
2+
│ │ │││ │ ╰─ text
3+
│ │ │││ ╰─ openTagEnd
4+
│ │ ││╰─ attrValue.value
5+
│ │ │╰─ attrValue "=c"
6+
│ │ ╰─ attrName
7+
╰─ ╰─ tagName
8+
2├─
9+
3╭─ a [b=c -- y]
10+
│ │ │││ ╰─ attrName
11+
│ │ ││╰─ attrValue.value "c --"
12+
│ │ │╰─ attrValue "=c --"
13+
│ │ ╰─ attrName
14+
│ ├─ closeTagEnd(a)
15+
╰─ ╰─ tagName
16+
4╭─
17+
│ ├─ openTagEnd
18+
╰─ ╰─ closeTagEnd(a)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a b=c -- y
2+
3+
a [b=c -- y]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1╭─ tag a = 'foo' instanceof
2+
│ │ │ │ │ ╰─ attrName "instanceof"
3+
│ │ │ │ ╰─ attrValue.value "'foo'"
4+
│ │ │ ╰─ attrValue "= 'foo'"
5+
│ │ ╰─ attrName
6+
╰─ ╰─ tagName "tag"
7+
2╭─
8+
│ ├─ openTagEnd
9+
╰─ ╰─ closeTagEnd(tag)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tag a = 'foo' instanceof

src/__tests__/fixtures/attr-operators-newline-after/__snapshots__/attr-operators-newline-after.expected.txt

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,17 @@
683683
│ │╰─ openTagEnd:selfClosed "/>"
684684
╰─ ╰─ attrName
685685
159╭─ <a=x >=
686-
│ │││╰─ attrValue.value "x >=\ny"
687-
│ ││├─ attrValue "=x >=\ny"
686+
│ ││││ │╰─ text "=\ny "
687+
│ ││││ ╰─ openTagEnd
688+
│ │││╰─ attrValue.value
689+
│ ││├─ attrValue "=x"
688690
│ ││╰─ attrName
689691
│ │╰─ tagName
690692
╰─ ╰─ openTagStart
691-
160╭─ y a/>
692-
│ │╰─ openTagEnd:selfClosed "/>"
693-
╰─ ╰─ attrName
693+
160╭─ y </a>
694+
│ │ │╰─ closeTagEnd(a)
695+
│ │ ╰─ closeTagName
696+
╰─ ╰─ closeTagStart "</"
694697
161╭─ <a=x &=
695698
│ │││╰─ attrValue.value "x &=\ny"
696699
│ ││├─ attrValue "=x &=\ny"
@@ -746,23 +749,29 @@
746749
│ │╰─ openTagEnd:selfClosed "/>"
747750
╰─ ╰─ attrName
748751
173╭─ <a=x >>=
749-
│ │││╰─ attrValue.value "x >>=\ny"
750-
│ ││├─ attrValue "=x >>=\ny"
752+
│ ││││ │╰─ text ">=\ny "
753+
│ ││││ ╰─ openTagEnd
754+
│ │││╰─ attrValue.value
755+
│ ││├─ attrValue "=x"
751756
│ ││╰─ attrName
752757
│ │╰─ tagName
753758
╰─ ╰─ openTagStart
754-
174╭─ y a/>
755-
│ │╰─ openTagEnd:selfClosed "/>"
756-
╰─ ╰─ attrName
759+
174╭─ y </a>
760+
│ │ │╰─ closeTagEnd(a)
761+
│ │ ╰─ closeTagName
762+
╰─ ╰─ closeTagStart "</"
757763
175╭─ <a=x >>>=
758-
│ │││╰─ attrValue.value "x >>>=\ny"
759-
│ ││├─ attrValue "=x >>>=\ny"
764+
│ ││││ │╰─ text ">>=\ny "
765+
│ ││││ ╰─ openTagEnd
766+
│ │││╰─ attrValue.value
767+
│ ││├─ attrValue "=x"
760768
│ ││╰─ attrName
761769
│ │╰─ tagName
762770
╰─ ╰─ openTagStart
763-
176╭─ y a/>
764-
│ │╰─ openTagEnd:selfClosed "/>"
765-
╰─ ╰─ attrName
771+
176╭─ y </a>
772+
│ │ │╰─ closeTagEnd(a)
773+
│ │ ╰─ closeTagName
774+
╰─ ╰─ closeTagStart "</"
766775
177╭─ <a=x -=
767776
│ │││╰─ attrValue.value "x -=\ny"
768777
│ ││├─ attrValue "=x -=\ny"
@@ -836,23 +845,29 @@
836845
│ │╰─ openTagEnd:selfClosed "/>"
837846
╰─ ╰─ attrName
838847
193╭─ <a=x >>
839-
│ │││╰─ attrValue.value "x >>\ny"
840-
│ ││├─ attrValue "=x >>\ny"
848+
│ ││││ │╰─ text ">\ny "
849+
│ ││││ ╰─ openTagEnd
850+
│ │││╰─ attrValue.value
851+
│ ││├─ attrValue "=x"
841852
│ ││╰─ attrName
842853
│ │╰─ tagName
843854
╰─ ╰─ openTagStart
844-
194╭─ y a/>
845-
│ │╰─ openTagEnd:selfClosed "/>"
846-
╰─ ╰─ attrName
855+
194╭─ y </a>
856+
│ │ │╰─ closeTagEnd(a)
857+
│ │ ╰─ closeTagName
858+
╰─ ╰─ closeTagStart "</"
847859
195╭─ <a=x >>>
848-
│ │││╰─ attrValue.value "x >>>\ny"
849-
│ ││├─ attrValue "=x >>>\ny"
860+
│ ││││ │╰─ text ">>\ny "
861+
│ ││││ ╰─ openTagEnd
862+
│ │││╰─ attrValue.value
863+
│ ││├─ attrValue "=x"
850864
│ ││╰─ attrName
851865
│ │╰─ tagName
852866
╰─ ╰─ openTagStart
853-
196╭─ y a/>
854-
│ │╰─ openTagEnd:selfClosed "/>"
855-
╰─ ╰─ attrName
867+
196╭─ y </a>
868+
│ │ │╰─ closeTagEnd(a)
869+
│ │ ╰─ closeTagName
870+
╰─ ╰─ closeTagStart "</"
856871
197╭─ <a=x
857872
│ │││╰─ attrValue.value "x\n( y )"
858873
│ ││├─ attrValue "=x\n( y )"

0 commit comments

Comments
 (0)