fix corner case in collapse_vars (#4869)

fixes #4868
This commit is contained in:
Alex Lam S.L
2021-04-24 22:16:51 +01:00
committed by GitHub
parent a2b1b96752
commit a1a212f639
2 changed files with 27 additions and 2 deletions

View File

@@ -2563,8 +2563,13 @@ merge(Compressor.prototype, {
if (is_lhs_read_only(value, compressor)) return;
var referenced = def.references.length - def.replaced;
if (referenced < 2) return;
candidate = candidate.clone();
candidate[candidate instanceof AST_Assign ? "right" : "value"] = value;
var expr = candidate.clone();
expr[expr instanceof AST_Assign ? "right" : "value"] = value;
if (candidate.name_index >= 0) {
expr.name_index = candidate.name_index;
expr.arg_index = candidate.arg_index;
}
candidate = expr;
}
return value_def = def;
}

View File

@@ -9010,3 +9010,23 @@ issue_4865: {
}
expect_stdout: true
}
issue_4868: {
options = {
collapse_vars: true,
unused: true,
}
input: {
var a;
(function(b) {
console.log(b[0]);
})(a = [ "PASS" ], a = [ "FAIL" ]);
}
expect: {
var a;
(function(b) {
console.log(b[0]);
})(a = [ "PASS" ], a = [ "FAIL" ]);
}
expect_stdout: "PASS"
}