fix corner case in collapse_vars (#4243)

fixes #4242
This commit is contained in:
Alex Lam S.L
2020-10-24 15:44:20 +01:00
committed by GitHub
parent c5df8355ba
commit e478da24c7
2 changed files with 22 additions and 0 deletions

View File

@@ -1974,6 +1974,7 @@ merge(Compressor.prototype, {
}
function foldable(expr) {
if (expr instanceof AST_Assign && expr.right.single_use) return;
var lhs_ids = Object.create(null);
var marker = new TreeWalker(function(node) {
if (node instanceof AST_SymbolRef) lhs_ids[node.definition().id] = true;

View File

@@ -8556,3 +8556,24 @@ issue_4070: {
}
expect_stdout: "NaN"
}
issue_4242: {
options = {
collapse_vars: true,
conditionals: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function() {
if (console)
var a = function(){}, b = (!1 === console || a)();
}());
}
expect: {
console.log(function() {
console && (!1 === console || function(){})();
}());
}
expect_stdout: "undefined"
}