aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorTal Ater <tal@talater.com>2014-09-02 23:30:25 +0300
committerTal Ater <tal@talater.com>2014-09-02 23:30:25 +0300
commit885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7 (patch)
tree3d29a96ef884f7368c040f9453b2346f3de01435 /lib/compress.js
parent4c64554808e0805b86893704dc87df9ec449961a (diff)
downloadtracifyjs-885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7.tar.gz
tracifyjs-885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7.zip
Compress conditional assignments where all possible outcomes are equivalant and condition has no side effects
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index b55361b3..e493e5fe 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2321,6 +2321,13 @@ merge(Compressor.prototype, {
alternative: alternative
});
}
+ // x=y?1:1 --> x=1
+ if (!self.condition.has_side_effects(compressor)
+ && consequent instanceof AST_Constant
+ && alternative instanceof AST_Constant
+ && consequent.equivalent_to(alternative)) {
+ return make_node_from_constant(compressor, consequent.value, self);
+ }
return self;
});