Compress conditions that have side effects using sequences

This commit is contained in:
Tal Ater
2014-09-04 02:57:49 +03:00
parent 7971ed33d1
commit fb0ec720a4
2 changed files with 27 additions and 15 deletions

View File

@@ -2322,11 +2322,15 @@ merge(Compressor.prototype, {
});
}
// x=y?1:1 --> x=1
if (!self.condition.has_side_effects(compressor)
&& consequent instanceof AST_Constant
if (consequent instanceof AST_Constant
&& alternative instanceof AST_Constant
&& consequent.equivalent_to(alternative)) {
return make_node_from_constant(compressor, consequent.value, self);
if (self.condition.has_side_effects(compressor)) {
return AST_Seq.from_array([self.condition, make_node_from_constant(compressor, consequent.value, self)]);
} else {
return make_node_from_constant(compressor, consequent.value, self);
}
}
return self;
});