]> git.kaiwu.me - njs.git/commitdiff
Corrected error message when parsing "var" inside "for".
authorValentin Bartenev <vbart@nginx.com>
Thu, 2 May 2019 08:08:44 +0000 (11:08 +0300)
committerValentin Bartenev <vbart@nginx.com>
Thu, 2 May 2019 08:08:44 +0000 (11:08 +0300)
The "var_in" flag indicates parsing inside the "for" statement with expectation
of the "in" token, but it doesn't define the loop as a for-in one.  In fact,
that's unknown at the moment when this particular error message is emitted.

As a result, the following code:

  for (var eval = 10; eval; eval--);

produces the error message about for-in loop:

  SyntaxError: Identifier "eval" is forbidden in for-in var declaration

Actually, according to the specification "eval" isn't a keyword and shouldn't
cause any errors here.  But this bug is beyond the scope of the current fix.

njs/njs_parser.c
njs/test/njs_unit_test.c

index c5071350e5aaf27fb823b1f29eca0ec1f387ce3b..c32f0e65be0fbc75f3ccca296504eb5fa2ef0d74 100644 (file)
@@ -1057,9 +1057,8 @@ njs_parser_var_statement(njs_vm_t *vm, njs_parser_t *parser, njs_token_t parent,
         if (token != NJS_TOKEN_NAME) {
             if (token == NJS_TOKEN_ARGUMENTS || token == NJS_TOKEN_EVAL) {
                 njs_parser_syntax_error(vm, parser, "Identifier \"%V\" "
-                                        "is forbidden in %s declaration",
-                                        njs_parser_text(parser),
-                                        var_in ? "for-in var" : "var");
+                                        "is forbidden in var declaration",
+                                        njs_parser_text(parser));
             }
 
             return NJS_TOKEN_ILLEGAL;
index e8b23e9cfff36eb7846dd6b3c6ba0bed9700e63a..0bd45f010befaa45d28778d6805d022c5dfb08d9 100644 (file)
@@ -6737,7 +6737,7 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in var declaration in 1") },
 
     { nxt_string("for (var arguments in []) {}"),
-      nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in for-in var declaration in 1") },
+      nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in var declaration in 1") },
 
     { nxt_string("function arguments(){}"),
       nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in function declaration in 1") },