Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d64ef1f

Browse files
committedApr 30, 2017
Fix: Support superTypeParameters (fixes #242)
1 parent 65c2e0a commit d64ef1f

7 files changed

+3012
-0
lines changed
 

‎lib/ast-converter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,9 @@ module.exports = function(ast, extra) {
15501550

15511551
if (hasExtends) {
15521552
superClass = heritageClauses.shift();
1553+
if (superClass.types[0] && superClass.types[0].typeArguments) {
1554+
result.superTypeParameters = convertTypeArgumentsToTypeParameters(superClass.types[0].typeArguments);
1555+
}
15531556
}
15541557

15551558
hasImplements = heritageClauses.length > 0;

‎tests/fixtures/typescript/basics/class-with-extends-generic-multiple.result.js

Lines changed: 563 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo<A extends B> extends Bar<C, D> {
2+
3+
}
Lines changed: 404 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,404 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
32
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": "ClassDeclaration",
20+
"range": [
21+
0,
22+
32
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 1
32+
}
33+
},
34+
"typeParameters": {
35+
"type": "TypeParameterDeclaration",
36+
"range": [
37+
9,
38+
12
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 9
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 12
48+
}
49+
},
50+
"params": [
51+
{
52+
"type": "TypeParameter",
53+
"range": [
54+
10,
55+
11
56+
],
57+
"loc": {
58+
"start": {
59+
"line": 1,
60+
"column": 10
61+
},
62+
"end": {
63+
"line": 1,
64+
"column": 11
65+
}
66+
},
67+
"name": "A",
68+
"constraint": null
69+
}
70+
]
71+
},
72+
"superTypeParameters": {
73+
"type": "TypeParameterInstantiation",
74+
"range": [
75+
24,
76+
27
77+
],
78+
"loc": {
79+
"start": {
80+
"line": 1,
81+
"column": 24
82+
},
83+
"end": {
84+
"line": 1,
85+
"column": 27
86+
}
87+
},
88+
"params": [
89+
{
90+
"type": "GenericTypeAnnotation",
91+
"range": [
92+
25,
93+
26
94+
],
95+
"loc": {
96+
"start": {
97+
"line": 1,
98+
"column": 25
99+
},
100+
"end": {
101+
"line": 1,
102+
"column": 26
103+
}
104+
},
105+
"id": {
106+
"type": "Identifier",
107+
"range": [
108+
25,
109+
26
110+
],
111+
"loc": {
112+
"start": {
113+
"line": 1,
114+
"column": 25
115+
},
116+
"end": {
117+
"line": 1,
118+
"column": 26
119+
}
120+
},
121+
"name": "B"
122+
},
123+
"typeParameters": null
124+
}
125+
]
126+
},
127+
"id": {
128+
"type": "Identifier",
129+
"range": [
130+
6,
131+
9
132+
],
133+
"loc": {
134+
"start": {
135+
"line": 1,
136+
"column": 6
137+
},
138+
"end": {
139+
"line": 1,
140+
"column": 9
141+
}
142+
},
143+
"name": "Foo"
144+
},
145+
"body": {
146+
"type": "ClassBody",
147+
"body": [],
148+
"range": [
149+
28,
150+
32
151+
],
152+
"loc": {
153+
"start": {
154+
"line": 1,
155+
"column": 28
156+
},
157+
"end": {
158+
"line": 3,
159+
"column": 1
160+
}
161+
}
162+
},
163+
"superClass": {
164+
"type": "Identifier",
165+
"range": [
166+
21,
167+
24
168+
],
169+
"loc": {
170+
"start": {
171+
"line": 1,
172+
"column": 21
173+
},
174+
"end": {
175+
"line": 1,
176+
"column": 24
177+
}
178+
},
179+
"name": "Bar"
180+
},
181+
"implements": [],
182+
"decorators": []
183+
}
184+
],
185+
"sourceType": "script",
186+
"tokens": [
187+
{
188+
"type": "Keyword",
189+
"value": "class",
190+
"range": [
191+
0,
192+
5
193+
],
194+
"loc": {
195+
"start": {
196+
"line": 1,
197+
"column": 0
198+
},
199+
"end": {
200+
"line": 1,
201+
"column": 5
202+
}
203+
}
204+
},
205+
{
206+
"type": "Identifier",
207+
"value": "Foo",
208+
"range": [
209+
6,
210+
9
211+
],
212+
"loc": {
213+
"start": {
214+
"line": 1,
215+
"column": 6
216+
},
217+
"end": {
218+
"line": 1,
219+
"column": 9
220+
}
221+
}
222+
},
223+
{
224+
"type": "Punctuator",
225+
"value": "<",
226+
"range": [
227+
9,
228+
10
229+
],
230+
"loc": {
231+
"start": {
232+
"line": 1,
233+
"column": 9
234+
},
235+
"end": {
236+
"line": 1,
237+
"column": 10
238+
}
239+
}
240+
},
241+
{
242+
"type": "Identifier",
243+
"value": "A",
244+
"range": [
245+
10,
246+
11
247+
],
248+
"loc": {
249+
"start": {
250+
"line": 1,
251+
"column": 10
252+
},
253+
"end": {
254+
"line": 1,
255+
"column": 11
256+
}
257+
}
258+
},
259+
{
260+
"type": "Punctuator",
261+
"value": ">",
262+
"range": [
263+
11,
264+
12
265+
],
266+
"loc": {
267+
"start": {
268+
"line": 1,
269+
"column": 11
270+
},
271+
"end": {
272+
"line": 1,
273+
"column": 12
274+
}
275+
}
276+
},
277+
{
278+
"type": "Keyword",
279+
"value": "extends",
280+
"range": [
281+
13,
282+
20
283+
],
284+
"loc": {
285+
"start": {
286+
"line": 1,
287+
"column": 13
288+
},
289+
"end": {
290+
"line": 1,
291+
"column": 20
292+
}
293+
}
294+
},
295+
{
296+
"type": "Identifier",
297+
"value": "Bar",
298+
"range": [
299+
21,
300+
24
301+
],
302+
"loc": {
303+
"start": {
304+
"line": 1,
305+
"column": 21
306+
},
307+
"end": {
308+
"line": 1,
309+
"column": 24
310+
}
311+
}
312+
},
313+
{
314+
"type": "Punctuator",
315+
"value": "<",
316+
"range": [
317+
24,
318+
25
319+
],
320+
"loc": {
321+
"start": {
322+
"line": 1,
323+
"column": 24
324+
},
325+
"end": {
326+
"line": 1,
327+
"column": 25
328+
}
329+
}
330+
},
331+
{
332+
"type": "Identifier",
333+
"value": "B",
334+
"range": [
335+
25,
336+
26
337+
],
338+
"loc": {
339+
"start": {
340+
"line": 1,
341+
"column": 25
342+
},
343+
"end": {
344+
"line": 1,
345+
"column": 26
346+
}
347+
}
348+
},
349+
{
350+
"type": "Punctuator",
351+
"value": ">",
352+
"range": [
353+
26,
354+
27
355+
],
356+
"loc": {
357+
"start": {
358+
"line": 1,
359+
"column": 26
360+
},
361+
"end": {
362+
"line": 1,
363+
"column": 27
364+
}
365+
}
366+
},
367+
{
368+
"type": "Punctuator",
369+
"value": "{",
370+
"range": [
371+
28,
372+
29
373+
],
374+
"loc": {
375+
"start": {
376+
"line": 1,
377+
"column": 28
378+
},
379+
"end": {
380+
"line": 1,
381+
"column": 29
382+
}
383+
}
384+
},
385+
{
386+
"type": "Punctuator",
387+
"value": "}",
388+
"range": [
389+
31,
390+
32
391+
],
392+
"loc": {
393+
"start": {
394+
"line": 3,
395+
"column": 0
396+
},
397+
"end": {
398+
"line": 3,
399+
"column": 1
400+
}
401+
}
402+
}
403+
]
404+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo<A> extends Bar<B> {
2+
3+
}

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

Lines changed: 2027 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function M<T extends Constructor<{}>>(Base: T) {
2+
return class extends Base { }
3+
}
4+
5+
class X extends M<any>(C) implements I { }
6+
7+
class C { }
8+
interface I { }
9+
type Constructor<T> = new (...args: any[]) => T;

0 commit comments

Comments
 (0)
This repository has been archived.