Skip to content

Commit

Permalink
fix(parser/html): allow multi line attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Sep 20, 2024
1 parent 83626d9 commit 56a3c2d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 10 deletions.
11 changes: 1 addition & 10 deletions crates/biome_html_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use biome_parser::diagnostic::ParseDiagnostic;
use biome_parser::lexer::{Lexer, LexerCheckpoint, LexerWithCheckpoint, TokenFlags};
use biome_rowan::SyntaxKind;
use biome_unicode_table::lookup_byte;
use biome_unicode_table::Dispatch::{BSL, QOT, UNI, WHS};
use biome_unicode_table::Dispatch::{BSL, QOT, UNI};
use std::ops::Add;

pub(crate) struct HtmlLexer<'src> {
Expand Down Expand Up @@ -246,15 +246,6 @@ impl<'src> HtmlLexer<'src> {
None => {}
}
}
WHS if matches!(chr, b'\n' | b'\r') => {
let unterminated =
ParseDiagnostic::new("Missing closing quote", start..self.text_position())
.with_hint("The closing quote must be on the same line.");

self.diagnostics.push(unterminated);

return ERROR_TOKEN;
}
// we don't need to handle IDT because it's always len 1.
UNI => self.advance_char_unchecked(),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="foo
bar baz">foo</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```html
<div class="foo
bar baz">foo</div>
```


## AST

```
HtmlRoot {
bom_token: missing (optional),
directive: missing (optional),
html: HtmlElementList [
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: HtmlString {
value_token: HTML_STRING_LITERAL@11..24 "\"foo\nbar baz\"" [] [],
},
},
},
],
r_angle_token: R_ANGLE@24..25 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@25..28 "foo" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@28..29 "<" [] [],
slash_token: SLASH@29..30 "/" [] [],
name: HtmlName {
value_token: HTML_LITERAL@30..33 "div" [] [],
},
r_angle_token: R_ANGLE@33..34 ">" [] [],
},
},
],
eof_token: EOF@34..35 "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: (empty)
2: [email protected]
0: [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: [email protected]
0: [email protected] "\"foo\nbar baz\"" [] []
3: [email protected] ">" [] []
1: [email protected]
0: [email protected]
0: [email protected] "foo" [] []
2: [email protected]
0: [email protected] "<" [] []
1: [email protected] "/" [] []
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
3: [email protected] "" [Newline("\n")] []
```

0 comments on commit 56a3c2d

Please sign in to comment.