Merge pull request #1155 from kzc/issue_1154
Fix conditional expressions of form (x ? -1 : -1)
This commit is contained in:
@@ -2746,7 +2746,7 @@ merge(Compressor.prototype, {
|
|||||||
if (consequent.is_constant(compressor)
|
if (consequent.is_constant(compressor)
|
||||||
&& alternative.is_constant(compressor)
|
&& alternative.is_constant(compressor)
|
||||||
&& consequent.equivalent_to(alternative)) {
|
&& consequent.equivalent_to(alternative)) {
|
||||||
var consequent_value = consequent.constant_value();
|
var consequent_value = consequent.constant_value(compressor);
|
||||||
if (self.condition.has_side_effects(compressor)) {
|
if (self.condition.has_side_effects(compressor)) {
|
||||||
return AST_Seq.from_array([self.condition, make_node_from_constant(compressor, consequent_value, self)]);
|
return AST_Seq.from_array([self.condition, make_node_from_constant(compressor, consequent_value, self)]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -868,3 +868,41 @@ trivial_boolean_ternary_expressions : {
|
|||||||
f(!(x >= y));
|
f(!(x >= y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1154: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate : true,
|
||||||
|
booleans : true,
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
function f1(x) { return x ? -1 : -1; }
|
||||||
|
function f2(x) { return x ? +2 : +2; }
|
||||||
|
function f3(x) { return x ? ~3 : ~3; }
|
||||||
|
function f4(x) { return x ? !4 : !4; }
|
||||||
|
function f5(x) { return x ? void 5 : void 5; }
|
||||||
|
function f6(x) { return x ? typeof 6 : typeof 6; }
|
||||||
|
|
||||||
|
function g1() { return g() ? -1 : -1; }
|
||||||
|
function g2() { return g() ? +2 : +2; }
|
||||||
|
function g3() { return g() ? ~3 : ~3; }
|
||||||
|
function g4() { return g() ? !4 : !4; }
|
||||||
|
function g5() { return g() ? void 5 : void 5; }
|
||||||
|
function g6() { return g() ? typeof 6 : typeof 6; }
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1(x) { return -1; }
|
||||||
|
function f2(x) { return 2; }
|
||||||
|
function f3(x) { return -4; }
|
||||||
|
function f4(x) { return !1; }
|
||||||
|
function f5(x) { return; }
|
||||||
|
function f6(x) { return "number"; }
|
||||||
|
|
||||||
|
function g1() { return g(), -1; }
|
||||||
|
function g2() { return g(), 2; }
|
||||||
|
function g3() { return g(), -4; }
|
||||||
|
function g4() { return g(), !1; }
|
||||||
|
function g5() { return g(), void 0; }
|
||||||
|
function g6() { return g(), "number"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user