diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-14 19:04:18 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-14 19:04:18 +0300 |
commit | 50d1670e4266b7cefaccb4eef779ee6e08c980e1 (patch) | |
tree | fd7746a388576f2cce10d3c48cdc5c30e505a704 /lib/compress.js | |
parent | 5e83e7ec17aca27ea818ce380a53c72ee221b900 (diff) | |
download | tracifyjs-50d1670e4266b7cefaccb4eef779ee6e08c980e1.tar.gz tracifyjs-50d1670e4266b7cefaccb4eef779ee6e08c980e1.zip |
minor
when unsafe, compress undefined as [][0]
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 26 |
1 files changed, 22 insertions, 4 deletions
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; }); |