From 86cfb5be86603b472085920a82905b22c9d06fea Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Mon, 3 Sep 2012 23:49:57 +0300 Subject: [PATCH] boolean and if/exit optimizations --- lib/compress.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 + }) + }); + }); + })(); -- 2.34.1