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/honest-shirts-wear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#10003](https://github.com/biomejs/biome/issues/10003): Biome no longer panics when parsing Svelte files containing `{#}`.
26 changes: 22 additions & 4 deletions crates/biome_html_parser/src/syntax/svelte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ pub(crate) fn parse_svelte_hash_block(p: &mut HtmlParser) -> ParsedSyntax {
T![await] => parse_await_block(p, m),
T![snippet] => parse_snippet_block(p, m),
_ => {
m.abandon(p);
Absent
p.error(p.err_builder(
"Expected `if`, `each`, `key`, `await`, or `snippet`",
p.cur_range(),
));

if !p.at(T!['}']) {
let _ = ParseRecoveryTokenSet::new(HTML_BOGUS, token_set![T!['}']]).recover(p);
}

p.expect(T!['}']);
Present(m.complete(p, SVELTE_BOGUS_BLOCK))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
Expand Down Expand Up @@ -826,8 +835,17 @@ pub(crate) fn parse_svelte_at_block(p: &mut HtmlParser) -> ParsedSyntax {
T![render] => parse_render_block(p, m),
T![const] => parse_const_block(p, m),
_ => {
m.abandon(p);
Absent
p.error(p.err_builder(
"Expected `render`, `html`, `const`, or `debug`",
p.cur_range(),
));

if !p.at(T!['}']) {
let _ = ParseRecoveryTokenSet::new(HTML_BOGUS, token_set![T!['}']]).recover(p);
}

p.expect(T!['}']);
Present(m.complete(p, SVELTE_BOGUS_BLOCK))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{@notarealblocktype}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```svelte
{@notarealblocktype}

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
SvelteBogusBlock {
items: [
SV_CURLY_AT@0..2 "{@" [] [],
HtmlBogus {
items: [
IDENT@2..19 "notarealblocktype" [] [],
],
},
R_CURLY@19..20 "}" [] [],
],
},
],
eof_token: EOF@20..21 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..21
0: (empty)
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..20
0: SVELTE_BOGUS_BLOCK@0..20
0: SV_CURLY_AT@0..2 "{@" [] []
1: HTML_BOGUS@2..19
0: IDENT@2..19 "notarealblocktype" [] []
2: R_CURLY@19..20 "}" [] []
4: EOF@20..21 "" [Newline("\n")] []

```

## Diagnostics

```
at_block_invalid_block_type.svelte:1:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected `render`, `html`, `const`, or `debug`

> 1 │ {@notarealblocktype}
│ ^^^^^^^^^^^^^^^^^
2 │

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{@}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```svelte
{@}

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
SvelteBogusBlock {
items: [
SV_CURLY_AT@0..2 "{@" [] [],
R_CURLY@2..3 "}" [] [],
],
},
],
eof_token: EOF@3..4 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..4
0: (empty)
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..3
0: SVELTE_BOGUS_BLOCK@0..3
0: SV_CURLY_AT@0..2 "{@" [] []
1: R_CURLY@2..3 "}" [] []
4: EOF@3..4 "" [Newline("\n")] []

```

## Diagnostics

```
at_block_missing_block_type.svelte:1:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected `render`, `html`, `const`, or `debug`

> 1 │ {@}
│ ^
2 │

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{@
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```svelte
{@

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
SvelteBogusBlock {
items: [
SV_CURLY_AT@0..2 "{@" [] [],
],
},
],
eof_token: EOF@2..3 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..3
0: (empty)
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..2
0: SVELTE_BOGUS_BLOCK@0..2
0: SV_CURLY_AT@0..2 "{@" [] []
4: EOF@2..3 "" [Newline("\n")] []

```

## Diagnostics

```
at_block_missing_block_type_and_closing_brace.svelte:2:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected `render`, `html`, `const`, or `debug`

1 │ {@
> 2 │

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#notarealblocktype}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```svelte
{#notarealblocktype}
```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
SvelteBogusBlock {
items: [
SV_CURLY_HASH@0..2 "{#" [] [],
HtmlBogus {
items: [
IDENT@2..19 "notarealblocktype" [] [],
],
},
R_CURLY@19..20 "}" [] [],
],
},
],
eof_token: EOF@20..20 "" [] [],
}
```

## CST

```
0: HTML_ROOT@0..20
0: (empty)
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..20
0: SVELTE_BOGUS_BLOCK@0..20
0: SV_CURLY_HASH@0..2 "{#" [] []
1: HTML_BOGUS@2..19
0: IDENT@2..19 "notarealblocktype" [] []
2: R_CURLY@19..20 "}" [] []
4: EOF@20..20 "" [] []

```

## Diagnostics

```
template_invalid_block_type.svelte:1:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected `if`, `each`, `key`, `await`, or `snippet`

> 1 │ {#notarealblocktype}
│ ^^^^^^^^^^^^^^^^^

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```svelte
{#}

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: missing (optional),
directive: missing (optional),
html: HtmlElementList [
SvelteBogusBlock {
items: [
SV_CURLY_HASH@0..2 "{#" [] [],
R_CURLY@2..3 "}" [] [],
],
},
],
eof_token: EOF@3..4 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..4
0: (empty)
1: (empty)
2: (empty)
3: HTML_ELEMENT_LIST@0..3
0: SVELTE_BOGUS_BLOCK@0..3
0: SV_CURLY_HASH@0..2 "{#" [] []
1: R_CURLY@2..3 "}" [] []
4: EOF@3..4 "" [Newline("\n")] []

```

## Diagnostics

```
template_missing_block_type.svelte:1:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Expected `if`, `each`, `key`, `await`, or `snippet`

> 1 │ {#}
│ ^
2 │

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#
Loading
Loading