Fix object expression in arrow function expression (#897)

* Add new case for keeping parens around ObjectExpression in ArrowFunctionExpression.

* Add new test.
master
Davy Duperron 2017-03-05 22:04:50 +01:00 committed by Christopher Chedeau
parent 860a9fd6d4
commit 2ef9896567
3 changed files with 12 additions and 0 deletions

View File

@ -246,6 +246,15 @@ FPp.needsParens = function(assumeExpressionContext) {
}
switch (node.type) {
case "CallExpression":
if (
node.callee.type === "ObjectExpression" &&
parent.type === "ArrowFunctionExpression"
) {
return true;
}
return false;
case "SpreadElement":
case "SpreadProperty":
return parent.type === "MemberExpression" &&

View File

@ -8,6 +8,7 @@ export default (() => {})();
(() => {})\`\`;
new (() => {});
if ((() => {}) ? 1 : 0) {}
let f = () => ({}())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(a => {}).length;
typeof (() => {});
@ -17,6 +18,7 @@ export default (() => {})();
new (() => {})();
if ((() => {}) ? 1 : 0) {
}
let f = () => ({}());
"
`;

View File

@ -5,3 +5,4 @@ export default (() => {})();
(() => {})``;
new (() => {});
if ((() => {}) ? 1 : 0) {}
let f = () => ({}())