[njs] Fixed condition on already been declared exception.

Dmitry Volyntsev xeioex at nginx.com
Tue Apr 23 12:46:52 UTC 2019


details:   https://hg.nginx.org/njs/rev/ad1be10fba80
branches:  
changeset: 919:ad1be10fba80
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Apr 23 15:31:40 2019 +0300
description:
Fixed condition on already been declared exception.

diffstat:

 njs/njs_parser.c   |   1 -
 njs/njs_variable.c |  20 ++++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diffs (42 lines):

diff -r 52983554e61f -r ad1be10fba80 njs/njs_parser.c
--- a/njs/njs_parser.c	Mon Apr 22 19:53:41 2019 +0300
+++ b/njs/njs_parser.c	Tue Apr 23 15:31:40 2019 +0300
@@ -203,7 +203,6 @@ njs_parser_scope_begin(njs_vm_t *vm, njs
     } else {
         if (type == NJS_SCOPE_GLOBAL) {
             type += NJS_INDEX_GLOBAL_OFFSET;
-            scope->module = vm->options.module;
         }
 
         scope->next_index[0] = type;
diff -r 52983554e61f -r ad1be10fba80 njs/njs_variable.c
--- a/njs/njs_variable.c	Mon Apr 22 19:53:41 2019 +0300
+++ b/njs/njs_variable.c	Tue Apr 23 15:31:40 2019 +0300
@@ -91,17 +91,17 @@ njs_variable_scope_add(njs_vm_t *vm, njs
     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;


More information about the nginx-devel mailing list