From: Dmitry Volyntsev Date: Wed, 4 Mar 2026 23:16:15 +0000 (-0800) Subject: Parser: allow await expressions in tagged templates. X-Git-Tag: 0.9.7~14 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=e496636ec3ccab2194511cef157141301a399049;p=njs.git Parser: allow await expressions in tagged templates. --- diff --git a/src/njs_parser.c b/src/njs_parser.c index 998ce5e7..93811746 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -2274,8 +2274,6 @@ static njs_int_t njs_parser_tagged_template_literal_after(njs_parser_t *parser, njs_lexer_token_t *token, njs_queue_link_t *current) { - parser->scope->in_tagged_template--; - return njs_parser_stack_pop(parser); } @@ -2359,8 +2357,6 @@ njs_parser_property(njs_parser_t *parser, njs_lexer_token_t *token, parser->node = node; - parser->scope->in_tagged_template++; - njs_parser_next(parser, njs_parser_template_literal); return njs_parser_after(parser, current, node, 1, @@ -3888,12 +3884,6 @@ njs_parser_await(njs_parser_t *parser, njs_lexer_token_t *token, return NJS_ERROR; } - if (parser->scope->in_tagged_template > 0) { - njs_parser_syntax_error(parser, - "await in tagged template not supported"); - return NJS_ERROR; - } - node = njs_parser_node_new(parser, NJS_TOKEN_AWAIT); if (njs_slow_path(node == NULL)) { return NJS_ERROR; diff --git a/src/njs_parser.h b/src/njs_parser.h index 387ff2b6..1e760454 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_tagged_template; }; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 868f9a59..c9f77cdd 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -20778,10 +20778,16 @@ static njs_unit_test_t njs_test[] = njs_str("undefined") }, { njs_str("(async () => (function (){}) `${(async () => 1)(await 1)}`)()"), - njs_str("SyntaxError: await in tagged template not supported") }, + njs_str("[object Promise]") }, { njs_str("(async () => (function (){}) `${await 1}`)()"), - njs_str("SyntaxError: await in tagged template not supported") }, + njs_str("[object Promise]") }, + + { njs_str("(async () => ({" + " x: 7," + " t(...a) { return this.x + ':' + a[1]; }" + "}).t`${await 2}`)()"), + njs_str("[object Promise]") }, { njs_str("async function af() {await encrypt({},}"), njs_str("SyntaxError: Unexpected token \"}\"") }, @@ -21588,6 +21594,46 @@ static njs_unit_test_t njs_externals_test[] = "f().then($r.retval)"), njs_str("9") }, + { njs_str("async function f() {" + " return ((...a) => a[1])`${await Promise.resolve(1)}`;" + "}" + "f().then($r.retval)"), + njs_str("1") }, + + { njs_str("async function f() {" + " return ((...a) => a[1])`${await Promise.resolve(2)}`" + " + ':' +" + " ((...a) => a[1])`${await Promise.resolve(3)}`;" + "}" + "f().then($r.retval)"), + njs_str("2:3") }, + + { njs_str("async function f() {" + " return ({" + " x: 'X'," + " t(...a) { return this.x + ':' + a[1]; }" + " }).t`${await Promise.resolve(4)}`;" + "}" + "f().then($r.retval)"), + njs_str("X:4") }, + + { njs_str("async function f() {" + " return ((...a) => a[1] + ':' + a[2] + ':' + a[0].length)" + " `a${await Promise.resolve(2)}b" + "${await Promise.resolve(3)}c`;" + "}" + "f().then($r.retval)"), + njs_str("2:3:3") }, + + { njs_str("async function f() {" + " var log = '';" + " function p(v) { log += v; return Promise.resolve(v); }" + " function t() { log += 'T'; return log; }" + " return t`${await p('A')}${await p('B')}`;" + "}" + "f().then($r.retval)"), + njs_str("ABT") }, + { njs_str("$r.retval(Promise.all([async () => [await x('X')]]))"), njs_str("[object Promise]") },