diff --git a/lib/compress.js b/lib/compress.js index d890caf7..334efb24 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4705,6 +4705,7 @@ merge(Compressor.prototype, { value.walk(new TreeWalker(function(node) { if (node instanceof AST_SymbolRef && node.definition() === defun_def) { node.thedef = lambda_def; + lambda_def.references.push(node); } })); } else { diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 90206ec6..1cc575b0 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -1434,3 +1434,28 @@ defun_lambda_same_name: { } expect_stdout: "120" } + +issue_2660: { + options = { + reduce_vars: true, + toplevel: true, + side_effects: true, + unused: true, + } + input: { + var a = 2; + function f(b) { + return b && f() || a--; + } + f(1); + console.log(a); + } + expect: { + var a = 2; + (function f(b) { + return b && f() || a--; + })(1); + console.log(a); + } + expect_stdout: "1" +}