From: Mihai Bazon Date: Mon, 3 Sep 2012 20:49:57 +0000 (+0300) Subject: boolean and if/exit optimizations X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=86cfb5be86603b472085920a82905b22c9d06fea;p=UglifyJS.git boolean and if/exit optimizations --- diff --git a/lib/compress.js b/lib/compress.js index 7e8ad3b8..20af4707 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -62,6 +62,7 @@ function Compressor(options, false_by_default) { conditionals : !false_by_default, comparations : !false_by_default, evaluate : !false_by_default, + booleans : !false_by_default, warnings : true }); @@ -560,6 +561,17 @@ function Compressor(options, false_by_default) { }).optimize(compressor) }); } + if (self.body instanceof AST_Exit + && self.alternative instanceof AST_Exit + && self.body.TYPE == self.alternative.TYPE) { + return make_node(self.body.CTOR, self, { + value: make_node(AST_Conditional, self, { + condition : self.condition, + consequent : self.body.value, + alternative : self.alternative.value + }).optimize(compressor) + }); + } return self; }); @@ -709,4 +721,22 @@ function Compressor(options, false_by_default) { return self; }); + SQUEEZE(AST_True, function(self, compressor){ + if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, self, { + operator: "!", + expression: make_node(AST_Number, self, { + value: 0 + }) + }); + }); + + SQUEEZE(AST_False, function(self, compressor){ + if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, self, { + operator: "!", + expression: make_node(AST_Number, self, { + value: 1 + }) + }); + }); + })();