From: Alex Lam S.L Date: Mon, 11 May 2020 18:29:33 +0000 (+0100) Subject: fix corner case in `reduce_vars` (#3881) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=e8a7956b6f0a71bed038a2b8936eb30d91e94d73;p=UglifyJS.git fix corner case in `reduce_vars` (#3881) fixes #3880 --- diff --git a/lib/compress.js b/lib/compress.js index 08abde9b..1e33dc10 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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; } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 00cebcd6..262a77f2 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -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" +}