Skip to content

Commit

Permalink
Merge pull request #14 from paoloricciuti/fix-object-expressions-stat…
Browse files Browse the repository at this point in the history
…ements

fix: add parenthesis to object expressions statements
  • Loading branch information
Rich-Harris authored Nov 30, 2024
2 parents 03c6151 + 8954ec2 commit af59c14
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,9 @@ const handlers = {

ExpressionStatement(node, state) {
if (
node.expression.type === 'AssignmentExpression' &&
node.expression.left.type === 'ObjectPattern'
node.expression.type === 'ObjectExpression' ||
(node.expression.type === 'AssignmentExpression' &&
node.expression.left.type === 'ObjectPattern')
) {
// is an AssignmentExpression to an ObjectPattern
state.commands.push('(');
Expand Down
1 change: 1 addition & 0 deletions test/samples/object-expressions/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let blah;
obj = { blah };
obj = { blah };
obj = { a: b };
({ a: 1, b: 1 });

obj = {
method() {
Expand Down
4 changes: 2 additions & 2 deletions test/samples/object-expressions/expected.js.map

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

1 change: 1 addition & 0 deletions test/samples/object-expressions/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let blah;
obj = { blah };
obj = { blah };
obj = { a: b };
({ a: 1, b: 1 });

obj = {
method() {
Expand Down

0 comments on commit af59c14

Please sign in to comment.