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/nested-each-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-plugin-svelte": patch
---

fix: preserve nested rest patterns in `{#each}` destructuring
3 changes: 2 additions & 1 deletion src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,8 @@ function _expandNode(node: any, original: string, parent?: any): string {
}
}
case 'RestElement':
return ' ...' + node.argument.name;
// argument may be a nested Array/ObjectPattern, not only an Identifier
return ' ...' + _expandNode(node.argument, original).slice(1);
}

console.error(JSON.stringify(node, null, 4));
Expand Down
7 changes: 7 additions & 0 deletions test/printer/samples/each-block-destructured-nested-rest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{#each array as [first, second, ...[third, ...{ length }]]}
<p>{first} {second} {third} {length}</p>
{/each}

{#each items as [head, ...{ length }]}
<p>{head} {length}</p>
{/each}
Loading