Skip to content

Commit

Permalink
fix(javascript): add parens for unary in bind (#4950)
Browse files Browse the repository at this point in the history
* test: add tests

* fix(javascript): add parens for unary in bind
  • Loading branch information
ikatyang committed Aug 8, 2018
1 parent e72cb53 commit 4d2f224
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/language-js/needs-parens.js
Expand Up @@ -168,6 +168,7 @@ function needsParens(path, options) {
(node.operator === "+" || node.operator === "-")
);

case "BindExpression":
case "MemberExpression":
return name === "object" && parent.object === node;

Expand Down
22 changes: 22 additions & 0 deletions tests/bind_expressions/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -215,3 +215,25 @@ class X {
}
`;

exports[`unary.js - babylon-verify 1`] = `
(void 0)::func();
(+0)::is(-0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(void 0)::func();
(+0)::is(-0);
`;

exports[`unary.js - babylon-verify 2`] = `
(void 0)::func();
(+0)::is(-0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;(void 0)::func()
;(+0)::is(-0)
`;
3 changes: 3 additions & 0 deletions tests/bind_expressions/unary.js
@@ -0,0 +1,3 @@
(void 0)::func();

(+0)::is(-0);

0 comments on commit 4d2f224

Please sign in to comment.