Skip to content

Commit 0900e23

Browse files
committed
fix(html): listing error
1 parent fa51a85 commit 0900e23

File tree

8 files changed

+92
-7
lines changed

8 files changed

+92
-7
lines changed

.changeset/nine-bottles-float.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added support for the Svelte syntax `{@debug}`. The Biome HTML parser is now able to parse and format the blocks:
6+
7+
```diff
8+
-{@debug foo,bar, something}
9+
+{@debug foo, bar, something}
10+
```

crates/biome_html_formatter/tests/specs/html/astro/debug.svelte renamed to crates/biome_html_formatter/tests/specs/html/svelte/debug.svelte

File renamed without changes.

crates/biome_html_formatter/tests/specs/html/astro/debug.svelte.snap renamed to crates/biome_html_formatter/tests/specs/html/svelte/debug.svelte.snap

File renamed without changes.

crates/biome_html_parser/src/syntax/parse_error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ pub(crate) fn closing_tag_should_not_have_attributes(
9494
}
9595

9696
pub(crate) fn expected_svelte_closing_block(p: &HtmlParser, range: TextRange) -> ParseDiagnostic {
97-
p.err_builder("Expected a closing block.", range)
98-
.with_hint(markup!("Add a '}' block."))
97+
p.err_builder("Expected an identifier.", range)
9998
}

crates/biome_html_parser/src/syntax/svelte.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ pub(crate) fn parse_debug_block(p: &mut HtmlParser, marker: Marker) -> ParsedSyn
3636
Present(marker.complete(p, SVELTE_DEBUG_BLOCK))
3737
}
3838

39-
const BLOCK_RECOVER: TokenSet<HtmlSyntaxKind> =
40-
token_set!(T!['{'], T![<], T!["{@"], T!["{/"], T!["{:"], T!["{#"]);
39+
const BLOCK_RECOVER: TokenSet<HtmlSyntaxKind> = token_set!(
40+
T!['{'],
41+
T![<],
42+
T!["{@"],
43+
T!["{/"],
44+
T!["{:"],
45+
T!["{#"],
46+
T!['}']
47+
);
4148

4249
#[derive(Debug)]
4350
struct BindingList;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{@debug something,}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
source: crates/biome_html_parser/tests/spec_test.rs
3+
expression: snapshot
4+
---
5+
## Input
6+
7+
```svelte
8+
{@debug something,}
9+
10+
```
11+
12+
13+
## AST
14+
15+
```
16+
HtmlRoot {
17+
bom_token: missing (optional),
18+
frontmatter: missing (optional),
19+
directive: missing (optional),
20+
html: HtmlElementList [
21+
SvelteDebugBlock {
22+
sv_curly_at_token: SV_CURLY_AT@0..2 "{@" [] [],
23+
debug_token: DEBUG_KW@2..8 "debug" [] [Whitespace(" ")],
24+
bindings: SvelteBindingList [
25+
SvelteName {
26+
svelte_ident_token: SVELTE_IDENT@8..17 "something" [] [],
27+
},
28+
COMMA@17..18 "," [] [],
29+
missing element,
30+
],
31+
r_curly_token: R_CURLY@18..19 "}" [] [],
32+
},
33+
],
34+
eof_token: EOF@19..20 "" [Newline("\n")] [],
35+
}
36+
```
37+
38+
## CST
39+
40+
```
41+
42+
0: (empty)
43+
1: (empty)
44+
2: (empty)
45+
46+
47+
0: [email protected] "{@" [] []
48+
1: DEBUG_KW@2..8 "debug" [] [Whitespace(" ")]
49+
2: SVELTE_BINDING_LIST@8..18
50+
0: SVELTE_NAME@8..17
51+
0: SVELTE_IDENT@8..17 "something" [] []
52+
1: COMMA@17..18 "," [] []
53+
2: (empty)
54+
3: R_CURLY@18..19 "}" [] []
55+
4: EOF@19..20 "" [Newline("\n")] []
56+
57+
```
58+
59+
## Diagnostics
60+
61+
```
62+
debug-trailing-comma.svelte:1:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
63+
64+
× Expected an identifier.
65+
66+
> 1 │ {@debug something,}
67+
^
68+
2
69+
70+
```

crates/biome_html_parser/tests/html_specs/error/svelte/debug.svelte.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ HtmlRoot {
6969
```
7070
debug.svelte:2:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
7171
72-
× Expected a closing block.
72+
× Expected an identifier.
7373
7474
1 │ {@debug
7575
> 2 │ {@debug something}
7676
^^
7777
3
7878
79-
i Add a '}' block.
80-
8179
```

0 commit comments

Comments
 (0)