Skip to content

Commit

Permalink
fix corner case in unused (#4557)
Browse files Browse the repository at this point in the history
fixes #4556
  • Loading branch information
alexlamsl committed Jan 15, 2021
1 parent 65d39a3 commit 18dbceb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5766,6 +5766,9 @@ merge(Compressor.prototype, {
var write_only = def.value.write_only;
var value = def.value.drop_side_effect_free(compressor);
if (def.value !== value) {
sym.references.forEach(function(node) {
if (node.fixed === sym.fixed) node.fixed = def.value;
});
def.value = null;
if (value) {
AST_Node.warn("Side effects in last use of variable {name} [{file}:{line},{col}]", template(def.name));
Expand Down
20 changes: 20 additions & 0 deletions test/compress/spreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,23 @@ issue_4363: {
expect_stdout: "PASS"
node_version: ">=8"
}

issue_4556: {
options = {
reduce_vars: true,
unused: true,
}
input: {
console.log(function() {
var a = "" + [ a++ ];
var b = [ ...a ];
}());
}
expect: {
console.log(function() {
var a;
}());
}
expect_stdout: "undefined"
node_version: ">=6"
}

0 comments on commit 18dbceb

Please sign in to comment.