Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 918190d

Browse files
weirdpatternJamesHenry
authored andcommitted
Fix: export type alias ExportNamedDeclaration node generation (fixes #134) (#135)
1 parent 2df6d83 commit 918190d

7 files changed

+1086
-0
lines changed

lib/ast-converter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,16 +1941,23 @@ module.exports = function(ast, extra) {
19411941
init: convertChild(node.type),
19421942
range: [node.name.getStart(), node.end]
19431943
};
1944+
19441945
typeAliasDeclarator.loc = getLocFor(typeAliasDeclarator.range[0], typeAliasDeclarator.range[1], ast);
1946+
19451947
// Process typeParameters
19461948
if (node.typeParameters && node.typeParameters.length) {
19471949
typeAliasDeclarator.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters);
19481950
}
1951+
19491952
assign(result, {
19501953
type: "VariableDeclaration",
19511954
kind: "type",
19521955
declarations: [typeAliasDeclarator]
19531956
});
1957+
1958+
// check for exports
1959+
result = fixExports(node, result, ast);
1960+
19541961
break;
19551962

19561963
default:
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
40
6+
],
7+
"loc": {
8+
"end": {
9+
"line": 1,
10+
"column": 40
11+
},
12+
"start": {
13+
"line": 1,
14+
"column": 0
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExportNamedDeclaration",
20+
"range": [
21+
0,
22+
40
23+
],
24+
"loc": {
25+
"end": {
26+
"line": 1,
27+
"column": 40
28+
},
29+
"start": {
30+
"line": 1,
31+
"column": 0
32+
}
33+
},
34+
"declaration": {
35+
"type": "VariableDeclaration",
36+
"range": [
37+
7,
38+
40
39+
],
40+
"loc": {
41+
"end": {
42+
"line": 1,
43+
"column": 40
44+
},
45+
"start": {
46+
"line": 1,
47+
"column": 7
48+
}
49+
},
50+
"kind": "type",
51+
"declarations": [
52+
{
53+
"type": "VariableDeclarator",
54+
"range": [
55+
12,
56+
40
57+
],
58+
"loc": {
59+
"end": {
60+
"line": 1,
61+
"column": 40
62+
},
63+
"start": {
64+
"line": 1,
65+
"column": 12
66+
}
67+
},
68+
"id": {
69+
"type": "Identifier",
70+
"range": [
71+
12,
72+
21
73+
],
74+
"loc": {
75+
"end": {
76+
"line": 1,
77+
"column": 21
78+
},
79+
"start": {
80+
"line": 1,
81+
"column": 12
82+
}
83+
},
84+
"name": "TestAlias"
85+
},
86+
"init": {
87+
"type": "TSUnionType",
88+
"loc": {
89+
"end": {
90+
"line": 1,
91+
"column": 39
92+
},
93+
"start": {
94+
"line": 1,
95+
"column": 24
96+
}
97+
},
98+
"range": [
99+
24,
100+
39
101+
],
102+
"types": [
103+
{
104+
"type": "TSStringKeyword",
105+
"range": [
106+
24,
107+
30
108+
],
109+
"loc": {
110+
"end": {
111+
"line": 1,
112+
"column": 30
113+
},
114+
"start": {
115+
"line": 1,
116+
"column": 24
117+
}
118+
}
119+
},
120+
{
121+
"type": "TSNumberKeyword",
122+
"range": [
123+
33,
124+
39
125+
],
126+
"loc": {
127+
"end": {
128+
"line": 1,
129+
"column": 39
130+
},
131+
"start": {
132+
"line": 1,
133+
"column": 33
134+
}
135+
}
136+
}
137+
]
138+
}
139+
}
140+
]
141+
},
142+
"source": null,
143+
"specifiers": []
144+
}
145+
],
146+
"sourceType": "module",
147+
"tokens": [
148+
{
149+
"type": "Keyword",
150+
"range": [
151+
0,
152+
6
153+
],
154+
"loc": {
155+
"end": {
156+
"line": 1,
157+
"column": 6
158+
},
159+
"start": {
160+
"line": 1,
161+
"column": 0
162+
}
163+
},
164+
"value": "export"
165+
},
166+
{
167+
"type": "Identifier",
168+
"range": [
169+
7,
170+
11
171+
],
172+
"loc": {
173+
"end": {
174+
"line": 1,
175+
"column": 11
176+
},
177+
"start": {
178+
"line": 1,
179+
"column": 7
180+
}
181+
},
182+
"value": "type"
183+
},
184+
{
185+
"type": "Identifier",
186+
"range": [
187+
12,
188+
21
189+
],
190+
"loc": {
191+
"end": {
192+
"line": 1,
193+
"column": 21
194+
},
195+
"start": {
196+
"line": 1,
197+
"column": 12
198+
}
199+
},
200+
"value": "TestAlias"
201+
},
202+
{
203+
"type": "Punctuator",
204+
"range": [
205+
22,
206+
23
207+
],
208+
"loc": {
209+
"end": {
210+
"line": 1,
211+
"column": 23
212+
},
213+
"start": {
214+
"line": 1,
215+
"column": 22
216+
}
217+
},
218+
"value": "="
219+
},
220+
{
221+
"type": "Identifier",
222+
"range": [
223+
24,
224+
30
225+
],
226+
"loc": {
227+
"end": {
228+
"line": 1,
229+
"column": 30
230+
},
231+
"start": {
232+
"line": 1,
233+
"column": 24
234+
}
235+
},
236+
"value": "string"
237+
},
238+
{
239+
"type": "Punctuator",
240+
"range": [
241+
31,
242+
32
243+
],
244+
"loc": {
245+
"end": {
246+
"line": 1,
247+
"column": 32
248+
},
249+
"start": {
250+
"line": 1,
251+
"column": 31
252+
}
253+
},
254+
"value": "|"
255+
},
256+
{
257+
"type": "Identifier",
258+
"range": [
259+
33,
260+
39
261+
],
262+
"loc": {
263+
"end": {
264+
"line": 1,
265+
"column": 39
266+
},
267+
"start": {
268+
"line": 1,
269+
"column": 33
270+
}
271+
},
272+
"value": "number"
273+
},
274+
{
275+
"type": "Punctuator",
276+
"range": [
277+
39,
278+
40
279+
],
280+
"loc": {
281+
"end": {
282+
"line": 1,
283+
"column": 40
284+
},
285+
"start": {
286+
"line": 1,
287+
"column": 39
288+
}
289+
},
290+
"value": ";"
291+
}
292+
]
293+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type TestAlias = string | number;

0 commit comments

Comments
 (0)