-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser/html): emit diagnostics for parsing errors (#3846)
- Loading branch information
Showing
12 changed files
with
417 additions
and
19 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
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
1 change: 1 addition & 0 deletions
1
crates/biome_html_parser/tests/html_specs/error/attributes/missing-initializer.html
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 @@ | ||
<div class=></div> |
99 changes: 99 additions & 0 deletions
99
crates/biome_html_parser/tests/html_specs/error/attributes/missing-initializer.html.snap
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,99 @@ | ||
--- | ||
source: crates/biome_html_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
|
||
```html | ||
<div class=></div> | ||
``` | ||
## AST | ||
``` | ||
HtmlRoot { | ||
bom_token: missing (optional), | ||
directive: missing (optional), | ||
html: HtmlElement { | ||
opening_element: HtmlOpeningElement { | ||
l_angle_token: L_ANGLE@0..1 "<" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@1..5 "div" [] [Whitespace(" ")], | ||
}, | ||
attributes: HtmlAttributeList [ | ||
HtmlAttribute { | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@5..10 "class" [] [], | ||
}, | ||
initializer: HtmlAttributeInitializerClause { | ||
eq_token: EQ@10..11 "=" [] [], | ||
value: missing (required), | ||
}, | ||
}, | ||
], | ||
r_angle_token: R_ANGLE@11..12 ">" [] [], | ||
}, | ||
children: HtmlElementList [], | ||
closing_element: HtmlClosingElement { | ||
l_angle_token: L_ANGLE@12..13 "<" [] [], | ||
slash_token: SLASH@13..14 "/" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@14..17 "div" [] [], | ||
}, | ||
r_angle_token: R_ANGLE@17..18 ">" [] [], | ||
}, | ||
}, | ||
eof_token: EOF@18..19 "" [Newline("\n")] [], | ||
} | ||
``` | ||
## CST | ||
``` | ||
0: [email protected] | ||
0: (empty) | ||
1: (empty) | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] | ||
0: [email protected] "div" [] [Whitespace(" ")] | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] | ||
0: [email protected] "class" [] [] | ||
1: [email protected] | ||
0: [email protected] "=" [] [] | ||
1: (empty) | ||
3: [email protected] ">" [] [] | ||
1: [email protected] | ||
2: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] "/" [] [] | ||
2: [email protected] | ||
0: [email protected] "div" [] [] | ||
3: [email protected] ">" [] [] | ||
3: [email protected] "" [Newline("\n")] [] | ||
``` | ||
## Diagnostics | ||
``` | ||
missing-initializer.html:1:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Expected an initializer but instead found '>'. | ||
> 1 │ <div class=></div> | ||
│ ^ | ||
2 │ | ||
i Expected an initializer here. | ||
> 1 │ <div class=></div> | ||
│ ^ | ||
2 │ | ||
``` |
1 change: 1 addition & 0 deletions
1
crates/biome_html_parser/tests/html_specs/error/element/missing-close-tag.html
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 @@ | ||
<div>foo |
77 changes: 77 additions & 0 deletions
77
crates/biome_html_parser/tests/html_specs/error/element/missing-close-tag.html.snap
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,77 @@ | ||
--- | ||
source: crates/biome_html_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
|
||
```html | ||
<div>foo | ||
``` | ||
## AST | ||
``` | ||
HtmlRoot { | ||
bom_token: missing (optional), | ||
directive: missing (optional), | ||
html: HtmlElement { | ||
opening_element: HtmlOpeningElement { | ||
l_angle_token: L_ANGLE@0..1 "<" [] [], | ||
name: HtmlName { | ||
value_token: HTML_LITERAL@1..4 "div" [] [], | ||
}, | ||
attributes: HtmlAttributeList [], | ||
r_angle_token: R_ANGLE@4..5 ">" [] [], | ||
}, | ||
children: HtmlElementList [ | ||
HtmlContent { | ||
value_token: HTML_LITERAL@5..9 "foo\n" [] [], | ||
}, | ||
], | ||
closing_element: missing (required), | ||
}, | ||
eof_token: EOF@9..9 "" [] [], | ||
} | ||
``` | ||
## CST | ||
``` | ||
0: [email protected] | ||
0: (empty) | ||
1: (empty) | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] | ||
0: [email protected] "div" [] [] | ||
2: [email protected] | ||
3: [email protected] ">" [] [] | ||
1: [email protected] | ||
0: [email protected] | ||
0: [email protected] "foo\n" [] [] | ||
2: (empty) | ||
3: [email protected] "" [] [] | ||
``` | ||
## Diagnostics | ||
``` | ||
missing-close-tag.html:2:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Expected a closing tag but instead found the end of the file. | ||
1 │ <div>foo | ||
> 2 │ | ||
│ | ||
i Expected a closing tag here. | ||
1 │ <div>foo | ||
> 2 │ | ||
│ | ||
``` |
1 change: 1 addition & 0 deletions
1
crates/biome_html_parser/tests/html_specs/error/element/missing-element-name.html
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 @@ | ||
<></> |
77 changes: 77 additions & 0 deletions
77
crates/biome_html_parser/tests/html_specs/error/element/missing-element-name.html.snap
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,77 @@ | ||
--- | ||
source: crates/biome_html_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
|
||
```html | ||
<></> | ||
``` | ||
|
||
|
||
## AST | ||
|
||
``` | ||
HtmlRoot { | ||
bom_token: missing (optional), | ||
directive: missing (optional), | ||
html: HtmlElement { | ||
opening_element: HtmlOpeningElement { | ||
l_angle_token: L_ANGLE@0..1 "<" [] [], | ||
name: missing (required), | ||
attributes: HtmlAttributeList [], | ||
r_angle_token: R_ANGLE@1..2 ">" [] [], | ||
}, | ||
children: HtmlElementList [], | ||
closing_element: HtmlClosingElement { | ||
l_angle_token: L_ANGLE@2..3 "<" [] [], | ||
slash_token: SLASH@3..4 "/" [] [], | ||
name: missing (required), | ||
r_angle_token: R_ANGLE@4..5 ">" [] [], | ||
}, | ||
}, | ||
eof_token: EOF@5..6 "" [Newline("\n")] [], | ||
} | ||
``` | ||
|
||
## CST | ||
|
||
``` | ||
0: [email protected] | ||
0: (empty) | ||
1: (empty) | ||
2: [email protected] | ||
0: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: (empty) | ||
2: [email protected] | ||
3: [email protected] ">" [] [] | ||
1: [email protected] | ||
2: [email protected] | ||
0: [email protected] "<" [] [] | ||
1: [email protected] "/" [] [] | ||
2: (empty) | ||
3: [email protected] ">" [] [] | ||
3: [email protected] "" [Newline("\n")] [] | ||
``` | ||
|
||
## Diagnostics | ||
|
||
``` | ||
missing-element-name.html:1:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Expected an element name but instead found '>'. | ||
> 1 │ <></> | ||
│ ^ | ||
2 │ | ||
i Expected an element name here. | ||
> 1 │ <></> | ||
│ ^ | ||
2 │ | ||
``` |
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
crates/biome_html_parser/tests/html_specs/ok/attributes/multiline-attributes.html
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 @@ | ||
<div | ||
class="foo" | ||
role="button" | ||
> | ||
foo | ||
</div> |
Oops, something went wrong.