enhance reduce_vars (#5163)
This commit is contained in:
@@ -899,30 +899,22 @@ merge(Compressor.prototype, {
|
||||
case "&&=":
|
||||
case "||=":
|
||||
case "??=":
|
||||
left.walk(tw);
|
||||
push(tw);
|
||||
if (scan) {
|
||||
right.walk(tw);
|
||||
walk_assign();
|
||||
} else {
|
||||
mark_assignment_to_arguments(left);
|
||||
right.walk(tw);
|
||||
}
|
||||
pop(tw);
|
||||
return true;
|
||||
var lazy = true;
|
||||
default:
|
||||
if (!scan) {
|
||||
mark_assignment_to_arguments(left);
|
||||
return;
|
||||
return walk_lazy();
|
||||
}
|
||||
ld.assignments++;
|
||||
var fixed = ld.fixed;
|
||||
if (is_modified(compressor, tw, node, node, 0)) {
|
||||
ld.fixed = false;
|
||||
return;
|
||||
return walk_lazy();
|
||||
}
|
||||
var safe = safe_to_read(tw, ld);
|
||||
if (lazy) push(tw);
|
||||
right.walk(tw);
|
||||
if (lazy) pop(tw);
|
||||
if (safe && !left.in_arg && safe_to_assign(tw, ld)) {
|
||||
push_ref(ld, left);
|
||||
mark(tw, ld);
|
||||
@@ -995,6 +987,15 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function walk_lazy() {
|
||||
if (!lazy) return;
|
||||
left.walk(tw);
|
||||
push(tw);
|
||||
right.walk(tw);
|
||||
pop(tw);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
def(AST_Binary, function(tw) {
|
||||
if (!lazy_op[this.operator]) return;
|
||||
|
||||
@@ -550,6 +550,24 @@ logical_side_effects: {
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
evaluate_lazy_assignment: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = 42;
|
||||
console.log(a &&= "PASS");
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
issue_4815_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
Reference in New Issue
Block a user