Skip to content

Commit

Permalink
(fix) properly format nested array patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Holthausen committed Nov 14, 2021
1 parent f5e5c4f commit 6ae9053
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* (feat) Support `bracketSameLine` option and deprecate `svelteBracketNewLine` ([#251](https://github.com/sveltejs/prettier-plugin-svelte/pull/251))
* (fix) Prevent script/style contents from being erased in certain cases ([#255](https://github.com/sveltejs/prettier-plugin-svelte/issues/255))
* (fix) Properly format nested array patterns ([#259](https://github.com/sveltejs/prettier-plugin-svelte/issues/259))

## 2.4.0

Expand Down
2 changes: 1 addition & 1 deletion src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ function expandNode(node: any): string {
case 'ObjectPattern':
return ' {' + node.properties.map(expandNode).join(',') + ' }';
case 'Property':
if (node.value.type === 'ObjectPattern') {
if (node.value.type === 'ObjectPattern' || node.value.type === 'ArrayPattern') {
return ' ' + node.key.name + ':' + expandNode(node.value);
} else if (node.value.type === 'Identifier' && node.key.name !== node.value.name) {
return expandNode(node.key) + ':' + expandNode(node.value);
Expand Down
7 changes: 7 additions & 0 deletions test/printer/samples/nested-destructuring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{#await thePromise}
<p>loading...</p>
{:then { data: [theValue] }}
<p>the value is {theValue}</p>
{:catch { data: [{ data: [theError] }] }}
<p>oh no! {theError.message}</p>
{/await}

0 comments on commit 6ae9053

Please sign in to comment.