fix corner case in reduce_vars (#5062)

fixes #5061
This commit is contained in:
Alex Lam S.L
2021-07-08 09:31:04 +01:00
committed by GitHub
parent 6577d641ac
commit ea7829daf5
2 changed files with 53 additions and 0 deletions

View File

@@ -889,6 +889,7 @@ merge(Compressor.prototype, {
} else {
right.parent_scope.resolve().fn_defs.push(right);
right.safe_ids = null;
if (!node.write_only) mark_fn_def(tw, ld, right);
}
return true;
} else if (scan) {

View File

@@ -6346,3 +6346,55 @@ issue_5046: {
}
expect_stdout: "PASS"
}
issue_5061_1: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
var f, a = 1;
(f = function() {
console.log(a ? "foo" : "bar");
})();
f(a = 0);
}
expect: {
var f, a = 1;
(f = function() {
console.log(a ? "foo" : "bar");
})();
f(a = 0);
}
expect_stdout: [
"foo",
"bar",
]
}
issue_5061_2: {
options = {
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var f, a = 1;
(f = function() {
console.log(a ? "foo" : "bar");
})();
f(a = 0);
}
expect: {
var f, a = 1;
(f = function() {
console.log(a ? "foo" : "bar");
})();
f(a = 0);
}
expect_stdout: [
"foo",
"bar",
]
}