diff --git a/src/njs_parser.c b/src/njs_parser.c index dbd9169f2..66b6826f0 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -4617,8 +4617,8 @@ njs_parser_statement(njs_parser_t *parser, njs_lexer_token_t *token, static njs_int_t -njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token, - njs_queue_link_t *current) +njs_parser_statement_wo_node_(njs_parser_t *parser, njs_lexer_token_t *token, + njs_queue_link_t *current, int labelled) { switch (token->type) { case NJS_TOKEN_OPEN_BRACE: @@ -4631,6 +4631,12 @@ njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token, case NJS_TOKEN_SEMICOLON: njs_lexer_consume_token(parser->lexer, 1); + if (labelled == 1) { + token = njs_lexer_token(parser->lexer, 0); + if (token->type != NJS_TOKEN_END) { + return NJS_OK; + } + } return njs_parser_stack_pop(parser); case NJS_TOKEN_IF: @@ -4710,6 +4716,22 @@ njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token, } +static njs_int_t +njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token, + njs_queue_link_t *current) +{ + return njs_parser_statement_wo_node_(parser, token, current, 0); +} + + +static njs_int_t +njs_parser_statement_wo_node_labelled(njs_parser_t *parser, + njs_lexer_token_t *token, njs_queue_link_t *current) +{ + return njs_parser_statement_wo_node_(parser, token, current, 1); +} + + static njs_int_t njs_parser_statement_after(njs_parser_t *parser, njs_lexer_token_t *token, njs_queue_link_t *current) @@ -6685,7 +6707,7 @@ njs_parser_labelled_statement(njs_parser_t *parser, njs_lexer_token_t *token, return NJS_DONE; } else { - njs_parser_next(parser, njs_parser_statement_wo_node); + njs_parser_next(parser, njs_parser_statement_wo_node_labelled); } return njs_parser_after(parser, current, (void *) unique_id, 1, diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 2f0e318c4..ce9d4a4cb 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3494,6 +3494,13 @@ static njs_unit_test_t njs_test[] = "} catch(e) {c = 10;}; [c, fin]"), njs_str("1,1") }, + { njs_str("function v1() {" + "function v2 () {}" + "v3:;" + "1;" + "} v1();"), + njs_str("undefined") }, + /* jumping out of a nested try-catch block. */ { njs_str("var r = 0; "