Skip to content

Commit

Permalink
fix corner case in reduce_vars (#3881)
Browse files Browse the repository at this point in the history
fixes #3880
  • Loading branch information
alexlamsl committed May 11, 2020
1 parent 2b24dc2 commit e8a7956
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/compress.js
Expand Up @@ -797,8 +797,12 @@ merge(Compressor.prototype, {
d.recursive_refs++;
} else if (value && ref_once(tw, compressor, d)) {
d.in_loop = tw.loop_ids[d.id] !== tw.in_loop;
d.single_use = value instanceof AST_Lambda && !value.pinned()
|| !d.in_loop && d.scope === this.scope && value.is_constant_expression();
d.single_use = value instanceof AST_Lambda
&& !value.pinned()
&& (!d.in_loop || tw.parent() instanceof AST_Call)
|| !d.in_loop
&& d.scope === this.scope
&& value.is_constant_expression();
} else {
d.single_use = false;
}
Expand Down
21 changes: 21 additions & 0 deletions test/compress/reduce_vars.js
Expand Up @@ -7047,3 +7047,24 @@ issue_3866: {
}
expect_stdout: "PASS"
}

issue_3880: {
options = {
reduce_funcs: true,
reduce_vars: true,
unused: true,
}
input: {
(function(a) {
while (a.var ^= 1);
console.log("PASS");
})(function() {});
}
expect: {
(function(a) {
while (a.var ^= 1);
console.log("PASS");
})(function() {});
}
expect_stdout: "PASS"
}

0 comments on commit e8a7956

Please sign in to comment.