Stop dropping args in new expressions
This commit is contained in:
committed by
Richard van Velzen
parent
9c53c7ada7
commit
6c8e001fee
@@ -594,7 +594,7 @@ function OutputStream(options) {
|
||||
|
||||
PARENS(AST_New, function(output){
|
||||
var p = output.parent();
|
||||
if (no_constructor_parens(this, output)
|
||||
if (!need_constructor_parens(this, output)
|
||||
&& (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()
|
||||
|| p instanceof AST_Call && p.expression === this)) // (new foo)(bar)
|
||||
return true;
|
||||
@@ -995,7 +995,7 @@ function OutputStream(options) {
|
||||
/* -----[ other expressions ]----- */
|
||||
DEFPRINT(AST_Call, function(self, output){
|
||||
self.expression.print(output);
|
||||
if (self instanceof AST_New && no_constructor_parens(self, output))
|
||||
if (self instanceof AST_New && !need_constructor_parens(self, output))
|
||||
return;
|
||||
output.with_parens(function(){
|
||||
self.args.forEach(function(expr, i){
|
||||
@@ -1285,13 +1285,9 @@ function OutputStream(options) {
|
||||
};
|
||||
|
||||
// self should be AST_New. decide if we want to show parens or not.
|
||||
function no_constructor_parens(self, output) {
|
||||
return self.args.length == 0 && !output.option("beautify") ||
|
||||
!(self.expression instanceof AST_SymbolRef ||
|
||||
self.expression instanceof AST_Call ||
|
||||
self.expression instanceof AST_Function ||
|
||||
self.expression instanceof AST_Assign
|
||||
);
|
||||
function need_constructor_parens(self, output) {
|
||||
// Always print parentheses with arguments
|
||||
return self.args.length > 0;
|
||||
};
|
||||
|
||||
function best_of(a) {
|
||||
|
||||
Reference in New Issue
Block a user