Skip to content

Commit 7428846

Browse files
committed
Support for ES2020 export ns from
1 parent 977b1f8 commit 7428846

File tree

6 files changed

+200
-13
lines changed

6 files changed

+200
-13
lines changed

src/nodes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ export class EmptyStatement {
330330
export class ExportAllDeclaration {
331331
readonly type: string;
332332
readonly source: Literal;
333-
constructor(source: Literal) {
333+
readonly exported: Identifier | null;
334+
constructor(source: Literal, exported: Identifier | null) {
334335
this.type = Syntax.ExportAllDeclaration;
335336
this.source = source;
337+
this.exported = exported;
336338
}
337339
}
338340

src/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,14 +3678,19 @@ export class Parser {
36783678
} else if (this.match('*')) {
36793679
// export * from 'foo';
36803680
this.nextToken();
3681+
let exported: Node.Identifier | null = null;
3682+
if (this.matchContextualKeyword('as')) {
3683+
this.nextToken();
3684+
exported = this.parseIdentifierName();
3685+
}
36813686
if (!this.matchContextualKeyword('from')) {
36823687
const message = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
36833688
this.throwError(message, this.lookahead.value);
36843689
}
36853690
this.nextToken();
36863691
const src = this.parseModuleSpecifier();
36873692
this.consumeSemicolon();
3688-
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
3693+
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src, exported));
36893694

36903695
} else if (this.lookahead.type === Token.Keyword) {
36913696
// export var f = 1;

test/fixtures/ES6/export-declaration/export-from-batch.tree.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
}
2323
}
2424
},
25+
"exported": null,
2526
"range": [
2627
0,
2728
20
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as someIdentifier from "someModule"
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExportAllDeclaration",
6+
"source": {
7+
"type": "Literal",
8+
"value": "someModule",
9+
"raw": "\"someModule\"",
10+
"range": [
11+
32,
12+
44
13+
],
14+
"loc": {
15+
"start": {
16+
"line": 1,
17+
"column": 32
18+
},
19+
"end": {
20+
"line": 1,
21+
"column": 44
22+
}
23+
}
24+
},
25+
"exported": {
26+
"type": "Identifier",
27+
"name": "someIdentifier",
28+
"range": [
29+
12,
30+
26
31+
],
32+
"loc": {
33+
"start": {
34+
"line": 1,
35+
"column": 12
36+
},
37+
"end": {
38+
"line": 1,
39+
"column": 26
40+
}
41+
}
42+
},
43+
"range": [
44+
0,
45+
44
46+
],
47+
"loc": {
48+
"start": {
49+
"line": 1,
50+
"column": 0
51+
},
52+
"end": {
53+
"line": 1,
54+
"column": 44
55+
}
56+
}
57+
}
58+
],
59+
"sourceType": "module",
60+
"range": [
61+
0,
62+
44
63+
],
64+
"loc": {
65+
"start": {
66+
"line": 1,
67+
"column": 0
68+
},
69+
"end": {
70+
"line": 1,
71+
"column": 44
72+
}
73+
},
74+
"tokens": [
75+
{
76+
"type": "Keyword",
77+
"value": "export",
78+
"range": [
79+
0,
80+
6
81+
],
82+
"loc": {
83+
"start": {
84+
"line": 1,
85+
"column": 0
86+
},
87+
"end": {
88+
"line": 1,
89+
"column": 6
90+
}
91+
}
92+
},
93+
{
94+
"type": "Punctuator",
95+
"value": "*",
96+
"range": [
97+
7,
98+
8
99+
],
100+
"loc": {
101+
"start": {
102+
"line": 1,
103+
"column": 7
104+
},
105+
"end": {
106+
"line": 1,
107+
"column": 8
108+
}
109+
}
110+
},
111+
{
112+
"type": "Identifier",
113+
"value": "as",
114+
"range": [
115+
9,
116+
11
117+
],
118+
"loc": {
119+
"start": {
120+
"line": 1,
121+
"column": 9
122+
},
123+
"end": {
124+
"line": 1,
125+
"column": 11
126+
}
127+
}
128+
},
129+
{
130+
"type": "Identifier",
131+
"value": "someIdentifier",
132+
"range": [
133+
12,
134+
26
135+
],
136+
"loc": {
137+
"start": {
138+
"line": 1,
139+
"column": 12
140+
},
141+
"end": {
142+
"line": 1,
143+
"column": 26
144+
}
145+
}
146+
},
147+
{
148+
"type": "Identifier",
149+
"value": "from",
150+
"range": [
151+
27,
152+
31
153+
],
154+
"loc": {
155+
"start": {
156+
"line": 1,
157+
"column": 27
158+
},
159+
"end": {
160+
"line": 1,
161+
"column": 31
162+
}
163+
}
164+
},
165+
{
166+
"type": "String",
167+
"value": "\"someModule\"",
168+
"range": [
169+
32,
170+
44
171+
],
172+
"loc": {
173+
"start": {
174+
"line": 1,
175+
"column": 32
176+
},
177+
"end": {
178+
"line": 1,
179+
"column": 44
180+
}
181+
}
182+
}
183+
]
184+
}

test/test-262-whitelist.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,14 +2411,6 @@ test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-
24112411
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-spread-operator.js(strict mode)
24122412
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(default)
24132413
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(strict mode)
2414-
test/language/module-code/eval-rqstd-once.js(default)
2415-
test/language/module-code/eval-rqstd-once.js(strict mode)
2416-
test/language/module-code/eval-rqstd-order.js(default)
2417-
test/language/module-code/eval-rqstd-order.js(strict mode)
2418-
test/language/module-code/eval-self-once.js(default)
2419-
test/language/module-code/eval-self-once.js(strict mode)
2420-
test/language/module-code/instn-once.js(default)
2421-
test/language/module-code/instn-once.js(strict mode)
24222414
test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(default)
24232415
test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(strict mode)
24242416
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)
1513415126
test/language/module-code/export-expname-from-string.js(strict mode)
1513515127
test/language/module-code/export-expname-import-string-binding.js(default)
1513615128
test/language/module-code/export-expname-import-string-binding.js(strict mode)
15137-
test/language/module-code/export-star-as-dflt.js(default)
15138-
test/language/module-code/export-star-as-dflt.js(strict mode)
1513915129
test/annexB/built-ins/escape/argument_bigint.js(default)
1514015130
test/annexB/built-ins/escape/argument_bigint.js(strict mode)
1514115131
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
1739817388
test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(default)
1739917389
test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(strict mode)
1740017390
test/language/expressions/optional-chaining/call-expression-super-no-base.js(default)
17401-
test/language/expressions/optional-chaining/call-expression-super-no-base.js(strict mode)
17391+
test/language/expressions/optional-chaining/call-expression-super-no-base.js(strict mode)
17392+
test/language/module-code/early-dup-export-as-star-as.js(default)
17393+
test/language/module-code/early-dup-export-as-star-as.js(strict mode)
17394+
test/language/module-code/early-dup-export-star-as-dflt.js(default)
17395+
test/language/module-code/early-dup-export-star-as-dflt.js(strict mode)

0 commit comments

Comments
 (0)