From f10778faebda160ddbdebee65e1fe2c074b5a44f Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 2 May 2019 11:08:44 +0300 Subject: [PATCH] Corrected error message when parsing "var" inside "for". 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 | 5 ++--- njs/test/njs_unit_test.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/njs/njs_parser.c b/njs/njs_parser.c index c5071350..c32f0e65 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -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; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index e8b23e9c..0bd45f01 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") }, -- 2.47.3