From 7428846b2bcc2f1a5a0f463e950728ca8f0f12d5 Mon Sep 17 00:00:00 2001 From: Remi Liu Date: Mon, 7 Dec 2020 14:45:37 +0800 Subject: [PATCH] Support for ES2020 export ns from --- src/nodes.ts | 4 +- src/parser.ts | 7 +- .../export-from-batch.tree.json | 1 + .../es2020/export-ns-from/goal.module.js | 1 + .../export-ns-from/goal.module.tree.json | 184 ++++++++++++++++++ test/test-262-whitelist.txt | 16 +- 6 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/es2020/export-ns-from/goal.module.js create mode 100644 test/fixtures/es2020/export-ns-from/goal.module.tree.json diff --git a/src/nodes.ts b/src/nodes.ts index 2b92e9fe2..bc4916564 100644 --- a/src/nodes.ts +++ b/src/nodes.ts @@ -330,9 +330,11 @@ export class EmptyStatement { export class ExportAllDeclaration { readonly type: string; readonly source: Literal; - constructor(source: Literal) { + readonly exported: Identifier | null; + constructor(source: Literal, exported: Identifier | null) { this.type = Syntax.ExportAllDeclaration; this.source = source; + this.exported = exported; } } diff --git a/src/parser.ts b/src/parser.ts index fe21966ec..20ad43a82 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3678,6 +3678,11 @@ export class Parser { } else if (this.match('*')) { // export * from 'foo'; this.nextToken(); + let exported: Node.Identifier | null = null; + if (this.matchContextualKeyword('as')) { + this.nextToken(); + exported = this.parseIdentifierName(); + } if (!this.matchContextualKeyword('from')) { const message = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause; this.throwError(message, this.lookahead.value); @@ -3685,7 +3690,7 @@ export class Parser { this.nextToken(); const src = this.parseModuleSpecifier(); this.consumeSemicolon(); - exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src)); + exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src, exported)); } else if (this.lookahead.type === Token.Keyword) { // export var f = 1; diff --git a/test/fixtures/ES6/export-declaration/export-from-batch.tree.json b/test/fixtures/ES6/export-declaration/export-from-batch.tree.json index 9b835d7dc..e5da23753 100644 --- a/test/fixtures/ES6/export-declaration/export-from-batch.tree.json +++ b/test/fixtures/ES6/export-declaration/export-from-batch.tree.json @@ -22,6 +22,7 @@ } } }, + "exported": null, "range": [ 0, 20 diff --git a/test/fixtures/es2020/export-ns-from/goal.module.js b/test/fixtures/es2020/export-ns-from/goal.module.js new file mode 100644 index 000000000..624200f6b --- /dev/null +++ b/test/fixtures/es2020/export-ns-from/goal.module.js @@ -0,0 +1 @@ +export * as someIdentifier from "someModule" \ No newline at end of file diff --git a/test/fixtures/es2020/export-ns-from/goal.module.tree.json b/test/fixtures/es2020/export-ns-from/goal.module.tree.json new file mode 100644 index 000000000..9fa07c44d --- /dev/null +++ b/test/fixtures/es2020/export-ns-from/goal.module.tree.json @@ -0,0 +1,184 @@ +{ + "type": "Program", + "body": [ + { + "type": "ExportAllDeclaration", + "source": { + "type": "Literal", + "value": "someModule", + "raw": "\"someModule\"", + "range": [ + 32, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 44 + } + } + }, + "exported": { + "type": "Identifier", + "name": "someIdentifier", + "range": [ + 12, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "range": [ + 0, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + } + } + ], + "sourceType": "module", + "range": [ + 0, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "tokens": [ + { + "type": "Keyword", + "value": "export", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "*", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "as", + "range": [ + 9, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "someIdentifier", + "range": [ + 12, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + { + "type": "String", + "value": "\"someModule\"", + "range": [ + 32, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 44 + } + } + } + ] +} \ No newline at end of file diff --git a/test/test-262-whitelist.txt b/test/test-262-whitelist.txt index d1bb4ad5e..f1c134bb8 100644 --- a/test/test-262-whitelist.txt +++ b/test/test-262-whitelist.txt @@ -2411,14 +2411,6 @@ test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma- test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-spread-operator.js(strict mode) test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(default) test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(strict mode) -test/language/module-code/eval-rqstd-once.js(default) -test/language/module-code/eval-rqstd-once.js(strict mode) -test/language/module-code/eval-rqstd-order.js(default) -test/language/module-code/eval-rqstd-order.js(strict mode) -test/language/module-code/eval-self-once.js(default) -test/language/module-code/eval-self-once.js(strict mode) -test/language/module-code/instn-once.js(default) -test/language/module-code/instn-once.js(strict mode) test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(default) test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(strict mode) test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.js(default) @@ -15134,8 +15126,6 @@ test/language/module-code/export-expname-from-string.js(default) test/language/module-code/export-expname-from-string.js(strict mode) test/language/module-code/export-expname-import-string-binding.js(default) test/language/module-code/export-expname-import-string-binding.js(strict mode) -test/language/module-code/export-star-as-dflt.js(default) -test/language/module-code/export-star-as-dflt.js(strict mode) test/annexB/built-ins/escape/argument_bigint.js(default) test/annexB/built-ins/escape/argument_bigint.js(strict mode) test/annexB/built-ins/unescape/argument_bigint.js(default) @@ -17398,4 +17388,8 @@ test/language/statements/class/async-gen-method-static/forbidden-ext/b2/cls-decl test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(default) test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(strict mode) test/language/expressions/optional-chaining/call-expression-super-no-base.js(default) -test/language/expressions/optional-chaining/call-expression-super-no-base.js(strict mode) \ No newline at end of file +test/language/expressions/optional-chaining/call-expression-super-no-base.js(strict mode) +test/language/module-code/early-dup-export-as-star-as.js(default) +test/language/module-code/early-dup-export-as-star-as.js(strict mode) +test/language/module-code/early-dup-export-star-as-dflt.js(default) +test/language/module-code/early-dup-export-star-as-dflt.js(strict mode)