[njs] Fixed ellipsis support.
Dmitry Volyntsev
xeioex at nginx.com
Thu May 12 00:10:44 UTC 2022
details: https://hg.nginx.org/njs/rev/34af2730bf97
branches:
changeset: 1853:34af2730bf97
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed May 11 16:33:46 2022 -0700
description:
Fixed ellipsis support.
As of now, ellispis syntax is supported for function declaration with
the rest arguments.
This closes #365 issue on Github.
diffstat:
src/njs_parser.c | 8 ++++++++
src/test/njs_unit_test.c | 5 +++++
2 files changed, 13 insertions(+), 0 deletions(-)
diffs (52 lines):
diff -r 5c7e02885c26 -r 34af2730bf97 src/njs_parser.c
--- a/src/njs_parser.c Fri May 06 18:55:35 2022 -0700
+++ b/src/njs_parser.c Wed May 11 16:33:46 2022 -0700
@@ -1664,12 +1664,18 @@ njs_parser_array_element_list(njs_parser
return NJS_OK;
case NJS_TOKEN_ELLIPSIS:
+#if 0
njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_assignment_expression);
return njs_parser_after(parser, current, array, 0,
njs_parser_array_spread_element);
+#else
+ (void) njs_parser_array_spread_element;
+ return njs_parser_failed(parser);
+#endif
+
default:
break;
}
@@ -2862,9 +2868,11 @@ njs_parser_argument_list(njs_parser_t *p
* ArgumentList , ... AssignmentExpression
*/
+#if 0 /* TODO. */
if (token->type == NJS_TOKEN_ELLIPSIS) {
njs_lexer_consume_token(parser->lexer, 1);
}
+#endif
njs_parser_next(parser, njs_parser_assignment_expression);
diff -r 5c7e02885c26 -r 34af2730bf97 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri May 06 18:55:35 2022 -0700
+++ b/src/test/njs_unit_test.c Wed May 11 16:33:46 2022 -0700
@@ -18041,9 +18041,14 @@ static njs_unit_test_t njs_test[] =
{ njs_str("[(]"),
njs_str("SyntaxError: Unexpected token \"]\" in 1") },
+#if 0 /* TODO spreading support. */
{ njs_str("[...]"),
njs_str("SyntaxError: Unexpected token \"]\" in 1") },
+ { njs_str("var id = (x) => x, x = id(...[1,2,3]); typeof x"),
+ njs_str("number") },
+#endif
+
{ njs_str("switch () {}"),
njs_str("SyntaxError: Unexpected token \")\" in 1") },
More information about the nginx-devel
mailing list