Fix parenthesis for call expression inside of member expression inside of new (#2035)

Fixes #2033
master
Christopher Chedeau 2017-06-07 12:40:27 -07:00 committed by GitHub
parent c7cacf0529
commit cabae6d877
3 changed files with 18 additions and 2 deletions

View File

@ -194,11 +194,24 @@ FastPath.prototype.needsParens = function() {
}
switch (node.type) {
case "CallExpression":
if (parent.type === "NewExpression" && parent.callee === node) {
case "CallExpression": {
let firstParentNotMemberExpression = parent;
let i = 0;
while (
firstParentNotMemberExpression &&
firstParentNotMemberExpression.type === "MemberExpression"
) {
firstParentNotMemberExpression = this.getParentNode(++i);
}
if (
firstParentNotMemberExpression.type === "NewExpression" &&
firstParentNotMemberExpression.callee === this.getParentNode(i - 1)
) {
return true;
}
return false;
}
case "SpreadElement":
case "SpreadProperty":

View File

@ -16,8 +16,10 @@ new (factory())(factory());
exports[`new_expression.js 1`] = `
new (memoize.Cache || MapCache)
new (typeof this == "function" ? this : Dict())
new (createObj()).prop(a());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new (memoize.Cache || MapCache)();
new (typeof this == "function" ? this : Dict())();
new (createObj()).prop(a());
`;

View File

@ -1,2 +1,3 @@
new (memoize.Cache || MapCache)
new (typeof this == "function" ? this : Dict())
new (createObj()).prop(a());