Skip to content

Commit

Permalink
fix corner case in collapse_vars (#4875)
Browse files Browse the repository at this point in the history
fixes #4874
  • Loading branch information
alexlamsl committed Apr 27, 2021
1 parent 97bd56b commit 4cccc01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/compress.js
Expand Up @@ -1963,6 +1963,7 @@ merge(Compressor.prototype, {
} else if (candidate instanceof AST_VarDef) {
replaced = !compressor.exposed(def) && def.references.length == def.replaced;
}
value_def.last_ref = false;
value_def.single_use = false;
}
if (replaced && !remove_candidate(candidate)) statements.splice(stat_index, 1);
Expand Down
27 changes: 27 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -9030,3 +9030,30 @@ issue_4868: {
}
expect_stdout: "PASS"
}

issue_4874: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a;
a = null;
(function(b) {
for (var c in b = b && b[console.log("PASS")])
console;
})(a = 42);
}
expect: {
var a;
null;
(function(b) {
for (var c in a && a[console.log("PASS")])
console;
})(a = 42);
}
expect_stdout: "PASS"
}

0 comments on commit 4cccc01

Please sign in to comment.