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

Commit 8fb71d2

Browse files
flying-sheepsoda0289
authored andcommitted
Breaking: Add .body to TSModuleBlock nodes (fixes #217) (#218)
1 parent 471f403 commit 8fb71d2

File tree

4 files changed

+361
-2
lines changed

4 files changed

+361
-2
lines changed

lib/ast-converter.js

+7
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,13 @@ module.exports = function(ast, extra) {
15941594
break;
15951595

15961596
// Modules
1597+
case SyntaxKind.ModuleBlock:
1598+
assign(result, {
1599+
type: "TSModuleBlock",
1600+
body: node.statements.map(convertChild)
1601+
});
1602+
break;
1603+
15971604
case SyntaxKind.ImportDeclaration:
15981605
assign(result, {
15991606
type: "ImportDeclaration",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
module.exports = {
2+
"body": [
3+
{
4+
"body": {
5+
"body": [
6+
{
7+
"loc": {
8+
"end": {
9+
"column": 22,
10+
"line": 2
11+
},
12+
"start": {
13+
"column": 2,
14+
"line": 2
15+
}
16+
},
17+
"range": [
18+
34,
19+
54
20+
],
21+
"source": {
22+
"loc": {
23+
"end": {
24+
"column": 21,
25+
"line": 2
26+
},
27+
"start": {
28+
"column": 17,
29+
"line": 2
30+
}
31+
},
32+
"range": [
33+
49,
34+
53
35+
],
36+
"raw": "'fs'",
37+
"type": "Literal",
38+
"value": "fs"
39+
},
40+
"specifiers": [
41+
{
42+
"loc": {
43+
"end": {
44+
"column": 11,
45+
"line": 2
46+
},
47+
"start": {
48+
"column": 9,
49+
"line": 2
50+
}
51+
},
52+
"local": {
53+
"loc": {
54+
"end": {
55+
"column": 11,
56+
"line": 2
57+
},
58+
"start": {
59+
"column": 9,
60+
"line": 2
61+
}
62+
},
63+
"name": "fs",
64+
"range": [
65+
41,
66+
43
67+
],
68+
"type": "Identifier"
69+
},
70+
"range": [
71+
41,
72+
43
73+
],
74+
"type": "ImportDefaultSpecifier"
75+
}
76+
],
77+
"type": "ImportDeclaration"
78+
}
79+
],
80+
"loc": {
81+
"end": {
82+
"column": 1,
83+
"line": 3
84+
},
85+
"start": {
86+
"column": 30,
87+
"line": 1
88+
}
89+
},
90+
"range": [
91+
30,
92+
56
93+
],
94+
"type": "TSModuleBlock"
95+
},
96+
"loc": {
97+
"end": {
98+
"column": 1,
99+
"line": 3
100+
},
101+
"start": {
102+
"column": 0,
103+
"line": 1
104+
}
105+
},
106+
"modifiers": [
107+
{
108+
"loc": {
109+
"end": {
110+
"column": 7,
111+
"line": 1
112+
},
113+
"start": {
114+
"column": 0,
115+
"line": 1
116+
}
117+
},
118+
"range": [
119+
0,
120+
7
121+
],
122+
"type": "TSDeclareKeyword"
123+
}
124+
],
125+
"name": {
126+
"loc": {
127+
"end": {
128+
"column": 29,
129+
"line": 1
130+
},
131+
"start": {
132+
"column": 15,
133+
"line": 1
134+
}
135+
},
136+
"range": [
137+
15,
138+
29
139+
],
140+
"raw": "\"i-use-things\"",
141+
"type": "Literal",
142+
"value": "i-use-things"
143+
},
144+
"range": [
145+
0,
146+
56
147+
],
148+
"type": "TSModuleDeclaration"
149+
}
150+
],
151+
"loc": {
152+
"end": {
153+
"column": 1,
154+
"line": 3
155+
},
156+
"start": {
157+
"column": 0,
158+
"line": 1
159+
}
160+
},
161+
"range": [
162+
0,
163+
56
164+
],
165+
"sourceType": "script",
166+
"tokens": [
167+
{
168+
"loc": {
169+
"end": {
170+
"column": 7,
171+
"line": 1
172+
},
173+
"start": {
174+
"column": 0,
175+
"line": 1
176+
}
177+
},
178+
"range": [
179+
0,
180+
7
181+
],
182+
"type": "Identifier",
183+
"value": "declare"
184+
},
185+
{
186+
"loc": {
187+
"end": {
188+
"column": 14,
189+
"line": 1
190+
},
191+
"start": {
192+
"column": 8,
193+
"line": 1
194+
}
195+
},
196+
"range": [
197+
8,
198+
14
199+
],
200+
"type": "Identifier",
201+
"value": "module"
202+
},
203+
{
204+
"loc": {
205+
"end": {
206+
"column": 29,
207+
"line": 1
208+
},
209+
"start": {
210+
"column": 15,
211+
"line": 1
212+
}
213+
},
214+
"range": [
215+
15,
216+
29
217+
],
218+
"type": "String",
219+
"value": "\"i-use-things\""
220+
},
221+
{
222+
"loc": {
223+
"end": {
224+
"column": 31,
225+
"line": 1
226+
},
227+
"start": {
228+
"column": 30,
229+
"line": 1
230+
}
231+
},
232+
"range": [
233+
30,
234+
31
235+
],
236+
"type": "Punctuator",
237+
"value": "{"
238+
},
239+
{
240+
"loc": {
241+
"end": {
242+
"column": 8,
243+
"line": 2
244+
},
245+
"start": {
246+
"column": 2,
247+
"line": 2
248+
}
249+
},
250+
"range": [
251+
34,
252+
40
253+
],
254+
"type": "Keyword",
255+
"value": "import"
256+
},
257+
{
258+
"loc": {
259+
"end": {
260+
"column": 11,
261+
"line": 2
262+
},
263+
"start": {
264+
"column": 9,
265+
"line": 2
266+
}
267+
},
268+
"range": [
269+
41,
270+
43
271+
],
272+
"type": "Identifier",
273+
"value": "fs"
274+
},
275+
{
276+
"loc": {
277+
"end": {
278+
"column": 16,
279+
"line": 2
280+
},
281+
"start": {
282+
"column": 12,
283+
"line": 2
284+
}
285+
},
286+
"range": [
287+
44,
288+
48
289+
],
290+
"type": "Identifier",
291+
"value": "from"
292+
},
293+
{
294+
"loc": {
295+
"end": {
296+
"column": 21,
297+
"line": 2
298+
},
299+
"start": {
300+
"column": 17,
301+
"line": 2
302+
}
303+
},
304+
"range": [
305+
49,
306+
53
307+
],
308+
"type": "String",
309+
"value": "'fs'"
310+
},
311+
{
312+
"loc": {
313+
"end": {
314+
"column": 22,
315+
"line": 2
316+
},
317+
"start": {
318+
"column": 21,
319+
"line": 2
320+
}
321+
},
322+
"range": [
323+
53,
324+
54
325+
],
326+
"type": "Punctuator",
327+
"value": ";"
328+
},
329+
{
330+
"loc": {
331+
"end": {
332+
"column": 1,
333+
"line": 3
334+
},
335+
"start": {
336+
"column": 0,
337+
"line": 3
338+
}
339+
},
340+
"range": [
341+
55,
342+
56
343+
],
344+
"type": "Punctuator",
345+
"value": "}"
346+
}
347+
],
348+
"type": "Program"
349+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "i-use-things" {
2+
import fs from 'fs';
3+
}

tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.result.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = {
8484
"column": 1
8585
}
8686
},
87-
"statements": [
87+
"body": [
8888
{
8989
"type": "TSNamespaceExportDeclaration",
9090
"declaration": {
@@ -617,4 +617,4 @@ module.exports = {
617617
}
618618
}
619619
]
620-
};
620+
};

0 commit comments

Comments
 (0)