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

Commit e96ba1f

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Calculate range correctly for exported generic class (fixes #152) (#155)
1 parent 11d5a7d commit e96ba1f

9 files changed

+1017
-0
lines changed

lib/ast-converter.js

+7
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,13 @@ module.exports = function(ast, extra) {
14651465
var lastClassToken = heritageClauses.length ? heritageClauses[heritageClauses.length - 1] : node.name;
14661466
var classNodeType = SyntaxKind[node.kind];
14671467

1468+
if (node.typeParameters && node.typeParameters.length) {
1469+
var lastTypeParameter = node.typeParameters[node.typeParameters.length - 1];
1470+
if (!lastClassToken || lastTypeParameter.pos > lastClassToken.pos) {
1471+
lastClassToken = ts.findNextToken(lastTypeParameter, ast);
1472+
}
1473+
}
1474+
14681475
if (node.modifiers && node.modifiers.length) {
14691476

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

0 commit comments

Comments
 (0)