[njs] Avoiding strict check in export default value expressions.

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 28 17:40:05 UTC 2019


details:   https://hg.nginx.org/njs/rev/913398656772
branches:  
changeset: 857:913398656772
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Mar 28 20:31:20 2019 +0300
description:
Avoiding strict check in export default value expressions.

Previously, only object literals were allowed.

diffstat:

 njs/njs_parser.c                      |   5 -----
 njs/test/module/export_expression.js  |  10 ++++++++++
 njs/test/module/export_expression2.js |   5 +++++
 njs/test/module/export_name.js        |   6 ++++++
 njs/test/njs_expect_test.exp          |  12 ++++++++++++
 5 files changed, 33 insertions(+), 5 deletions(-)

diffs (70 lines):

diff -r 6b8bb252ad06 -r 913398656772 njs/njs_parser.c
--- a/njs/njs_parser.c	Thu Mar 28 19:45:58 2019 +0300
+++ b/njs/njs_parser.c	Thu Mar 28 20:31:20 2019 +0300
@@ -2076,11 +2076,6 @@ njs_parser_export_statement(njs_vm_t *vm
         return token;
     }
 
-    if (parser->node->token != NJS_TOKEN_OBJECT) {
-        njs_parser_syntax_error(vm, parser, "Illegal export value");
-        return NXT_ERROR;
-    }
-
     node->right = parser->node;
     parser->node = node;
 
diff -r 6b8bb252ad06 -r 913398656772 njs/test/module/export_expression.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/njs/test/module/export_expression.js	Thu Mar 28 20:31:20 2019 +0300
@@ -0,0 +1,10 @@
+function gen_export() {
+    var _export = {};
+
+    _export.sum = function(a, b) { return a + b; }
+    _export.prod = function(a, b) { return a * b; }
+
+    return _export;
+}
+
+export default gen_export();
diff -r 6b8bb252ad06 -r 913398656772 njs/test/module/export_expression2.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/njs/test/module/export_expression2.js	Thu Mar 28 20:31:20 2019 +0300
@@ -0,0 +1,5 @@
+var _export = {};
+
+export default (_export.sum = function(a, b) { return a + b; },
+                _export.prod = function(a, b) { return a * b; },
+                _export);
diff -r 6b8bb252ad06 -r 913398656772 njs/test/module/export_name.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/njs/test/module/export_name.js	Thu Mar 28 20:31:20 2019 +0300
@@ -0,0 +1,6 @@
+var _export = {};
+
+_export.sum = function(a, b) { return a + b; }
+_export.prod = function(a, b) { return a * b; }
+
+export default _export;
diff -r 6b8bb252ad06 -r 913398656772 njs/test/njs_expect_test.exp
--- a/njs/test/njs_expect_test.exp	Thu Mar 28 19:45:58 2019 +0300
+++ b/njs/test/njs_expect_test.exp	Thu Mar 28 20:31:20 2019 +0300
@@ -685,6 +685,18 @@ njs_test {
      "Error: loading exception\r\n    at module \\(loading_exception.js:1\\)"}
     {"import lib3 from 'lib1.js'\r\n"
      "undefined\r\n"}
+    {"import m from 'export_name.js'\r\n"
+     "undefined\r\n"}
+    {"m.prod(3,4)\r\n"
+     "12\r\n"}
+    {"import m from 'export_expression.js'\r\n"
+     "undefined\r\n"}
+    {"m.sum(3,4)\r\n"
+     "7\r\n"}
+    {"import m from 'export_expression2.js'\r\n"
+     "undefined\r\n"}
+    {"m.prod(3,4)\r\n"
+     "12\r\n"}
 } "-p njs/test/module/"
 
 njs_run "-p njs/test/module/libs/ -d ./njs/test/module/normal.js" \


More information about the nginx-devel mailing list