From: hongzhidao Date: Sat, 13 Apr 2019 15:38:53 +0000 (+0800) Subject: Fixed function declaration with the same name as a variable. X-Git-Tag: 0.3.1~3 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=edbdbf5b728b591b85015afb1f584f18d0d3066d;p=njs.git Fixed function declaration with the same name as a variable. This closes #126 issue on Github. --- diff --git a/njs/njs_variable.c b/njs/njs_variable.c index f4596baa..7eaa3597 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -65,6 +65,11 @@ njs_variable_add(njs_vm_t *vm, njs_parser_scope_t *scope, nxt_str_t *name, if (nxt_lvlhsh_find(&scope->variables, &lhq) == NXT_OK) { var = lhq.value; + + if (type == NJS_VARIABLE_FUNCTION) { + var->type = type; + } + return var; } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index a7aeb48a..fb340ac7 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -6413,6 +6413,16 @@ static njs_unit_test_t njs_test[] = { nxt_string("function f() { var a = 1; function baz() { return a; } return baz; } f().bind()()"), nxt_string("1") }, + { nxt_string("function f() { var t = 1; function baz() { return t; } return baz; }" + "f().bind()();"), + nxt_string("1") }, + + { nxt_string("(function(a) { var s = typeof g, q = g; var g = 1; s += typeof g; function g(b) { return a + b }; return q; })(1)(2)"), + nxt_string("3")}, + + { nxt_string("(function(a) { var g = f; var f = 1; function f() { return a; } return g; })(42)()"), + nxt_string("42") }, + { nxt_string("function f(a, b) { return a + b }" "f(3,4) === f.bind()(3,4)"), nxt_string("true") },