@@ -12706,13 +12706,23 @@ Compressor.prototype.compress = function(node) {
|
||||
return try_evaluate(compressor, self);
|
||||
|
||||
function is_tail(node, parent) {
|
||||
if (parent instanceof AST_Binary) {
|
||||
return parent.right === node || parent.right.is_constant_expression(scope);
|
||||
if (parent instanceof AST_Binary) switch (node) {
|
||||
case parent.left:
|
||||
return parent.right.is_constant_expression(scope);
|
||||
case parent.right:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (parent instanceof AST_Conditional) {
|
||||
return parent.condition !== node
|
||||
|| parent.consequent.is_constant_expression(scope)
|
||||
if (parent instanceof AST_Conditional) switch (node) {
|
||||
case parent.condition:
|
||||
return parent.consequent.is_constant_expression(scope)
|
||||
&& parent.alternative.is_constant_expression(scope);
|
||||
case parent.consequent:
|
||||
case parent.alternative:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (parent instanceof AST_Sequence) {
|
||||
var exprs = parent.expressions;
|
||||
@@ -12723,7 +12733,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (parent instanceof AST_UnaryPrefix) return true;
|
||||
return parent instanceof AST_UnaryPrefix;
|
||||
}
|
||||
|
||||
function is_tail_block(stat, parent) {
|
||||
|
||||
@@ -1705,3 +1705,28 @@ issue_5506: {
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5641: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
if (a || b) {
|
||||
var b = "PASS", c = b && console.log(b);
|
||||
} else
|
||||
var d = a || b;
|
||||
}
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c, d;
|
||||
(a || b) && (b = "PASS") && console.log(b);
|
||||
}
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user