aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-17 11:50:35 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-17 11:50:35 +0300
commit07f1d56f69a5190d33400d4e5d4032edcaf016ff (patch)
tree1e1ad5be7c841e4f76c53b9c283430bea6dbfd4c /lib/compress.js
parent5e60a60b3b9ddea872187cf6568ebbcad58c1a60 (diff)
downloadtracifyjs-07f1d56f69a5190d33400d4e5d4032edcaf016ff.tar.gz
tracifyjs-07f1d56f69a5190d33400d4e5d4032edcaf016ff.zip
more smallish optimizations
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 09dc1802..ddb4437b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1321,9 +1321,10 @@ function Compressor(options, false_by_default) {
});
AST_UnaryPrefix.DEFMETHOD("optimize", function(compressor){
+ var self = this;
+ var e = self.expression;
if (compressor.option("booleans") && compressor.in_boolean_context()) {
- var e = this.expression;
- switch (this.operator) {
+ switch (self.operator) {
case "!":
if (e instanceof AST_UnaryPrefix && e.operator == "!") {
// !!foo ==> foo, if we're in boolean context
@@ -1333,11 +1334,14 @@ function Compressor(options, false_by_default) {
case "typeof":
// typeof always returns a non-empty string, thus it's
// always true in booleans
- compressor.warn("Boolean expression always true [{line},{col}]", this.start);
- return make_node(AST_True, this).optimize(compressor);
+ compressor.warn("Boolean expression always true [{line},{col}]", self.start);
+ return make_node(AST_True, self).optimize(compressor);
}
}
- return this.evaluate(compressor)[0];
+ if (e instanceof AST_Binary) {
+ self = best_of(self, e.negate(compressor));
+ }
+ return self.evaluate(compressor)[0];
});
SQUEEZE(AST_Binary, function(self, compressor){
@@ -1531,6 +1535,11 @@ function Compressor(options, false_by_default) {
AST_Conditional.DEFMETHOD("optimize", function(compressor){
var self = this;
if (!compressor.option("conditionals")) return self;
+ if (self.condition instanceof AST_Seq) {
+ var car = self.condition.car;
+ self.condition = self.condition.cdr;
+ return AST_Seq.cons(car, self.optimize(compressor)).optimize(compressor);
+ }
var cond = self.condition.evaluate(compressor);
if (cond.length == 2) {
if (cond[1]) {