Skip to content

Commit abfbb11

Browse files
dyc3claudeematipico
authored
fix(format/html): format a Svelte array pattern that skips a position (#11194)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent 77035bb commit abfbb11

5 files changed

Lines changed: 79 additions & 34 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed the HTML formatter refusing to format a Svelte file containing an array pattern that skips a position:
6+
7+
```svelte
8+
{#each animals as [, value]}
9+
<p>{value}</p>
10+
{/each}
11+
```
12+

crates/biome_html_formatter/src/svelte/lists/binding_assignment_binding_list.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,27 @@ impl FormatRule<SvelteBindingAssignmentBindingList> for FormatSvelteBindingAssig
1515
let mut join = f.join_nodes_with_space();
1616

1717
for binding_assignment in node.elements() {
18-
let node = binding_assignment.node()?;
1918
let separator = binding_assignment.trailing_separator()?;
2019

21-
join.entry(
22-
node.syntax(),
23-
&format_with(|f| {
24-
write!(f, [node.format()])?;
20+
match binding_assignment.node() {
21+
Ok(node) => join.entry(
22+
node.syntax(),
23+
&format_with(|f| {
24+
write!(f, [node.format()])?;
2525

26-
if let Some(separator) = separator {
27-
write!(f, [separator.format()])?;
28-
}
26+
if let Some(separator) = separator {
27+
write!(f, [separator.format()])?;
28+
}
2929

30-
Ok(())
31-
}),
32-
)
30+
Ok(())
31+
}),
32+
),
33+
Err(error) => {
34+
let separator = separator.ok_or(error)?;
35+
let parent = separator.parent().ok_or(error)?;
36+
join.entry(&parent, &separator.format());
37+
}
38+
}
3339
}
3440

3541
join.finish()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{#each animals as [, value]}
2+
<p>{value}</p>
3+
{/each}
4+
5+
{#each animals as [key, , value]}
6+
<p>{key}: {value}</p>
7+
{/each}
8+
9+
{#each animals as [key, value]}
10+
<p>{key}: {value}</p>
11+
{/each}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
info: svelte/each_array_hole.svelte
4+
---
5+
6+
# Input
7+
8+
```svelte
9+
{#each animals as [, value]}
10+
<p>{value}</p>
11+
{/each}
12+
13+
{#each animals as [key, , value]}
14+
<p>{key}: {value}</p>
15+
{/each}
16+
17+
{#each animals as [key, value]}
18+
<p>{key}: {value}</p>
19+
{/each}
20+
21+
```
22+
23+
24+
# Formatted
25+
26+
```svelte
27+
{#each animals as [, value]}
28+
<p>{value}</p>
29+
{/each}
30+
31+
{#each animals as [key, , value]}
32+
<p>{key}: {value}</p>
33+
{/each}
34+
35+
{#each animals as [key, value]}
36+
<p>{key}: {value}</p>
37+
{/each}
38+
39+
```

crates/biome_html_formatter/tests/specs/svelte-plugin/printer/each-block-destructured.svelte.snap

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)