Skip to content

Commit 5630294

Browse files
committed
fix: preserve commas in array expressions
fixes #432
1 parent a1a3f92 commit 5630294

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.2.7 (unreleased)
44

55
- (fix) force quote style inside style directives
6+
- (fix) preserve commas in array expressions
67
- (fix) Svelte 5: properly determine end of snippet parameters with TS annotations
78

89
## 3.2.6

src/print/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,16 @@ function _expandNode(node: any, parent?: any): string {
12061206
switch (node.type) {
12071207
case 'ArrayExpression':
12081208
case 'ArrayPattern':
1209-
return ' [' + node.elements.map(_expandNode).join(',').slice(1) + ']';
1209+
return (
1210+
' [' +
1211+
node.elements
1212+
// handle null specifically here; else it would become the empty string, but that would mean
1213+
// fewer elements in the array, which would change the meaning of the array
1214+
.map((el: any) => (el === null ? ' ' : _expandNode(el)))
1215+
.join(',')
1216+
.slice(1) +
1217+
']'
1218+
);
12101219
case 'AssignmentPattern':
12111220
return _expandNode(node.left) + ' =' + _expandNode(node.right);
12121221
case 'Identifier':
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{#each animals as [key, value]}
22
<p>{key}: {value}</p>
33
{/each}
4+
5+
{#each animals as [, value]}
6+
<p>{value}</p>
7+
{/each}

0 commit comments

Comments
 (0)