fix(javascript): add parens for unary in bind (#4950)

* test: add tests

* fix(javascript): add parens for unary in bind
master
Ika 2018-08-08 23:48:12 +08:00 committed by GitHub
parent e72cb538f9
commit 4d2f224919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -168,6 +168,7 @@ function needsParens(path, options) {
(node.operator === "+" || node.operator === "-")
);
case "BindExpression":
case "MemberExpression":
return name === "object" && parent.object === node;

View File

@ -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)
`;

View File

@ -0,0 +1,3 @@
(void 0)::func();
(+0)::is(-0);