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

Commit 713a5cc

Browse files
committed
fix: wrap interface in ExportNamedDeclaration if necessary (fixes #269
1 parent f5fcc87 commit 713a5cc

File tree

3 files changed

+206
-2
lines changed

3 files changed

+206
-2
lines changed

lib/convert.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,7 @@ module.exports = function convert(config) {
16901690

16911691
case SyntaxKind.InterfaceDeclaration: {
16921692
const interfaceHeritageClauses = node.heritageClauses || [];
1693+
const modifiers = node.modifiers || [];
16931694

16941695
let interfaceLastClassToken = interfaceHeritageClauses.length ? interfaceHeritageClauses[interfaceHeritageClauses.length - 1] : node.name;
16951696

@@ -1704,6 +1705,7 @@ module.exports = function convert(config) {
17041705

17051706
const hasImplementsClause = interfaceHeritageClauses.length > 0;
17061707
const interfaceOpenBrace = nodeUtils.findNextToken(interfaceLastClassToken, ast);
1708+
const hasExportKeyword = modifiers.some(m => m.kind === SyntaxKind.ExportKeyword);
17071709

17081710
const interfaceBody = {
17091711
type: AST_NODE_TYPES.TSInterfaceBody,
@@ -1712,12 +1714,23 @@ module.exports = function convert(config) {
17121714
loc: nodeUtils.getLocFor(interfaceOpenBrace.getStart(), node.end, ast)
17131715
};
17141716

1715-
Object.assign(result, {
1717+
const tsInterfaceDeclaration = {
17161718
type: AST_NODE_TYPES.TSInterfaceDeclaration,
17171719
body: interfaceBody,
17181720
id: convertChild(node.name),
17191721
heritage: hasImplementsClause ? interfaceHeritageClauses[0].types.map(convertInterfaceHeritageClause) : []
1720-
});
1722+
};
1723+
1724+
if (hasExportKeyword) {
1725+
Object.assign(result, {
1726+
declaration: tsInterfaceDeclaration,
1727+
exportKind: "value",
1728+
specifiers: [],
1729+
type: AST_NODE_TYPES.ExportNamedDeclaration
1730+
});
1731+
} else {
1732+
Object.assign(result, tsInterfaceDeclaration);
1733+
}
17211734
break;
17221735

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

0 commit comments

Comments
 (0)