Skip to content

Commit

Permalink
fix corner case in unused (#5080)
Browse files Browse the repository at this point in the history
fixes #5079
  • Loading branch information
alexlamsl committed Jul 14, 2021
1 parent 8e2dff6 commit f18804f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6366,7 +6366,10 @@ merge(Compressor.prototype, {
if (value) {
if (props.assign) {
var assign = props.assign.drop_side_effect_free(compressor);
if (assign) props.unshift(assign);
if (assign) {
assign.write_only = true;
props.unshift(assign);
}
}
if (!(parent instanceof AST_Sequence)
|| parent.tail_node() === node
Expand Down Expand Up @@ -6942,7 +6945,6 @@ merge(Compressor.prototype, {
if (assign) {
assign.write_only = true;
assign.walk(tw);
assign.write_only = "p";
}
props.forEach(function(prop) {
prop.walk(tw);
Expand Down
23 changes: 23 additions & 0 deletions test/compress/drop-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -3469,3 +3469,26 @@ issue_4912_3: {
}
expect_stdout: "PASS"
}

issue_5079: {
options = {
collapse_vars: true,
pure_getters: "strict",
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a;
do {
(a = 123456).p = a;
a.q = null;
} while (console.log("PASS"));
}
expect: {
do {
0, 0, null;
} while (console.log("PASS"));
}
expect_stdout: "PASS"
}

0 comments on commit f18804f

Please sign in to comment.