Skip to content

Commit

Permalink
fix corner case in unused (#5920)
Browse files Browse the repository at this point in the history
fixes #5918
  • Loading branch information
alexlamsl authored Aug 14, 2024
1 parent f34fbb2 commit abefd94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7253,6 +7253,10 @@ Compressor.prototype.compress = function(node) {
var def = node.definition();
var_defs[def.id] = (var_defs[def.id] || 0) + 1;
assignments.add(def.id, node);
var fixed = node.fixed_value(true);
if (fixed && fixed.tail_node().operator == "=") {
verify_safe_usage(def, node, value_modified[def.id]);
}
return true;
}
if (node instanceof AST_SymbolImport) {
Expand Down
29 changes: 29 additions & 0 deletions test/compress/drop-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -3870,3 +3870,32 @@ issue_5908_2: {
}
expect_stdout: "PASS"
}

issue_5918: {
options = {
pure_getters: "strict",
reduce_vars: true,
unused: true,
}
input: {
var a;
(function(b) {
b.p = 42;
})(a = function() {
arguments;
});
for (var i in a)
console.log("PASS");
}
expect: {
var a;
(function(b) {
b.p = 42;
})(a = function() {
arguments;
});
for (var i in a)
console.log("PASS");
}
expect_stdout: "PASS"
}

0 comments on commit abefd94

Please sign in to comment.