Skip to content

Commit

Permalink
wrap arrow function body in parentheses when it is an object destruct…
Browse files Browse the repository at this point in the history
…uring assignment (#70)
  • Loading branch information
sahilmob authored Jan 6, 2022
1 parent 590c981 commit 93f852c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/print/handlers.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,10 @@ const handlers = {

chunks.push(c(' => '));

if (node.body.type === 'ObjectExpression') {
if (
node.body.type === 'ObjectExpression' ||
(node.body.type === 'AssignmentExpression' && node.body.left.type === 'ObjectPattern')
) {
chunks.push(
c('('),
...handle(node.body, state),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a = () => ({ x } = { x: 42 });

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ({ b }) => b`let a = () => ({ x } = { x: 42 });`;

0 comments on commit 93f852c

Please sign in to comment.