]> git.kaiwu.me - njs.git/commitdiff
Parser: fixed the detection of await in arguments.
authorVadim Zhestikov <v.zhestikov@f5.com>
Tue, 28 Feb 2023 02:39:44 +0000 (18:39 -0800)
committerVadim Zhestikov <v.zhestikov@f5.com>
Tue, 28 Feb 2023 02:39:44 +0000 (18:39 -0800)
This fixes #619 issue on Github.

src/njs_parser.c
src/test/njs_unit_test.c

index c05054fbe2996bb91bb760a04461926a764d9c06..61f33d110c936d6490d792f4efd26b46e7e5e84f 100644 (file)
@@ -3565,17 +3565,14 @@ njs_parser_await(njs_parser_t *parser, njs_lexer_token_t *token,
     njs_queue_link_t *current)
 {
     njs_parser_node_t   *node;
-    njs_parser_scope_t  *scope;
-
-    scope = njs_function_scope(parser->scope);
 
-    if (!scope->async) {
+    if (!njs_function_scope(parser->scope)->async) {
         njs_parser_syntax_error(parser,
                                 "await is only valid in async functions");
         return NJS_ERROR;
     }
 
-    if (scope->in_args) {
+    if (parser->scope->in_args) {
         njs_parser_syntax_error(parser, "await in arguments not supported");
         return NJS_ERROR;
     }
index 88e86f73e22e56a06bbeab59c2ed56e875ce8def..2afae7a1f251d3a811f2a3a087a21ad078cb0019 100644 (file)
@@ -19824,6 +19824,9 @@ static njs_unit_test_t  njs_test[] =
               "(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) {}}"),
+      njs_str("SyntaxError: await in arguments not supported in 1") },
+
     { njs_str("async function af() {await encrypt({},}"),
       njs_str("SyntaxError: Unexpected token \"}\" in 1") },