Welcome! Log In Create A New Profile

Advanced

[njs] Parser: improved error message for import statement.

Dmitry Volyntsev
May 27, 2023 01:08PM
details: https://hg.nginx.org/njs/rev/2e8563c8143b
branches:
changeset: 2142:2e8563c8143b
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri May 26 21:54:12 2023 -0700
description:
Parser: improved error message for import statement.

This closes #642 issue on Github.

diffstat:

src/njs_parser.c | 9 ++++++++-
src/test/njs_unit_test.c | 8 +++++++-
2 files changed, 15 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r 9213a609cb17 -r 2e8563c8143b src/njs_parser.c
--- a/src/njs_parser.c Fri May 26 21:05:15 2023 -0700
+++ b/src/njs_parser.c Fri May 26 21:54:12 2023 -0700
@@ -8118,11 +8118,18 @@ njs_parser_import(njs_parser_t *parser,
return NJS_DONE;
}

- if (token->type != NJS_TOKEN_NAME) {
+ if (token->type == NJS_TOKEN_MULTIPLICATION
+ || token->type == NJS_TOKEN_OPEN_BRACE
+ || token->type == NJS_TOKEN_STRING)
+ {
njs_parser_syntax_error(parser, "Non-default import is not supported");
return NJS_DONE;
}

+ if (token->type != NJS_TOKEN_NAME) {
+ return njs_parser_failed(parser);
+ }
+
name = njs_parser_variable_node(parser, token->unique_id, NJS_VARIABLE_LET,
&var);
if (name == NULL) {
diff -r 9213a609cb17 -r 2e8563c8143b src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri May 26 21:05:15 2023 -0700
+++ b/src/test/njs_unit_test.c Fri May 26 21:54:12 2023 -0700
@@ -18903,12 +18903,18 @@ static njs_unit_test_t njs_test[] =

/* Module. */

- { njs_str("import;"),
+ { njs_str("import * from y"),
+ njs_str("SyntaxError: Non-default import is not supported in 1") },
+
+ { njs_str("import 'x' from y"),
njs_str("SyntaxError: Non-default import is not supported in 1") },

{ njs_str("import {x} from y"),
njs_str("SyntaxError: Non-default import is not supported in 1") },

+ { njs_str("import switch from y"),
+ njs_str("SyntaxError: Unexpected token \"switch\" in 1") },
+
{ njs_str("import x from y"),
njs_str("SyntaxError: Unexpected token \"y\" in 1") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Parser: improved error message for import statement.

Dmitry Volyntsev 285 May 27, 2023 01:08PM



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

Online Users

Guests: 100
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready