Fix parenthesis for call expression inside of member expression inside of new (#2035)
Fixes #2033master
parent
c7cacf0529
commit
cabae6d877
|
@ -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":
|
||||
|
|
|
@ -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());
|
||||
|
||||
`;
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
new (memoize.Cache || MapCache)
|
||||
new (typeof this == "function" ? this : Dict())
|
||||
new (createObj()).prop(a());
|
||||
|
|
Loading…
Reference in New Issue