Welcome! Log In Create A New Profile

Advanced

[njs] Fixed ellipsis support.

Dmitry Volyntsev
May 11, 2022 08:14PM
details: https://hg.nginx.org/njs/rev/34af2730bf97
branches:
changeset: 1853:34af2730bf97
user: Dmitry Volyntsev <xeioex@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") },

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed ellipsis support.

Dmitry Volyntsev 239 May 11, 2022 08:14PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 131
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready