Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed empty labelled statement in a function. #757

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/njs_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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") },
VadimZhestikov marked this conversation as resolved.
Show resolved Hide resolved

{ 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; "
Expand Down