[njs] Fixed for-in unwanted detection of arrow function.

Vadim Zhestikov v.zhestikov at f5.com
Thu Nov 17 00:11:06 UTC 2022


details:   https://hg.nginx.org/njs/rev/487780764501
branches:  
changeset: 2001:487780764501
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Wed Nov 16 16:09:47 2022 -0800
description:
Fixed for-in unwanted detection of arrow function.

diffstat:

 src/njs_parser.c         |  18 ++++++++++--------
 src/test/njs_unit_test.c |   3 +++
 2 files changed, 13 insertions(+), 8 deletions(-)

diffs (41 lines):

diff -r 0d0b16ecf796 -r 487780764501 src/njs_parser.c
--- a/src/njs_parser.c	Wed Nov 16 09:15:39 2022 -0800
+++ b/src/njs_parser.c	Wed Nov 16 16:09:47 2022 -0800
@@ -4291,14 +4291,16 @@ njs_parser_assignment_expression(njs_par
 {
     njs_int_t  ret;
 
-    ret = njs_parser_match_arrow_expression(parser, token);
-    if (ret == NJS_OK) {
-        njs_parser_next(parser, njs_parser_arrow_function);
-
-        return NJS_OK;
-
-    } else if (ret == NJS_ERROR) {
-        return NJS_ERROR;
+    if (!parser->use_lhs) {
+        ret = njs_parser_match_arrow_expression(parser, token);
+        if (ret == NJS_OK) {
+            njs_parser_next(parser, njs_parser_arrow_function);
+
+            return NJS_OK;
+
+        } else if (ret == NJS_ERROR) {
+            return NJS_ERROR;
+        }
     }
 
     njs_parser_next(parser, njs_parser_conditional_expression);
diff -r 0d0b16ecf796 -r 487780764501 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Nov 16 09:15:39 2022 -0800
+++ b/src/test/njs_unit_test.c	Wed Nov 16 16:09:47 2022 -0800
@@ -2965,6 +2965,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("for(I in``[)8"),
       njs_str("SyntaxError: Unexpected token \")\" in 1") },
 
+    { njs_str("for(9A=>>"),
+      njs_str("SyntaxError: Unexpected token \"A\" in 1") },
+
     /* switch. */
 
     { njs_str("switch"),



More information about the nginx-devel mailing list