diff --git a/lib/compress.js b/lib/compress.js index 42aae488..1889db0c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -13340,6 +13340,7 @@ Compressor.prototype.compress = function(node) { def.single_use = false; if (!in_loop) return; if (def.references.length == def.replaced) return; + if (def.orig.length == def.eliminated) return; if (def.orig.length == 1 && fn.functions.has(name)) return; if (!all(def.orig, function(sym) { if (sym instanceof AST_SymbolConst) return false; diff --git a/test/compress/functions.js b/test/compress/functions.js index 2b393ba1..40ed7fc6 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8270,3 +8270,62 @@ issue_5366: { "baz", ] } + +issue_5376_1: { + options = { + evaluate: true, + inline: true, + join_vars: true, + loops: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + "use strict"; + var a; + for (;42;) + var b = function() { + var c; + throw new Error(c++); + }(); + } + expect: { + "use strict"; + for (;;) { + 42; + throw new Error(NaN); + } + } + expect_stdout: Error("NaN") +} + +issue_5376_2: { + options = { + evaluate: true, + inline: true, + join_vars: true, + loops: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + "use strict"; + var a; + for (;42;) + var b = function() { + var c; + c++; + throw new Error("PASS"); + }(); + } + expect: { + "use strict"; + for (;;) { + 0; + throw new Error("PASS"); + } + } + expect_stdout: Error("PASS") +}