Fix object expression in arrow function expression (#897)

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

* Add new test.
This commit is contained in:
Davy Duperron authored and Christopher Chedeau committed 2017-03-05 13:04:50 -08:00
1 parent 860a9fd6d4
commit 2ef9896567
3 files changed
+12

No files matched your search

+9
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" &&
@@ -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 = () => ({}());
"
`;
@@ -5,3 +5,4 @@ export default (() => {})();
(() => {})``;
new (() => {});
if ((() => {}) ? 1 : 0) {}
let f = () => ({}())