diff options
author | Mihai Bazon <mihai@bazon.net> | 2014-07-18 11:31:41 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2014-07-18 11:31:41 +0300 |
commit | 62bda71c853e844f0477873397ae7ae211bc7dc8 (patch) | |
tree | 0b86e4cdb6309f9785e8bf3d6c0849be2c958c68 | |
parent | 83e0939088a26ad8c28bd2c1719f92bdcf17d045 (diff) | |
download | tracifyjs-62bda71c853e844f0477873397ae7ae211bc7dc8.tar.gz tracifyjs-62bda71c853e844f0477873397ae7ae211bc7dc8.zip |
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
-rw-r--r-- | lib/output.js | 17 |
1 files changed, 10 insertions, 7 deletions
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 ]----- */ |