From: Mihai Bazon Date: Fri, 14 Sep 2012 16:04:18 +0000 (+0300) Subject: minor X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=50d1670e4266b7cefaccb4eef779ee6e08c980e1;p=UglifyJS.git minor when unsafe, compress undefined as [][0] --- diff --git a/lib/compress.js b/lib/compress.js index 3fd69402..b37dcfe7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -224,8 +224,8 @@ function Compressor(options, false_by_default) { && !statements[last - 1].alternative) { CHANGED = true; return MAP.splice([ stat, make_node(AST_Return, stat, { - value: make_node(AST_Undefined, stat) - })]); + value: make_node(AST_Undefined, stat).optimize(compressor) + }).optimize(compressor)]); } } if (stat instanceof AST_If @@ -439,7 +439,7 @@ function Compressor(options, false_by_default) { ast = make_node(val ? AST_True : AST_False, this); break; case "undefined": - ast = make_node(AST_Undefined, this); + ast = make_node(AST_Undefined, this).optimize(compressor); break; default: if (val === null) { @@ -1353,7 +1353,25 @@ function Compressor(options, false_by_default) { AST_SymbolRef.DEFMETHOD("optimize", function(compressor){ if (this.name == "undefined" && this.undeclared()) { - return make_node(AST_Undefined, this); + return make_node(AST_Undefined, this).optimize(compressor); + } + return this; + }); + + SQUEEZE(AST_Undefined, function(self, compressor){ + return self.optimize(compressor); + }); + + AST_Undefined.DEFMETHOD("optimize", function(compressor){ + if (compressor.option("unsafe") && !(compressor.parent() instanceof AST_Array)) { + return make_node(AST_Sub, this, { + expression: make_node(AST_Array, this, { + elements: [] + }), + property: make_node(AST_Number, this, { + value: 0 + }) + }); } return this; });