Welcome! Log In Create A New Profile

Advanced

[njs] Fixed variable declaration with "from" name.

Dmitry Volyntsev
October 11, 2019 10:26AM
details: https://hg.nginx.org/njs/rev/b4cd260f7b69
branches:
changeset: 1183:b4cd260f7b69
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Oct 11 17:08:28 2019 +0300
description:
Fixed variable declaration with "from" name.

Previously, "from" was declared as a reserved word.

diffstat:

src/njs_lexer.h | 1 -
src/njs_lexer_keyword.c | 1 -
src/njs_parser.c | 2 +-
src/njs_parser.h | 21 +++++++++++++++++++++
src/test/njs_unit_test.c | 3 +++
5 files changed, 25 insertions(+), 3 deletions(-)

diffs (78 lines):

diff -r a4e44e7e6f38 -r b4cd260f7b69 src/njs_lexer.h
--- a/src/njs_lexer.h Fri Oct 11 06:50:33 2019 +0300
+++ b/src/njs_lexer.h Fri Oct 11 17:08:28 2019 +0300
@@ -214,7 +214,6 @@ typedef enum {
NJS_TOKEN_CLEAR_TIMEOUT,

NJS_TOKEN_IMPORT,
- NJS_TOKEN_FROM,
NJS_TOKEN_EXPORT,

NJS_TOKEN_RESERVED,
diff -r a4e44e7e6f38 -r b4cd260f7b69 src/njs_lexer_keyword.c
--- a/src/njs_lexer_keyword.c Fri Oct 11 06:50:33 2019 +0300
+++ b/src/njs_lexer_keyword.c Fri Oct 11 17:08:28 2019 +0300
@@ -96,7 +96,6 @@ static const njs_keyword_t njs_keywords

/* Module. */
{ njs_str("import"), NJS_TOKEN_IMPORT, 0 },
- { njs_str("from"), NJS_TOKEN_FROM, 0 },
{ njs_str("export"), NJS_TOKEN_EXPORT, 0 },

/* Reserved words. */
diff -r a4e44e7e6f38 -r b4cd260f7b69 src/njs_parser.c
--- a/src/njs_parser.c Fri Oct 11 06:50:33 2019 +0300
+++ b/src/njs_parser.c Fri Oct 11 17:08:28 2019 +0300
@@ -1825,7 +1825,7 @@ njs_parser_import_statement(njs_vm_t *vm
return token;
}

- token = njs_parser_match(vm, parser, token, NJS_TOKEN_FROM);
+ token = njs_parser_match_name(vm, parser, token, "from");
if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
diff -r a4e44e7e6f38 -r b4cd260f7b69 src/njs_parser.h
--- a/src/njs_parser.h Fri Oct 11 06:50:33 2019 +0300
+++ b/src/njs_parser.h Fri Oct 11 17:08:28 2019 +0300
@@ -233,6 +233,27 @@ njs_parser_match(njs_vm_t *vm, njs_parse
}


+njs_inline njs_token_t
+njs_parser_match_name(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token,
+ const char *name)
+{
+ size_t len;
+ njs_str_t *text;
+
+ len = njs_strlen(name);
+ text = njs_parser_text(parser);
+
+ if (njs_fast_path(token == NJS_TOKEN_NAME
+ && text->length == len
+ && memcmp(text->start, name, len) == 0))
+ {
+ return njs_parser_token(vm, parser);
+ }
+
+ return njs_parser_unexpected_token(vm, parser, token);
+}
+
+
njs_inline njs_variable_t *
njs_parser_variable_add(njs_vm_t *vm, njs_parser_t *parser,
njs_variable_type_t type)
diff -r a4e44e7e6f38 -r b4cd260f7b69 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Oct 11 06:50:33 2019 +0300
+++ b/src/test/njs_unit_test.c Fri Oct 11 17:08:28 2019 +0300
@@ -69,6 +69,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var \n a, \n b; b"),
njs_str("undefined") },

+ { njs_str("var from = 2; from + 2"),
+ njs_str("4") },
+
{ njs_str("var a / ="),
njs_str("SyntaxError: Unexpected token \"/\" in 1") },

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

[njs] Fixed variable declaration with "from" name.

Dmitry Volyntsev 64 October 11, 2019 10:26AM



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

Online Users

Guests: 75
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