handle duplicate function declarations correctly (#2837)

fixes #2836
This commit is contained in:
Alex Lam S.L
2018-01-23 01:28:09 +08:00
committed by GitHub
parent 06166df999
commit 5e2cd07d6f
2 changed files with 24 additions and 1 deletions

View File

@@ -305,7 +305,7 @@ AST_Scope.DEFMETHOD("find_variable", function(name){
AST_Scope.DEFMETHOD("def_function", function(symbol, init){ AST_Scope.DEFMETHOD("def_function", function(symbol, init){
var def = this.def_variable(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); this.functions.set(symbol.name, def);
return def; return def;
}); });

View File

@@ -5360,3 +5360,26 @@ issue_2799_2: {
} }
expect_stdout: "PASS" 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"
}