From: Mihai Bazon Date: Fri, 18 Jul 2014 08:31:41 +0000 (+0300) Subject: Fix parens for AST_Undefined X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=62bda71c853e844f0477873397ae7ae211bc7dc8;p=UglifyJS.git Fix parens for AST_Undefined Do the same as for AST_Unary, since we output undefined as `void 0`. Reported at https://github.com/mishoo/UglifyJS2/issues/338#issuecomment-48858341 --- diff --git a/lib/output.js b/lib/output.js index 6c8f15aa..7fe61af3 100644 --- a/lib/output.js +++ b/lib/output.js @@ -434,7 +434,13 @@ function OutputStream(options) { /* -----[ PARENTHESES ]----- */ function PARENS(nodetype, func) { - nodetype.DEFMETHOD("needs_parens", func); + if (Array.isArray(nodetype)) { + nodetype.forEach(function(nodetype){ + PARENS(nodetype, func); + }); + } else { + nodetype.DEFMETHOD("needs_parens", func); + } }; PARENS(AST_Node, function(){ @@ -453,7 +459,7 @@ function OutputStream(options) { return first_in_statement(output); }); - PARENS(AST_Unary, function(output){ + PARENS([ AST_Unary, AST_Undefined ], function(output){ var p = output.parent(); return p instanceof AST_PropAccess && p.expression === this; }); @@ -549,7 +555,7 @@ function OutputStream(options) { return true; }); - function assign_and_conditional_paren_rules(output) { + PARENS([ AST_Assign, AST_Conditional ], function (output){ var p = output.parent(); // !(a = false) β†’ true if (p instanceof AST_Unary) @@ -566,10 +572,7 @@ function OutputStream(options) { // (a = foo)["prop"] β€”orβ€” (a = foo).prop if (p instanceof AST_PropAccess && p.expression === this) return true; - }; - - PARENS(AST_Assign, assign_and_conditional_paren_rules); - PARENS(AST_Conditional, assign_and_conditional_paren_rules); + }); /* -----[ PRINTERS ]----- */