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 Dec 7, 2020
1 parent 3515f7e commit 6d4c7d0
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 @@ -316,9 +316,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 @@ -3610,14 +3610,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 @@ -2419,14 +2419,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 @@ -15156,8 +15148,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 @@ -17466,4 +17456,8 @@ test/language/statements/class/async-gen-method-static/forbidden-ext/b2/cls-decl
test/language/statements/class/async-gen-method-static/forbidden-ext/b2/cls-decl-async-gen-meth-static-forbidden-ext-indirect-access-prop-caller.js(default)
test/language/statements/class/async-gen-method-static/forbidden-ext/b2/cls-decl-async-gen-meth-static-forbidden-ext-indirect-access-own-prop-caller-value.js(default)
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/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.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 6d4c7d0

Please sign in to comment.