handle duplicate function declarations correctly (#2837)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 22 Jan 2018 17:28:09 +0000 (01:28 +0800)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2018 17:28:09 +0000 (01:28 +0800)
fixes #2836

lib/scope.js
test/compress/reduce_vars.js

index af852bb..6c883c6 100644 (file)
@@ -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;
 });
index 33175d1..4009c35 100644 (file)
@@ -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"
+}