-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support parsing type parameters
BREAKING CHANGE: onTagParams event renamed to onTagBodyParams
- Loading branch information
1 parent
9788f6e
commit 309a8a3
Showing
31 changed files
with
930 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"htmljs-parser": minor | ||
--- | ||
|
||
Add support for type parameter/argument parsing. | ||
This adds a new `onTagTypeParams`, `onTagTypeArgs` events and a `.typeParams` property on the `AttrMethod` range. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...ith-type-parameters/__snapshots__/attr-method-shorthand-with-type-parameters.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
1╭─ <foo<A>(event: A){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │╰─ attrMethod.typeParams.value | ||
│ ││ ├─ attrMethod.typeParams "<A>" | ||
│ ││ ├─ attrMethod "<A>(event: A){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
2╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
3╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
4├─ | ||
5╭─ <foo<A> (event: A){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │╰─ attrMethod.typeParams.value | ||
│ ││ ├─ attrMethod.typeParams "<A>" | ||
│ ││ ├─ attrMethod "<A> (event: A){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
6╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
7╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
8├─ | ||
9╭─ <foo <A>(event: A){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │╰─ attrMethod.typeParams.value | ||
│ ││ ├─ attrMethod.typeParams "<A>" | ||
│ ││ ├─ attrMethod "<A>(event: A){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
10╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
11╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
12├─ | ||
13╭─ <foo <A> (event: A){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │╰─ attrMethod.typeParams.value | ||
│ ││ ├─ attrMethod.typeParams "<A>" | ||
│ ││ ├─ attrMethod "<A> (event: A){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
14╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
15╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
16├─ | ||
17╭─ <foo<A, B = string>(event: A & B){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ ├─ attrMethod "<A, B = string>(event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
18╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
19╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
20├─ | ||
21╭─ <foo<A, B = string> (event: A & B){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ ├─ attrMethod "<A, B = string> (event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
22╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
23╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
24├─ | ||
25╭─ <foo <A, B = string>(event: A & B){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ ├─ attrMethod "<A, B = string>(event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
26╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
27╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
28├─ | ||
29╭─ <foo <A, B = string> (event: A & B){ | ||
│ ││ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ ├─ attrMethod "<A, B = string> (event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ├─ attrName | ||
│ ││ ╰─ attrName | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
30╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
31╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
32╰─ |
31 changes: 31 additions & 0 deletions
31
src/__tests__/fixtures/attr-method-shorthand-with-type-parameters/input.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<foo<A>(event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo<A> (event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo <A>(event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo <A> (event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo<A, B = string>(event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo<A, B = string> (event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo <A, B = string>(event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo <A, B = string> (event: A & B){ | ||
console.log(event.type) | ||
}/> |
120 changes: 120 additions & 0 deletions
120
...r-method-with-type-parameters/__snapshots__/attr-method-with-type-parameters.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
1╭─ <foo onclick<A>(event: A){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value | ||
│ ││ │ ├─ attrMethod.typeParams "<A>" | ||
│ ││ │ ╰─ attrMethod "<A>(event: A){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
2╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
3╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
4├─ | ||
5╭─ <foo onclick<A> (event: A){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value | ||
│ ││ │ ├─ attrMethod.typeParams "<A>" | ||
│ ││ │ ╰─ attrMethod "<A> (event: A){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
6╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
7╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
8├─ | ||
9╭─ <foo onclick <A>(event: A){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value | ||
│ ││ │ ├─ attrMethod.typeParams "<A>" | ||
│ ││ │ ╰─ attrMethod "<A>(event: A){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
10╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
11╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
12├─ | ||
13╭─ <foo onclick <A> (event: A){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value | ||
│ ││ │ ├─ attrMethod.typeParams "<A>" | ||
│ ││ │ ╰─ attrMethod "<A> (event: A){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
14╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
15╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
16├─ | ||
17╭─ <foo onclick<A, B = string>(event: A & B){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ │ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ │ ╰─ attrMethod "<A, B = string>(event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
18╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
19╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
20├─ | ||
21╭─ <foo onclick<A, B = string> (event: A & B){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ │ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ │ ╰─ attrMethod "<A, B = string> (event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
22╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
23╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
24├─ | ||
25╭─ <foo onclick <A, B = string>(event: A & B){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ │ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ │ ╰─ attrMethod "<A, B = string>(event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
26╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
27╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
28├─ | ||
29╭─ <foo onclick <A, B = string> (event: A & B){ | ||
│ ││ │ ││ ││ ╰─ attrMethod.body "{\n console.log(event.type)\n}" | ||
│ ││ │ ││ │╰─ attrMethod.params.value "event: A & B" | ||
│ ││ │ ││ ╰─ attrMethod.params "(event: A & B)" | ||
│ ││ │ │╰─ attrMethod.typeParams.value "A, B = string" | ||
│ ││ │ ├─ attrMethod.typeParams "<A, B = string>" | ||
│ ││ │ ╰─ attrMethod "<A, B = string> (event: A & B){\n console.log(event.type)\n}" | ||
│ ││ ╰─ attrName "onclick" | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
30╭─ console.log(event.type) | ||
╰─ ╰─ attrMethod.body.value "\n console.log(event.type)\n" | ||
31╭─ }/> | ||
╰─ ╰─ openTagEnd:selfClosed "/>" | ||
32╰─ |
31 changes: 31 additions & 0 deletions
31
src/__tests__/fixtures/attr-method-with-type-parameters/input.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<foo onclick<A>(event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick<A> (event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick <A>(event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick <A> (event: A){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick<A, B = string>(event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick<A, B = string> (event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick <A, B = string>(event: A & B){ | ||
console.log(event.type) | ||
}/> | ||
|
||
<foo onclick <A, B = string> (event: A & B){ | ||
console.log(event.type) | ||
}/> |
6 changes: 5 additions & 1 deletion
6
..._/fixtures/attr-name-with-html-chars/__snapshots__/attr-name-with-html-chars.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
1╭─ tagname <span>hello frank</span> | ||
│ │ ╰─ error(INVALID_ATTRIBUTE_NAME:Invalid attribute name. Attribute name cannot begin with the "<" character.) | ||
│ │ ││ │ │ ╰─ error(INVALID_ATTR_TYPE_PARAMS:Attribute cannot contain type parameters unless it is a shorthand method) "/span" | ||
│ │ ││ │ ╰─ attrName "frank" | ||
│ │ ││ ╰─ attrName "hello" | ||
│ │ │╰─ tagTypeArgs.value "span" | ||
│ │ ╰─ tagTypeArgs "<span>" | ||
╰─ ╰─ tagName "tagname" |
5 changes: 5 additions & 0 deletions
5
...sts__/fixtures/invalid-missing-tag-var/__snapshots__/invalid-missing-tag-var.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1╭─ <foo/, x=1/> | ||
│ ││ ╰─ error(MISSING_TAG_VARIABLE:A slash was found that was not followed by a variable name or lhs expression) | ||
│ │╰─ tagName "foo" | ||
╰─ ╰─ openTagStart | ||
2╰─ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<foo/, x=1/> |
Oops, something went wrong.