From: Vadim Zhestikov Date: Fri, 7 Oct 2022 01:28:52 +0000 (-0700) Subject: Fixed double declaration detection in modules. X-Git-Tag: 0.7.8~7 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=e4da8f80b901cc92ec12d9aee6aaf967035a8ad6;p=njs.git Fixed double declaration detection in modules. --- diff --git a/src/njs_variable.c b/src/njs_variable.c index 9ea34237..85fd235a 100644 --- a/src/njs_variable.c +++ b/src/njs_variable.c @@ -222,14 +222,17 @@ njs_variable_scope_find(njs_parser_t *parser, njs_parser_scope_t *scope, return root; } - module = parser->vm->options.module || parser->module; + if (scope->parent == NULL) { + module = parser->vm->options.module || parser->module; - if (module) { - if (type == NJS_VARIABLE_FUNCTION - || var->type == NJS_VARIABLE_FUNCTION) - { - goto failed; + if (module) { + if (type == NJS_VARIABLE_FUNCTION + || var->type == NJS_VARIABLE_FUNCTION) + { + goto failed; + } } + } return root; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 038ea3a9..3b11bf11 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -21296,6 +21296,10 @@ static njs_unit_test_t njs_module_test[] = { njs_str("{ var f = 1; } function f() {};"), njs_str("SyntaxError: \"f\" has already been declared in 1") }, + + { njs_str("function f(v) {var f = v;}; f(1); f"), + njs_str("[object Function]") }, + };