]> git.kaiwu.me - njs.git/commitdiff
Fixed condition on already been declared exception.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 23 Apr 2019 12:31:40 +0000 (15:31 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 23 Apr 2019 12:31:40 +0000 (15:31 +0300)
njs/njs_parser.c
njs/njs_variable.c

index cef217d8e1f9b2d5cba5dd9438fb8e25991c8b8d..54b6c16dd081c9b5e9063f6144610fa6d363bc50 100644 (file)
@@ -203,7 +203,6 @@ njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type)
     } else {
         if (type == NJS_SCOPE_GLOBAL) {
             type += NJS_INDEX_GLOBAL_OFFSET;
-            scope->module = vm->options.module;
         }
 
         scope->next_index[0] = type;
index 7b5f38b776e8a89742b68d55af77d2fab7c688da..ae8b15b10d06fb813ce9a57d9226c1535b3325c5 100644 (file)
@@ -91,17 +91,17 @@ njs_variable_scope_add(njs_vm_t *vm, njs_parser_scope_t *scope,
     if (nxt_lvlhsh_find(&scope->variables, lhq) == NXT_OK) {
         var = lhq->value;
 
-        if (!scope->module && scope->type != NJS_SCOPE_BLOCK) {
-            return var;
-        }
-
-        if (type == NJS_VARIABLE_FUNCTION
-            || var->type == NJS_VARIABLE_FUNCTION)
+        if (scope->module || scope->type == NJS_SCOPE_BLOCK
+            || (scope->type == NJS_SCOPE_GLOBAL && vm->options.module))
         {
-            njs_parser_syntax_error(vm, vm->parser,
-                                    "\"%V\" has already been declared",
-                                    &lhq->key);
-            return NULL;
+            if (type == NJS_VARIABLE_FUNCTION
+                || var->type == NJS_VARIABLE_FUNCTION)
+            {
+                njs_parser_syntax_error(vm, vm->parser,
+                                        "\"%V\" has already been declared",
+                                        &lhq->key);
+                return NULL;
+            }
         }
 
         return var;