diff --git a/src/njs_parser.c b/src/njs_parser.c index dbd9169f2..7eb6292e4 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -6699,23 +6699,32 @@ njs_parser_labelled_statement_after(njs_parser_t *parser, { njs_int_t ret; uintptr_t unique_id; + njs_parser_node_t *node; const njs_lexer_entry_t *entry; - if (parser->node != NULL) { - /* The statement is not empty block or just semicolon. */ - - unique_id = (uintptr_t) parser->target; - entry = (const njs_lexer_entry_t *) unique_id; - - ret = njs_name_copy(parser->vm, &parser->node->name, &entry->name); - if (ret != NJS_OK) { + node = parser->node; + if (node == NULL) { + node = njs_parser_node_new(parser, NJS_TOKEN_BLOCK); + if (node == NULL) { return NJS_ERROR; } - ret = njs_label_remove(parser->vm, parser->scope, unique_id); - if (ret != NJS_OK) { - return NJS_ERROR; - } + node->token_line = token->line; + + parser->node = node; + } + + unique_id = (uintptr_t) parser->target; + entry = (const njs_lexer_entry_t *) unique_id; + + ret = njs_name_copy(parser->vm, &parser->node->name, &entry->name); + if (ret != NJS_OK) { + return NJS_ERROR; + } + + ret = njs_label_remove(parser->vm, parser->scope, unique_id); + if (ret != NJS_OK) { + return NJS_ERROR; } return njs_parser_stack_pop(parser); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 2f0e318c4..75933665c 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3494,6 +3494,22 @@ 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") }, + + { njs_str("function v1() {" + "function v2 () {}" + "v3:;" + "} v1();"), + njs_str("undefined") }, + + { njs_str("{v1:;}"), + njs_str("undefined") }, + /* jumping out of a nested try-catch block. */ { njs_str("var r = 0; "