From 3b4df319b9ee55823dea653a0160ba88e72e67a7 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Mon, 22 Jan 2018 18:02:06 +0800 Subject: [PATCH] handle duplicate function declarations correctly fixes #2836 --- lib/scope.js | 2 +- test/compress/reduce_vars.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/scope.js b/lib/scope.js index af852bb1..6c883c66 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -305,7 +305,7 @@ AST_Scope.DEFMETHOD("find_variable", function(name){ AST_Scope.DEFMETHOD("def_function", function(symbol, init){ var def = this.def_variable(symbol, init); - if (!def.init) def.init = init; + if (!def.init || def.init instanceof AST_Defun) def.init = init; this.functions.set(symbol.name, def); return def; }); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 33175d1b..4009c35b 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -5360,3 +5360,26 @@ issue_2799_2: { } expect_stdout: "PASS" } + +issue_2836: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f() { + return "FAIL"; + } + console.log(f()); + function f() { + return "PASS"; + } + } + expect: { + console.log(function() { + return "PASS"; + }()); + } + expect_stdout: "PASS" +}