From: Dmitry Volyntsev Date: Wed, 4 Mar 2026 07:22:59 +0000 (-0800) Subject: Parser: allow await expressions in call arguments. X-Git-Tag: 0.9.7~15 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=e9ffedac65662508454d838f9d013212f568a794;p=njs.git Parser: allow await expressions in call arguments. --- diff --git a/src/njs_parser.c b/src/njs_parser.c index 0ca33486..998ce5e7 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -3079,8 +3079,6 @@ njs_parser_arguments(njs_parser_t *parser, njs_lexer_token_t *token, return njs_parser_stack_pop(parser); } - parser->scope->in_args++; - njs_parser_next(parser, njs_parser_argument_list); return njs_parser_after(parser, current, NULL, 1, @@ -3092,8 +3090,6 @@ 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--; - if (token->type == NJS_TOKEN_CLOSE_PARENTHESIS) { njs_lexer_consume_token(parser->lexer, 1); return njs_parser_stack_pop(parser); @@ -3892,11 +3888,6 @@ njs_parser_await(njs_parser_t *parser, njs_lexer_token_t *token, return NJS_ERROR; } - if (parser->scope->in_args > 0) { - njs_parser_syntax_error(parser, "await in arguments not supported"); - return NJS_ERROR; - } - if (parser->scope->in_tagged_template > 0) { njs_parser_syntax_error(parser, "await in tagged template not supported"); diff --git a/src/njs_parser.h b/src/njs_parser.h index 8a1bd9df..387ff2b6 100644 --- a/src/njs_parser.h +++ b/src/njs_parser.h @@ -26,7 +26,6 @@ struct njs_parser_scope_s { uint8_t arrow_function; uint8_t dest_disable; uint8_t async; - uint32_t in_args; uint32_t in_tagged_template; }; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index e718c147..868f9a59 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -20754,31 +20754,31 @@ static njs_unit_test_t njs_test[] = njs_str("ReferenceError: \"AsyncFunction\" is not defined") }, { njs_str("(async function() {console.log(await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("(async function() {console.log('Number: ' + await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("(async function() {f(await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("(async function() {f(f(1), await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("async () => [await x(1)(),]; async () => [await x(1)()]"), njs_str("[object AsyncFunction]") }, { njs_str("(async function() {f(1, 'a', await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("(async function() {f('Number: ' + await 111)})"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("[object AsyncFunction]") }, { njs_str("async function f1() {try {f(await f1)} catch(e) {}}"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("undefined") }, { njs_str("(async () => (function (){}) `${(async () => 1)(await 1)}`)()"), - njs_str("SyntaxError: await in arguments not supported") }, + njs_str("SyntaxError: await in tagged template not supported") }, { njs_str("(async () => (function (){}) `${await 1}`)()"), njs_str("SyntaxError: await in tagged template not supported") }, @@ -21540,6 +21540,54 @@ static njs_unit_test_t njs_externals_test[] = "f(1).then($r.retval)"), njs_str("1") }, + { njs_str("async function f() {" + " function g(v) { return v; }" + " return g(await Promise.resolve(1));" + "}" + "f().then($r.retval)"), + njs_str("1") }, + + { njs_str("async function f() {" + " return ({" + " g(v) { return v; }" + " }).g(await Promise.resolve(2));" + "}" + "f().then($r.retval)"), + njs_str("2") }, + + { njs_str("async function f() {" + " function g(a, b) { return a + b; }" + " return g(await Promise.resolve(1)," + " await Promise.resolve(2));" + "}" + "f().then($r.retval)"), + njs_str("3") }, + + { njs_str("async function f() {" + " return ({" + " k: 10," + " g(a, b) { return this.k + a + b; }" + " }).g(await Promise.resolve(1)," + " await Promise.resolve(2));" + "}" + "f().then($r.retval)"), + njs_str("13") }, + + { njs_str("async function f() {" + " function C(v) { this.v = v; }" + " return (new C(await Promise.resolve(7))).v;" + "}" + "f().then($r.retval)"), + njs_str("7") }, + + { njs_str("async function f() {" + " return ({" + " g(v) { return v; }" + " })?.g(await Promise.resolve(9));" + "}" + "f().then($r.retval)"), + njs_str("9") }, + { njs_str("$r.retval(Promise.all([async () => [await x('X')]]))"), njs_str("[object Promise]") },