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

Commit 3f9f41c

Browse files
despairbluesoda0289
authored andcommitted
Fix: wrap interface in ExportNamedDeclaration if necessary (fixes #269) (#270)
1 parent 69edd79 commit 3f9f41c

16 files changed

+452
-226
lines changed

lib/convert.js

+6
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@ module.exports = function convert(config) {
17031703
}
17041704

17051705
const hasImplementsClause = interfaceHeritageClauses.length > 0;
1706+
const hasAbstractKeyword = nodeUtils.hasModifier(SyntaxKind.AbstractKeyword, node);
17061707
const interfaceOpenBrace = nodeUtils.findNextToken(interfaceLastClassToken, ast);
17071708

17081709
const interfaceBody = {
@@ -1713,11 +1714,16 @@ module.exports = function convert(config) {
17131714
};
17141715

17151716
Object.assign(result, {
1717+
abstract: hasAbstractKeyword,
17161718
type: AST_NODE_TYPES.TSInterfaceDeclaration,
17171719
body: interfaceBody,
17181720
id: convertChild(node.name),
17191721
heritage: hasImplementsClause ? interfaceHeritageClauses[0].types.map(convertInterfaceHeritageClause) : []
17201722
});
1723+
1724+
// check for exports
1725+
result = nodeUtils.fixExports(node, result, ast);
1726+
17211727
break;
17221728

17231729
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
31
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 2,
14+
"column": 1
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExportNamedDeclaration",
20+
"declaration": {
21+
"type": "TSInterfaceDeclaration",
22+
"range": [
23+
16,
24+
31
25+
],
26+
"loc": {
27+
"start": {
28+
"line": 1,
29+
"column": 16
30+
},
31+
"end": {
32+
"line": 2,
33+
"column": 1
34+
}
35+
},
36+
"abstract": true,
37+
"body": {
38+
"type": "TSInterfaceBody",
39+
"body": [],
40+
"range": [
41+
28,
42+
31
43+
],
44+
"loc": {
45+
"start": {
46+
"line": 1,
47+
"column": 28
48+
},
49+
"end": {
50+
"line": 2,
51+
"column": 1
52+
}
53+
}
54+
},
55+
"id": {
56+
"type": "Identifier",
57+
"range": [
58+
26,
59+
27
60+
],
61+
"loc": {
62+
"start": {
63+
"line": 1,
64+
"column": 26
65+
},
66+
"end": {
67+
"line": 1,
68+
"column": 27
69+
}
70+
},
71+
"name": "I"
72+
},
73+
"heritage": []
74+
},
75+
"range": [
76+
0,
77+
31
78+
],
79+
"loc": {
80+
"start": {
81+
"line": 1,
82+
"column": 0
83+
},
84+
"end": {
85+
"line": 2,
86+
"column": 1
87+
}
88+
},
89+
"specifiers": [],
90+
"source": null
91+
}
92+
],
93+
"sourceType": "module",
94+
"tokens": [
95+
{
96+
"type": "Keyword",
97+
"value": "export",
98+
"range": [
99+
0,
100+
6
101+
],
102+
"loc": {
103+
"start": {
104+
"line": 1,
105+
"column": 0
106+
},
107+
"end": {
108+
"line": 1,
109+
"column": 6
110+
}
111+
}
112+
},
113+
{
114+
"type": "Identifier",
115+
"value": "abstract",
116+
"range": [
117+
7,
118+
15
119+
],
120+
"loc": {
121+
"start": {
122+
"line": 1,
123+
"column": 7
124+
},
125+
"end": {
126+
"line": 1,
127+
"column": 15
128+
}
129+
}
130+
},
131+
{
132+
"type": "Keyword",
133+
"value": "interface",
134+
"range": [
135+
16,
136+
25
137+
],
138+
"loc": {
139+
"start": {
140+
"line": 1,
141+
"column": 16
142+
},
143+
"end": {
144+
"line": 1,
145+
"column": 25
146+
}
147+
}
148+
},
149+
{
150+
"type": "Identifier",
151+
"value": "I",
152+
"range": [
153+
26,
154+
27
155+
],
156+
"loc": {
157+
"start": {
158+
"line": 1,
159+
"column": 26
160+
},
161+
"end": {
162+
"line": 1,
163+
"column": 27
164+
}
165+
}
166+
},
167+
{
168+
"type": "Punctuator",
169+
"value": "{",
170+
"range": [
171+
28,
172+
29
173+
],
174+
"loc": {
175+
"start": {
176+
"line": 1,
177+
"column": 28
178+
},
179+
"end": {
180+
"line": 1,
181+
"column": 29
182+
}
183+
}
184+
},
185+
{
186+
"type": "Punctuator",
187+
"value": "}",
188+
"range": [
189+
30,
190+
31
191+
],
192+
"loc": {
193+
"start": {
194+
"line": 2,
195+
"column": 0
196+
},
197+
"end": {
198+
"line": 2,
199+
"column": 1
200+
}
201+
}
202+
}
203+
]
204+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export abstract interface I {
2+
}

