diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-25 10:31:03 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-25 10:31:03 +0300 |
commit | 368ac8f93ca7ea704ee0eabd419cd083c6b843aa (patch) | |
tree | 17cf38c6e8c9094b7d1c6a6a8c4867833e22c48c /lib/compress.js | |
parent | 42038fd67f49be16a01be8a7f8085d9a52f13c50 (diff) | |
download | tracifyjs-368ac8f93ca7ea704ee0eabd419cd083c6b843aa.tar.gz tracifyjs-368ac8f93ca7ea704ee0eabd419cd083c6b843aa.zip |
some boolean cleanup
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 75 |
1 files changed, 24 insertions, 51 deletions
diff --git a/lib/compress.js b/lib/compress.js index a93b39b9..c6524e09 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1573,35 +1573,6 @@ function Compressor(options, false_by_default) { self.right = tmp; }; switch (self.operator) { - case "==": - case "!=": - var ll = self.left.evaluate(compressor); - var rr = self.right.evaluate(compressor); - if (ll.length == 2 && typeof ll[1] == "boolean") { - compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", { - operator : self.operator, - value : ll[1], - file : self.start.file, - line : self.start.line, - col : self.start.col - }); - self.left = make_node(AST_Number, self.left, { - value: +ll[1] - }); - } - if (rr.length == 2 && typeof rr[1] == "boolean") { - compressor.warn("Non-strict equality against boolean {operator} {value} [{file}:{line},{col}]", { - operator : self.operator, - value : rr[1], - file : self.start.file, - line : self.start.line, - col : self.start.col - }); - self.right = make_node(AST_Number, self.right, { - value: +rr[1] - }); - } - break; case "<": reverse(">"); break; case "<=": reverse(">="); break; } @@ -1743,31 +1714,33 @@ function Compressor(options, false_by_default) { return self; }); - SQUEEZE(AST_True, function(self, compressor){ + SQUEEZE(AST_Boolean, function(self, compressor){ return self.optimize(compressor); }); - AST_True.DEFMETHOD("optimize", function(compressor){ - if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, this, { - operator: "!", - expression: make_node(AST_Number, this, { - value: 0 - }) - }); - return this; - }); - - SQUEEZE(AST_False, function(self, compressor){ - return self.optimize(compressor); - }); - - AST_False.DEFMETHOD("optimize", function(compressor){ - if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, this, { - operator: "!", - expression: make_node(AST_Number, this, { - value: 1 - }) - }); + AST_Boolean.DEFMETHOD("optimize", function(compressor){ + if (compressor.option("booleans")) { + var p = compressor.parent(); + if (p instanceof AST_Binary && (p.operator == "==" + || p.operator == "!=")) { + compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", { + operator : p.operator, + value : this.value, + file : p.start.file, + line : p.start.line, + col : p.start.col, + }); + return make_node(AST_Number, this, { + value: +this.value + }); + } + return make_node(AST_UnaryPrefix, this, { + operator: "!", + expression: make_node(AST_Number, this, { + value: 1 - this.value + }) + }); + } return this; }); |