[njs] Fixed parsing of export default declarations.

Dmitry Volyntsev xeioex at nginx.com
Tue Jun 29 12:13:37 UTC 2021


details:   https://hg.nginx.org/njs/rev/f1a1b9ad198d
branches:  
changeset: 1668:f1a1b9ad198d
user:      Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date:      Thu Jun 24 08:53:12 2021 +0300
description:
Fixed parsing of export default declarations.

With non-assignment expression.

diffstat:

 src/njs_parser.c                     |  6 +++++-
 test/module/export_non_assignment.js |  1 +
 test/njs_expect_test.exp             |  2 ++
 3 files changed, 8 insertions(+), 1 deletions(-)

diffs (40 lines):

diff -r f10d5c38f098 -r f1a1b9ad198d src/njs_parser.c
--- a/src/njs_parser.c	Fri Jun 25 17:00:12 2021 +0000
+++ b/src/njs_parser.c	Thu Jun 24 08:53:12 2021 +0300
@@ -7468,7 +7468,7 @@ njs_parser_export(njs_parser_t *parser, 
     node->token_line = parser->line;
     parser->node = node;
 
-    njs_parser_next(parser, njs_parser_expression);
+    njs_parser_next(parser, njs_parser_assignment_expression);
 
     return njs_parser_after(parser, current, node, 1, njs_parser_export_after);
 }
@@ -7478,6 +7478,10 @@ static njs_int_t
 njs_parser_export_after(njs_parser_t *parser, njs_lexer_token_t *token,
     njs_queue_link_t *current)
 {
+    if (njs_parser_expect_semicolon(parser, token) != NJS_OK) {
+        return njs_parser_failed(parser);
+    }
+
     parser->target->right = parser->node;
     parser->node = parser->target;
 
diff -r f10d5c38f098 -r f1a1b9ad198d test/module/export_non_assignment.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/module/export_non_assignment.js	Thu Jun 24 08:53:12 2021 +0300
@@ -0,0 +1,1 @@
+export default 10, 11;
diff -r f10d5c38f098 -r f1a1b9ad198d test/njs_expect_test.exp
--- a/test/njs_expect_test.exp	Fri Jun 25 17:00:12 2021 +0000
+++ b/test/njs_expect_test.exp	Thu Jun 24 08:53:12 2021 +0300
@@ -749,6 +749,8 @@ njs_test {
      "Identifier \"default\" has already been declared in export.js:5\r\n"}
     {"import m from 'export_non_default.js'\r\n"
      "Non-default export is not supported in export_non_default.js:3\r\n"}
+    {"import m from 'export_non_assignment.js'\r\n"
+     "Unexpected token \",\" in export_non_assignment.js:1\r\n"}
     {"import ref from 'ref_exception.js'\r\n"
      "ReferenceError: \"undeclared\" is not defined"}
     {"var ref\r\n"


More information about the nginx-devel mailing list