diff --git a/lib/compress.js b/lib/compress.js index 59f579f0..5a05ac8b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -11997,6 +11997,8 @@ Compressor.prototype.compress = function(node) { if ((def.scope !== self.scope.resolve() || def.in_loop) && (!compressor.option("reduce_funcs") || def.escaped.depth == 1 || fixed.inlined)) { single_use = false; + } else if (def.redefined()) { + single_use = false; } else if (recursive_ref(compressor, def, fixed)) { single_use = false; } else if (fixed.name && fixed.name.definition() !== def) { diff --git a/test/compress/const.js b/test/compress/const.js index 0729a68c..a8837500 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1872,3 +1872,37 @@ issue_5476: { } expect_stdout: "undefined" } + +issue_5516: { + options = { + inline: true, + reduce_funcs: true, + reduce_vars: true, + unused: true, + } + input: { + console.log(typeof function() { + try {} catch (a) { + (function f() { + a; + })(); + } + { + const a = function() {}; + return a; + } + }()); + } + expect: { + console.log(typeof function() { + try {} catch (a) { + void a; + } + { + const a = function() {}; + return a; + } + }()); + } + expect_stdout: "function" +} diff --git a/test/compress/varify.js b/test/compress/varify.js index 75f6ec67..701edfd5 100644 --- a/test/compress/varify.js +++ b/test/compress/varify.js @@ -613,3 +613,35 @@ issue_4954: { ] node_version: ">=4" } + +issue_5516: { + options = { + reduce_funcs: true, + reduce_vars: true, + unused: true, + varify: true, + } + input: { + "use strict"; + console.log(typeof function() { + { + let a; + } + { + const a = function() {}; + return a; + } + }()); + } + expect: { + "use strict"; + console.log(typeof function() { + { + const a = function() {}; + return a; + } + }()); + } + expect_stdout: "function" + node_version: ">=4" +}