aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMatt Basta <me@mattbasta.com>2014-02-06 12:39:13 -0800
committerMatt Basta <me@mattbasta.com>2014-02-06 12:39:13 -0800
commitac0086a74521ffce97b6e8bde0bee54feb0c5ec9 (patch)
tree70d1e1f1472b0365cadc1058b66c169e80d8b4cb /lib/compress.js
parent5344b7dab897fe266db9524a99529d6b64e9386e (diff)
downloadtracifyjs-ac0086a74521ffce97b6e8bde0bee54feb0c5ec9.tar.gz
tracifyjs-ac0086a74521ffce97b6e8bde0bee54feb0c5ec9.zip
Simplify nested conditionals if possible
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1b6bedd5..005c606d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2296,6 +2296,19 @@ merge(Compressor.prototype, {
return consequent;
}
}
+ // x?y?z:a:a --> x&&y?z:a
+ if (consequent instanceof AST_Conditional
+ && consequent.alternative.equivalent_to(alternative)) {
+ return make_node(AST_Conditional, self, {
+ condition: make_node(AST_Binary, self, {
+ left: self.condition,
+ operator: "&&",
+ right: consequent.condition
+ }),
+ consequent: consequent.consequent,
+ alternative: alternative
+ });
+ }
return self;
});