Skip to content

Commit 13dd884

Browse files
author
Declan Vong
authored
fix: don't strip parens around a destructuring assignment (#308)
1 parent 4c88f68 commit 13dd884

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/parsing/parser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,14 @@ fn should_skip_paren_expr(node: &ParenExpr, context: &Context) -> bool {
23902390
return false;
23912391
}
23922392

2393+
// keep parens around any destructuring assignments
2394+
if let Node::AssignExpr(assign_expr) = node.expr.as_node() {
2395+
let left_kind = assign_expr.left.kind();
2396+
if matches!(left_kind, NodeKind::ObjectPat) {
2397+
return false;
2398+
}
2399+
}
2400+
23932401
if matches!(node.expr.kind(), NodeKind::ArrayLit) {
23942402
return true;
23952403
}

tests/specs/issues/issue0306.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
== should not remove parentheses around a destructuring assignment ==
2+
({ a } = b);
3+
(a = b);
4+
5+
[expect]
6+
({ a } = b);
7+
a = b;

0 commit comments

Comments
 (0)