Fix parenthesis when call inside of new (#1169)

Fixes #1167
master
Christopher Chedeau 2017-04-10 10:49:13 -07:00 committed by GitHub
parent 6552257ab0
commit 8cc5f22090
3 changed files with 20 additions and 0 deletions

View File

@ -243,6 +243,9 @@ FPp.needsParens = function(assumeExpressionContext) {
switch (node.type) {
case "CallExpression":
if (parent.type === "NewExpression" && parent.callee === node) {
return true;
}
return false;
case "SpreadElement":

View File

@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`call.js 1`] = `
"new (factory())()
new factory()()
new (factory())(factory())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new (factory())();
new factory()();
new (factory())(factory());
"
`;
exports[`new_expression.js 1`] = `
"new (memoize.Cache || MapCache)
new (typeof this == \\"function\\" ? this : Dict())

View File

@ -0,0 +1,4 @@
new (factory())()
new factory()()
new (factory())(factory())