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 tracking of argument scope. #731

Merged
merged 1 commit into from
Jun 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
6 changes: 3 additions & 3 deletions src/njs_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ njs_parser_arguments(njs_parser_t *parser, njs_lexer_token_t *token,
return njs_parser_stack_pop(parser);
}

parser->scope->in_args = 1;
parser->scope->in_args++;

njs_parser_next(parser, njs_parser_argument_list);

Expand All @@ -2840,7 +2840,7 @@ static njs_int_t
njs_parser_parenthesis_or_comma(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
parser->scope->in_args = 0;
parser->scope->in_args--;

if (token->type == NJS_TOKEN_CLOSE_PARENTHESIS) {
njs_lexer_consume_token(parser->lexer, 1);
Expand Down Expand Up @@ -3575,7 +3575,7 @@ njs_parser_await(njs_parser_t *parser, njs_lexer_token_t *token,
return NJS_ERROR;
}

if (parser->scope->in_args) {
if (parser->scope->in_args > 0) {
njs_parser_syntax_error(parser, "await in arguments not supported");
return NJS_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/njs_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct njs_parser_scope_s {
uint8_t arrow_function;
uint8_t dest_disable;
uint8_t async;
uint8_t in_args;
uint32_t in_args;
};


Expand Down
12 changes: 6 additions & 6 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19938,19 +19938,19 @@ static njs_unit_test_t njs_test[] =
{ njs_str("(async function() {console.log('Number: ' + await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },

{ njs_str("function f(a) {}"
"(async function() {f(await 111)})"),
{ njs_str("(async function() {f(await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },

{ njs_str("(async function() {f(f(1), await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },

{ njs_str("async () => [await x(1)(),]; async () => [await x(1)()]"),
njs_str("[object AsyncFunction]") },

{ njs_str("function f(a, b, c) {}"
"(async function() {f(1, 'a', await 111)})"),
{ njs_str("(async function() {f(1, 'a', await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },

{ njs_str("function f(a) {}"
"(async function() {f('Number: ' + await 111)})"),
{ njs_str("(async function() {f('Number: ' + await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },

{ njs_str("async function f1() {try {f(await f1)} catch(e) {}}"),
Expand Down