fix corner case in reduce_vars (#5435)

fixes #5434
This commit is contained in:
Alex Lam S.L
2022-05-06 02:32:47 +01:00
committed by GitHub
parent 1a4e99dc2d
commit 89a35f9fcd
2 changed files with 36 additions and 1 deletions

View File

@@ -649,7 +649,7 @@ Compressor.prototype.compress = function(node) {
}
if (!HOP(tw.safe_ids, def.id)) {
if (!safe) return false;
if (safe.read) {
if (safe.read || tw.in_loop) {
var scope = tw.find_parent(AST_BlockScope);
if (scope instanceof AST_Class) return false;
if (def.scope.resolve() !== scope.resolve()) return false;

View File

@@ -7861,3 +7861,38 @@ issue_5324: {
}
expect_stdout: "NaN"
}
issue_5434: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function(a) {
for (var i = 0; i < 2; i++) {
var b = "FAIL";
f && f();
a = b;
var f = function() {
b = "PASS";
};
}
return a;
}());
}
expect: {
console.log(function(a) {
for (var i = 0; i < 2; i++) {
var b = "FAIL";
f && f();
a = b;
var f = function() {
b = "PASS";
};
}
return a;
}());
}
expect_stdout: "PASS"
}