Skip to content

Commit 6d4c7d0

Browse files
committed
Support for ES2020 export ns from
1 parent 3515f7e commit 6d4c7d0

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
@@ -316,9 +316,11 @@ export class EmptyStatement {
316316
export class ExportAllDeclaration {
317317
readonly type: string;
318318
readonly source: Literal;
319-
constructor(source: Literal) {
319+
readonly exported: Identifier | null;
320+
constructor(source: Literal, exported: Identifier | null) {
320321
this.type = Syntax.ExportAllDeclaration;
321322
this.source = source;
323+
this.exported = exported;
322324
}
323325
}
324326

src/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3610,14 +3610,19 @@ export class Parser {
36103610
} else if (this.match('*')) {
36113611
// export * from 'foo';
36123612
this.nextToken();
3613+
let exported: Node.Identifier | null = null;
3614+
if (this.matchContextualKeyword('as')) {
3615+
this.nextToken();
3616+
exported = this.parseIdentifierName();
3617+
}
36133618
if (!this.matchContextualKeyword('from')) {
36143619
const message = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
36153620
this.throwError(message, this.lookahead.value);
36163621
}
36173622
this.nextToken();
36183623
const src = this.parseModuleSpecifier();
36193624
this.consumeSemicolon();
3620-
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
3625+
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src, exported));
36213626

36223627
} else if (this.lookahead.type === Token.Keyword) {
36233628
// 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
@@ -2419,14 +2419,6 @@ test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-
24192419
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-spread-operator.js(strict mode)
24202420
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(default)
24212421
test/language/arguments-object/cls-expr-private-meth-static-args-trailing-comma-undefined.js(strict mode)
2422-
test/language/module-code/eval-rqstd-once.js(default)
2423-
test/language/module-code/eval-rqstd-once.js(strict mode)
2424-
test/language/module-code/eval-rqstd-order.js(default)
2425-
test/language/module-code/eval-rqstd-order.js(strict mode)
2426-
test/language/module-code/eval-self-once.js(default)
2427-
test/language/module-code/eval-self-once.js(strict mode)
2428-
test/language/module-code/instn-once.js(default)
2429-
test/language/module-code/instn-once.js(strict mode)
24302422
test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(default)
24312423
test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js(strict mode)
24322424
test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.js(default)
@@ -15156,8 +15148,6 @@ test/language/module-code/export-expname-from-string.js(default)
1515615148
test/language/module-code/export-expname-from-string.js(strict mode)
1515715149
test/language/module-code/export-expname-import-string-binding.js(default)
1515815150
test/language/module-code/export-expname-import-string-binding.js(strict mode)
15159-
test/language/module-code/export-star-as-dflt.js(default)
15160-
test/language/module-code/export-star-as-dflt.js(strict mode)
1516115151
test/annexB/built-ins/escape/argument_bigint.js(default)
1516215152
test/annexB/built-ins/escape/argument_bigint.js(strict mode)
1516315153
test/annexB/built-ins/unescape/argument_bigint.js(default)
@@ -17466,4 +17456,8 @@ test/language/statements/class/async-gen-method-static/forbidden-ext/b2/cls-decl
1746617456
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)
1746717457
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)
1746817458
test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(default)
17469-
test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(strict mode)
17459+
test/language/statements/class/elements/syntax/valid/grammar-special-prototype-async-gen-meth-valid.js(strict mode)
17460+
test/language/module-code/early-dup-export-as-star-as.js(default)
17461+
test/language/module-code/early-dup-export-as-star-as.js(strict mode)
17462+
test/language/module-code/early-dup-export-star-as-dflt.js(default)
17463+
test/language/module-code/early-dup-export-star-as-dflt.js(strict mode)

0 commit comments

Comments
 (0)