tests/fixtures/typescript/basics/class-with-mixin.result.js

+41-41
Original file line numberDiff line numberDiff line change
@@ -301,59 +301,59 @@ module.exports = {
301301
"name": "Constructor"
302302
},
303303
"typeParameters": {
304+
"type": "TypeParameterInstantiation",
305+
"range": [
306+
32,
307+
36
308+
],
304309
"loc": {
305-
"end": {
306-
"column": 36,
307-
"line": 1
308-
},
309310
"start": {
310-
"column": 32,
311-
"line": 1
311+
"line": 1,
312+
"column": 32
313+
},
314+
"end": {
315+
"line": 1,
316+
"column": 36
312317
}
313318
},
314319
"params": [
315320
{
316-
"id": {
317-
"loc": {
318-
"end": {
319-
"column": 35,
320-
"line": 1
321-
},
322-
"start": {
323-
"column": 33,
324-
"line": 1
325-
}
321+
"type": "GenericTypeAnnotation",
322+
"range": [
323+
33,
324+
35
325+
],
326+
"loc": {
327+
"start": {
328+
"line": 1,
329+
"column": 33
326330
},
327-
"members": [],
331+
"end": {
332+
"line": 1,
333+
"column": 35
334+
}
335+
},
336+
"id": {
337+
"type": "TSTypeLiteral",
328338
"range": [
329339
33,
330340
35
331341
],
332-
"type": "TSTypeLiteral"
333-
},
334-
"loc": {
335-
"end": {
336-
"column": 35,
337-
"line": 1
342+
"loc": {
343+
"start": {
344+
"line": 1,
345+
"column": 33
346+
},
347+
"end": {
348+
"line": 1,
349+
"column": 35
350+
}
338351
},
339-
"start": {
340-
"column": 33,
341-
"line": 1
342-
}
352+
"members": []
343353
},
344-
"range": [
345-
33,
346-
35
347-
],
348-
"type": "GenericTypeAnnotation",
349354
"typeParameters": null
350355
}
351-
],
352-
"range": [
353-
32,
354-
36
355-
],
356-
"type": "TypeParameterInstantiation"
356+
]
357357
}
358358
}
359359
}
@@ -633,6 +633,7 @@ module.exports = {
633633
"column": 15
634634
}
635635
},
636+
"abstract": false,
636637
"body": {
637638
"type": "TSInterfaceBody",
638639
"body": [],
@@ -691,7 +692,6 @@ module.exports = {
691692
"declarations": [
692693
{
693694
"type": "VariableDeclarator",
694-
"typeParameters": null,
695695
"id": {
696696
"type": "Identifier",
697697
"range": [
@@ -726,6 +726,7 @@ module.exports = {
726726
"column": 47
727727
}
728728
},
729+
"typeParameters": null,
729730
"parameters": [
730731
{
731732
"type": "RestElement",
@@ -814,7 +815,6 @@ module.exports = {
814815
}
815816
}
816817
],
817-
"typeParameters": null,
818818
"typeAnnotation": {
819819
"type": "TypeAnnotation",
820820
"loc": {
@@ -2079,4 +2079,4 @@ module.exports = {
20792079
}
20802080
}
20812081
]
2082-
};
2082+
};

tests/fixtures/typescript/basics/interface-extends-multiple.result.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
"column": 1
3232
}
3333
},
34+
"abstract": false,
3435
"body": {
3536
"type": "TSInterfaceBody",
3637
"body": [],
@@ -288,4 +289,4 @@ module.exports = {
288289
}
289290
}
290291
]
291-
};
292+
};

0 commit comments

Comments
 (0)