From e4da8f80b901cc92ec12d9aee6aaf967035a8ad6 Mon Sep 17 00:00:00 2001 From: Vadim Zhestikov Date: Thu, 6 Oct 2022 18:28:52 -0700 Subject: [PATCH] Fixed double declaration detection in modules. --- src/njs_variable.c | 15 +++++++++------ src/test/njs_unit_test.c | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) 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]") }, + }; -- 2.47.3