Only transform foo() ? EXP(x) : EXP(y) into EXP(foo() ? x : y) if EXP has no
side effects.
Fix #710
if (consequent instanceof AST_Call
&& alternative.TYPE === consequent.TYPE
&& consequent.args.length == alternative.args.length
+ && !consequent.expression.has_side_effects(compressor)
&& consequent.expression.equivalent_to(alternative.expression)) {
if (consequent.args.length == 0) {
return make_node(AST_Seq, self, {
conditionals: true
};
input: {
+ var do_something; // if undeclared it's assumed to have side-effects
if (some_condition()) {
do_something(x);
} else {
}
}
expect: {
+ var do_something;
do_something(some_condition() ? x : y);
}
}
conditionals: true
};
input: {
- var x;
+ var x, FooBar;
if (some_condition()) {
x = new FooBar(1);
} else {
}
}
expect: {
- var x;
+ var x, FooBar;
x = new FooBar(some_condition() ? 1 : 2);
}
}
conditionals: true
};
input: {
+ var FooBar;
if (some_condition()) {
new FooBar(1);
} else {
}
}
expect: {
+ var FooBar;
some_condition() ? new FooBar(1) : FooBar(2);
}
}
conditionals: true
};
input: {
+ var do_something;
if (some_condition()) {
do_something();
} else {
}
}
expect: {
+ var do_something;
some_condition(), do_something();
}
}