fix corner case in conditionals (#4492)
This commit is contained in:
@@ -9843,10 +9843,17 @@ merge(Compressor.prototype, {
|
|||||||
&& !condition.has_side_effects(compressor)
|
&& !condition.has_side_effects(compressor)
|
||||||
&& !consequent.expression.has_side_effects(compressor)) {
|
&& !consequent.expression.has_side_effects(compressor)) {
|
||||||
var node = consequent.clone();
|
var node = consequent.clone();
|
||||||
node.args[arg_index] = make_node(AST_Conditional, self, {
|
var arg = consequent.args[arg_index];
|
||||||
|
node.args[arg_index] = arg instanceof AST_Spread ? make_node(AST_Spread, self, {
|
||||||
|
expression: make_node(AST_Conditional, self, {
|
||||||
condition: condition,
|
condition: condition,
|
||||||
consequent: consequent.args[arg_index],
|
consequent: arg.expression,
|
||||||
alternative: alternative.args[arg_index]
|
alternative: alternative.args[arg_index].expression,
|
||||||
|
}),
|
||||||
|
}) : make_node(AST_Conditional, self, {
|
||||||
|
condition: condition,
|
||||||
|
consequent: arg,
|
||||||
|
alternative: alternative.args[arg_index],
|
||||||
});
|
});
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,28 @@ collapse_vars_4: {
|
|||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conditionals_farg: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function log(msg) {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
var a = 42, b = [ "PASS" ], c = [ "FAIL" ];
|
||||||
|
a ? log(...b) : log(...c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function log(msg) {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
var a = 42, b = [ "PASS" ], c = [ "FAIL" ];
|
||||||
|
log(...a ? b : c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
dont_inline: {
|
dont_inline: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user