]> git.kaiwu.me - njs.git/commitdiff
Fixed double declaration detection in modules.
authorVadim Zhestikov <v.zhestikov@f5.com>
Fri, 7 Oct 2022 01:28:52 +0000 (18:28 -0700)
committerVadim Zhestikov <v.zhestikov@f5.com>
Fri, 7 Oct 2022 01:28:52 +0000 (18:28 -0700)
src/njs_variable.c
src/test/njs_unit_test.c

index 9ea34237bc77b0cc9a2468222bd2e84f5279a7ec..85fd235a283e3ced1430bd8de7e17d2aa6ecf310 100644 (file)
@@ -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;
index 038ea3a9288a6bb8beda6b9beb7fa8b781db4e1d..3b11bf1113932ccb8e46860f2df24463f1afc368 100644 (file)
@@ -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]") },
+
 };