Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-lions-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#10274](https://github.com/biomejs/biome/issues/10274): Svelte templates with missing expressions no longer parsed as `HtmlBogusElement`
7 changes: 7 additions & 0 deletions crates/biome_html_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ impl<'src> HtmlLexer<'src> {
/// Consumes tokens within a single text expression ('{...}') while tracking nested
/// brackets until the matching closing bracket is found.
fn consume_single_text_expression(&mut self) -> HtmlSyntaxKind {
// emit leading whitespace as trivia so it's not part of the expression literal
if let Some(current) = self.current_byte()
&& lookup_byte(current) == WHS
{
return self.consume_newline_or_whitespaces();
}

let mut brackets_stack = 0;
while let Some(current) = self.current_byte() {
match current {
Expand Down
7 changes: 6 additions & 1 deletion crates/biome_html_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,13 @@ fn parse_single_text_expression_content(p: &mut HtmlParser) -> ParsedSyntax {
return Absent;
}
if p.cur_text().is_empty() {
p.bump_remap(HTML_LITERAL);
p.re_lex(HtmlReLexContext::Svelte);
return Absent;
}
if p.cur_text().trim().is_empty() {
return Absent;
}
Comment on lines 851 to 857

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚑ Quick win

Missing test for the bug fix, as required by coding guidelines.

The coding guidelines mandate that bug fixes include a test that reproduces and validates the fix. The snapshot files update for if_missing_expression.svelte.snap is a good signal, but there is no dedicated input fixture (or explicit unit test) that was committed as part of this PR. The PR thread confirms one was promised but not yet delivered.

As per coding guidelines: "bug fixes require tests that reproduce and validate the fix."

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/biome_html_parser/src/syntax/mod.rs` around lines 851 - 857, Add a
unit/integration test that reproduces the original bug fixed in the parsing
logic around p.cur_text()/p.re_lex(HtmlReLexContext::Svelte) returning Absent:
create an input fixture (e.g. if_missing_expression.svelte) that previously
produced the failing snapshot, add a test that parses this fixture through the
same entrypoint used in crates/biome_html_parser (calling into the module
containing the logic with p.cur_text()/p.re_lex and expecting the Absent
behavior), and assert the parser output matches the updated snapshot (or
explicit expected AST); ensure the test lands in the crate test suite and
references the updated snapshot file so CI will validate the regression is
prevented going forward.


let m = p.start();

p.bump_remap(HTML_LITERAL);
Expand All @@ -876,6 +877,10 @@ impl TextExpression {
HTML_LITERAL,
HtmlLexContext::TextExpression(self.kind),
);
} else if p.cur_text().is_empty() {
m.abandon(p);
p.re_lex(HtmlReLexContext::Svelte);
return Absent;
} else if !p.at(T!['}']) {
p.bump_remap(HTML_LITERAL);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ HtmlRoot {
attributes: HtmlAttributeList [
SvelteAttachAttribute {
sv_curly_at_token: SV_CURLY_AT@5..7 "{@" [] [],
attach_token: ATTACH_KW@7..13 "attach" [] [],
attach_token: ATTACH_KW@7..14 "attach" [] [Whitespace(" ")],
expression: HtmlTextExpression {
html_literal_token: HTML_LITERAL@13..25 " >...</div>\n" [] [],
html_literal_token: HTML_LITERAL@14..25 ">...</div>\n" [] [],
},
r_curly_token: missing (required),
},
Expand Down Expand Up @@ -61,9 +61,9 @@ HtmlRoot {
2: HTML_ATTRIBUTE_LIST@5..25
0: SVELTE_ATTACH_ATTRIBUTE@5..25
0: SV_CURLY_AT@5..7 "{@" [] []
1: ATTACH_KW@7..13 "attach" [] []
2: HTML_TEXT_EXPRESSION@13..25
0: HTML_LITERAL@13..25 " >...</div>\n" [] []
1: ATTACH_KW@7..14 "attach" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@14..25
0: HTML_LITERAL@14..25 ">...</div>\n" [] []
3: (empty)
3: (empty)
1: HTML_ELEMENT_LIST@25..25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ HtmlRoot {
clauses: SvelteAwaitClausesList [
SvelteAwaitCatchBlock {
sv_curly_colon_token: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] [],
catch_token: CATCH_KW@39..44 "catch" [] [],
catch_token: CATCH_KW@39..45 "catch" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@44..50 " error" [] [],
html_literal_token: HTML_LITERAL@45..50 "error" [] [],
},
r_curly_token: R_CURLY@50..51 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -101,9 +101,9 @@ HtmlRoot {
},
SvelteAwaitThenBlock {
sv_curly_colon_token: SV_CURLY_COLON@76..79 "{:" [Newline("\n")] [],
then_token: THEN_KW@79..83 "then" [] [],
then_token: THEN_KW@79..84 "then" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@83..89 " value" [] [],
html_literal_token: HTML_LITERAL@84..89 "value" [] [],
},
r_curly_token: R_CURLY@89..90 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -185,9 +185,9 @@ HtmlRoot {
1: SVELTE_AWAIT_CLAUSES_LIST@36..107
0: SVELTE_AWAIT_CATCH_BLOCK@36..76
0: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] []
1: CATCH_KW@39..44 "catch" [] []
2: HTML_TEXT_EXPRESSION@44..50
0: HTML_LITERAL@44..50 " error" [] []
1: CATCH_KW@39..45 "catch" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@45..50
0: HTML_LITERAL@45..50 "error" [] []
3: R_CURLY@50..51 "}" [] []
4: HTML_ELEMENT_LIST@51..76
0: HTML_ELEMENT@51..76
Expand All @@ -211,9 +211,9 @@ HtmlRoot {
3: R_ANGLE@75..76 ">" [] []
1: SVELTE_AWAIT_THEN_BLOCK@76..107
0: SV_CURLY_COLON@76..79 "{:" [Newline("\n")] []
1: THEN_KW@79..83 "then" [] []
2: HTML_TEXT_EXPRESSION@83..89
0: HTML_LITERAL@83..89 " value" [] []
1: THEN_KW@79..84 "then" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@84..89
0: HTML_LITERAL@84..89 "value" [] []
3: R_CURLY@89..90 "}" [] []
4: HTML_ELEMENT_LIST@90..107
0: HTML_ELEMENT@90..107
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,51 @@ HtmlRoot {
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
HtmlBogusElement {
items: [
HtmlBogus {
items: [
SV_CURLY_HASH@0..2 "{#" [] [],
AWAIT_KW@2..7 "await" [] [],
HtmlTextExpression {
html_literal_token: HTML_LITERAL@7..16 " promise " [] [],
},
HtmlBogus {
items: [
CATCH_KW@16..21 "catch" [] [],
HTML_LITERAL@21..21 "" [] [],
],
SvelteAwaitBlock {
opening_block: SvelteAwaitOpeningBlock {
sv_curly_hash_token: SV_CURLY_HASH@0..2 "{#" [] [],
await_token: AWAIT_KW@2..7 "await" [] [],
expression: HtmlTextExpression {
html_literal_token: HTML_LITERAL@7..16 " promise " [] [],
},
then_clause: missing (optional),
catch_clause: SvelteAwaitCatchClause {
catch_token: CATCH_KW@16..21 "catch" [] [],
name: missing (required),
},
r_curly_token: R_CURLY@21..22 "}" [] [],
children: HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@22..26 "<" [Newline("\n"), Whitespace(" ")] [],
name: HtmlTagName {
value_token: HTML_LITERAL@26..27 "p" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@27..28 ">" [] [],
},
R_CURLY@21..22 "}" [] [],
HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@22..26 "<" [Newline("\n"), Whitespace(" ")] [],
name: HtmlTagName {
value_token: HTML_LITERAL@26..27 "p" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@27..28 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@28..34 "Error!" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@34..35 "<" [] [],
slash_token: SLASH@35..36 "/" [] [],
name: HtmlTagName {
value_token: HTML_LITERAL@36..37 "p" [] [],
},
r_angle_token: R_ANGLE@37..38 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@28..34 "Error!" [] [],
},
],
],
},
SvelteAwaitClausesList [],
SvelteAwaitClosingBlock {
sv_curly_slash_token: SV_CURLY_SLASH@38..41 "{/" [Newline("\n")] [],
await_token: AWAIT_KW@41..46 "await" [] [],
r_curly_token: R_CURLY@46..47 "}" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@34..35 "<" [] [],
slash_token: SLASH@35..36 "/" [] [],
name: HtmlTagName {
value_token: HTML_LITERAL@36..37 "p" [] [],
},
r_angle_token: R_ANGLE@37..38 ">" [] [],
},
},
],
},
clauses: SvelteAwaitClausesList [],
closing_block: SvelteAwaitClosingBlock {
sv_curly_slash_token: SV_CURLY_SLASH@38..41 "{/" [Newline("\n")] [],
await_token: AWAIT_KW@41..46 "await" [] [],
r_curly_token: R_CURLY@46..47 "}" [] [],
},
},
],
eof_token: EOF@47..48 "" [Newline("\n")] [],
Expand All @@ -85,17 +80,18 @@ HtmlRoot {
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..47
0: HTML_BOGUS_ELEMENT@0..47
0: HTML_BOGUS@0..38
0: SVELTE_AWAIT_BLOCK@0..47
0: SVELTE_AWAIT_OPENING_BLOCK@0..38
0: SV_CURLY_HASH@0..2 "{#" [] []
1: AWAIT_KW@2..7 "await" [] []
2: HTML_TEXT_EXPRESSION@7..16
0: HTML_LITERAL@7..16 " promise " [] []
3: HTML_BOGUS@16..21
3: (empty)
4: SVELTE_AWAIT_CATCH_CLAUSE@16..21
0: CATCH_KW@16..21 "catch" [] []
1: HTML_LITERAL@21..21 "" [] []
4: R_CURLY@21..22 "}" [] []
5: HTML_ELEMENT_LIST@22..38
1: (empty)
5: R_CURLY@21..22 "}" [] []
6: HTML_ELEMENT_LIST@22..38
0: HTML_ELEMENT@22..38
0: HTML_OPENING_ELEMENT@22..28
0: L_ANGLE@22..26 "<" [Newline("\n"), Whitespace(" ")] []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ HtmlRoot {
clauses: SvelteAwaitClausesList [
SvelteAwaitThenBlock {
sv_curly_colon_token: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] [],
then_token: THEN_KW@39..43 "then" [] [],
then_token: THEN_KW@39..44 "then" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@43..49 " value" [] [],
html_literal_token: HTML_LITERAL@44..49 "value" [] [],
},
r_curly_token: R_CURLY@49..50 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -103,9 +103,9 @@ HtmlRoot {
},
SvelteAwaitCatchBlock {
sv_curly_colon_token: SV_CURLY_COLON@67..70 "{:" [Newline("\n")] [],
catch_token: CATCH_KW@70..75 "catch" [] [],
catch_token: CATCH_KW@70..76 "catch" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@75..81 " error" [] [],
html_literal_token: HTML_LITERAL@76..81 "error" [] [],
},
r_curly_token: R_CURLY@81..82 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -140,9 +140,9 @@ HtmlRoot {
},
SvelteAwaitCatchBlock {
sv_curly_colon_token: SV_CURLY_COLON@107..110 "{:" [Newline("\n")] [],
catch_token: CATCH_KW@110..115 "catch" [] [],
catch_token: CATCH_KW@110..116 "catch" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@115..128 " anotherError" [] [],
html_literal_token: HTML_LITERAL@116..128 "anotherError" [] [],
},
r_curly_token: R_CURLY@128..129 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -224,9 +224,9 @@ HtmlRoot {
1: SVELTE_AWAIT_CLAUSES_LIST@36..161
0: SVELTE_AWAIT_THEN_BLOCK@36..67
0: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] []
1: THEN_KW@39..43 "then" [] []
2: HTML_TEXT_EXPRESSION@43..49
0: HTML_LITERAL@43..49 " value" [] []
1: THEN_KW@39..44 "then" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@44..49
0: HTML_LITERAL@44..49 "value" [] []
3: R_CURLY@49..50 "}" [] []
4: HTML_ELEMENT_LIST@50..67
0: HTML_ELEMENT@50..67
Expand All @@ -250,9 +250,9 @@ HtmlRoot {
3: R_ANGLE@66..67 ">" [] []
1: SVELTE_AWAIT_CATCH_BLOCK@67..107
0: SV_CURLY_COLON@67..70 "{:" [Newline("\n")] []
1: CATCH_KW@70..75 "catch" [] []
2: HTML_TEXT_EXPRESSION@75..81
0: HTML_LITERAL@75..81 " error" [] []
1: CATCH_KW@70..76 "catch" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@76..81
0: HTML_LITERAL@76..81 "error" [] []
3: R_CURLY@81..82 "}" [] []
4: HTML_ELEMENT_LIST@82..107
0: HTML_ELEMENT@82..107
Expand All @@ -276,9 +276,9 @@ HtmlRoot {
3: R_ANGLE@106..107 ">" [] []
2: SVELTE_AWAIT_CATCH_BLOCK@107..161
0: SV_CURLY_COLON@107..110 "{:" [Newline("\n")] []
1: CATCH_KW@110..115 "catch" [] []
2: HTML_TEXT_EXPRESSION@115..128
0: HTML_LITERAL@115..128 " anotherError" [] []
1: CATCH_KW@110..116 "catch" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@116..128
0: HTML_LITERAL@116..128 "anotherError" [] []
3: R_CURLY@128..129 "}" [] []
4: HTML_ELEMENT_LIST@129..161
0: HTML_ELEMENT@129..161
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ HtmlRoot {
clauses: SvelteAwaitClausesList [
SvelteAwaitThenBlock {
sv_curly_colon_token: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] [],
then_token: THEN_KW@39..43 "then" [] [],
then_token: THEN_KW@39..44 "then" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@43..49 " value" [] [],
html_literal_token: HTML_LITERAL@44..49 "value" [] [],
},
r_curly_token: R_CURLY@49..50 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -101,9 +101,9 @@ HtmlRoot {
},
SvelteAwaitThenBlock {
sv_curly_colon_token: SV_CURLY_COLON@67..70 "{:" [Newline("\n")] [],
then_token: THEN_KW@70..74 "then" [] [],
then_token: THEN_KW@70..75 "then" [] [Whitespace(" ")],
name: HtmlTextExpression {
html_literal_token: HTML_LITERAL@74..87 " anotherValue" [] [],
html_literal_token: HTML_LITERAL@75..87 "anotherValue" [] [],
},
r_curly_token: R_CURLY@87..88 "}" [] [],
children: HtmlElementList [
Expand Down Expand Up @@ -185,9 +185,9 @@ HtmlRoot {
1: SVELTE_AWAIT_CLAUSES_LIST@36..112
0: SVELTE_AWAIT_THEN_BLOCK@36..67
0: SV_CURLY_COLON@36..39 "{:" [Newline("\n")] []
1: THEN_KW@39..43 "then" [] []
2: HTML_TEXT_EXPRESSION@43..49
0: HTML_LITERAL@43..49 " value" [] []
1: THEN_KW@39..44 "then" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@44..49
0: HTML_LITERAL@44..49 "value" [] []
3: R_CURLY@49..50 "}" [] []
4: HTML_ELEMENT_LIST@50..67
0: HTML_ELEMENT@50..67
Expand All @@ -211,9 +211,9 @@ HtmlRoot {
3: R_ANGLE@66..67 ">" [] []
1: SVELTE_AWAIT_THEN_BLOCK@67..112
0: SV_CURLY_COLON@67..70 "{:" [Newline("\n")] []
1: THEN_KW@70..74 "then" [] []
2: HTML_TEXT_EXPRESSION@74..87
0: HTML_LITERAL@74..87 " anotherValue" [] []
1: THEN_KW@70..75 "then" [] [Whitespace(" ")]
2: HTML_TEXT_EXPRESSION@75..87
0: HTML_LITERAL@75..87 "anotherValue" [] []
3: R_CURLY@87..88 "}" [] []
4: HTML_ELEMENT_LIST@88..112
0: HTML_ELEMENT@88..112
Expand Down
Loading
Loading