Skip to content

Commit

Permalink
Support for ES2020 export ns from
Browse files Browse the repository at this point in the history
  • Loading branch information
ljqx committed May 11, 2021
1 parent 977b1f8 commit 7428846
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3678,14 +3678,19 @@ 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);
}
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}
}
},
"exported": null,
"range": [
0,
20
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es2020/export-ns-from/goal.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as someIdentifier from "someModule"
184 changes: 184 additions & 0 deletions test/fixtures/es2020/export-ns-from/goal.module.tree.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}
16 changes: 5 additions & 11 deletions test/test-262-whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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)

0 comments on commit 7428846

Please sign in to comment.