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

Commit 54854b2

Browse files
committed
New: Support primitive types in type arguments
1 parent af92891 commit 54854b2

File tree

3 files changed

+239
-5
lines changed

3 files changed

+239
-5
lines changed

lib/ast-converter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ module.exports = function(ast, extra) {
546546
typeArgument.end
547547
],
548548
loc: getLocFor(typeArgumentStart, typeArgument.end, ast),
549-
id: convertChild(typeArgument.typeName)
549+
id: convertChild(typeArgument.typeName || typeArgument)
550550
};
551551
})
552552
};
@@ -1805,6 +1805,7 @@ module.exports = function(ast, extra) {
18051805
arguments: node.arguments.map(convertChild)
18061806
});
18071807
if (node.typeArguments && node.typeArguments.length) {
1808+
// console.log(node.typeArguments);
18081809
result.typeParameters = convertTypeArgumentsToTypeParameters(node.typeArguments);
18091810
}
18101811
break;

tests/fixtures/typescript/expressions/call-expression-type-arguments.result.js

+235-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module.exports = {
22
"type": "Program",
33
"range": [
44
0,
5-
9
5+
24
66
],
77
"loc": {
88
"start": {
99
"line": 1,
1010
"column": 0
1111
},
1212
"end": {
13-
"line": 1,
14-
"column": 9
13+
"line": 2,
14+
"column": 14
1515
}
1616
},
1717
"body": [
@@ -121,6 +121,112 @@ module.exports = {
121121
9
122122
],
123123
"type": "ExpressionStatement"
124+
},
125+
{
126+
"expression": {
127+
"arguments": [],
128+
"callee": {
129+
"loc": {
130+
"end": {
131+
"column": 3,
132+
"line": 2
133+
},
134+
"start": {
135+
"column": 0,
136+
"line": 2
137+
}
138+
},
139+
"name": "foo",
140+
"range": [
141+
10,
142+
13
143+
],
144+
"type": "Identifier"
145+
},
146+
"loc": {
147+
"end": {
148+
"column": 13,
149+
"line": 2
150+
},
151+
"start": {
152+
"column": 0,
153+
"line": 2
154+
}
155+
},
156+
"range": [
157+
10,
158+
23
159+
],
160+
"type": "CallExpression",
161+
"typeParameters": {
162+
"loc": {
163+
"end": {
164+
"column": 11,
165+
"line": 2
166+
},
167+
"start": {
168+
"column": 3,
169+
"line": 2
170+
}
171+
},
172+
"params": [
173+
{
174+
"id": {
175+
"loc": {
176+
"end": {
177+
"column": 10,
178+
"line": 2
179+
},
180+
"start": {
181+
"column": 4,
182+
"line": 2
183+
}
184+
},
185+
"range": [
186+
14,
187+
20
188+
],
189+
"type": "TSNumberKeyword"
190+
},
191+
"loc": {
192+
"end": {
193+
"column": 10,
194+
"line": 2
195+
},
196+
"start": {
197+
"column": 4,
198+
"line": 2
199+
}
200+
},
201+
"range": [
202+
14,
203+
20
204+
],
205+
"type": "GenericTypeAnnotation"
206+
}
207+
],
208+
"range": [
209+
13,
210+
21
211+
],
212+
"type": "TypeParameterInstantiation"
213+
}
214+
},
215+
"loc": {
216+
"end": {
217+
"column": 14,
218+
"line": 2
219+
},
220+
"start": {
221+
"column": 0,
222+
"line": 2
223+
}
224+
},
225+
"range": [
226+
10,
227+
24
228+
],
229+
"type": "ExpressionStatement"
124230
}
125231
],
126232
"sourceType": "script",
@@ -250,6 +356,132 @@ module.exports = {
250356
],
251357
"type": "Punctuator",
252358
"value": ";"
359+
},
360+
{
361+
"loc": {
362+
"end": {
363+
"column": 3,
364+
"line": 2
365+
},
366+
"start": {
367+
"column": 0,
368+
"line": 2
369+
}
370+
},
371+
"range": [
372+
10,
373+
13
374+
],
375+
"type": "Identifier",
376+
"value": "foo"
377+
},
378+
{
379+
"loc": {
380+
"end": {
381+
"column": 4,
382+
"line": 2
383+
},
384+
"start": {
385+
"column": 3,
386+
"line": 2
387+
}
388+
},
389+
"range": [
390+
13,
391+
14
392+
],
393+
"type": "Punctuator",
394+
"value": "<"
395+
},
396+
{
397+
"loc": {
398+
"end": {
399+
"column": 10,
400+
"line": 2
401+
},
402+
"start": {
403+
"column": 4,
404+
"line": 2
405+
}
406+
},
407+
"range": [
408+
14,
409+
20
410+
],
411+
"type": "Identifier",
412+
"value": "number"
413+
},
414+
{
415+
"loc": {
416+
"end": {
417+
"column": 11,
418+
"line": 2
419+
},
420+
"start": {
421+
"column": 10,
422+
"line": 2
423+
}
424+
},
425+
"range": [
426+
20,
427+
21
428+
],
429+
"type": "Punctuator",
430+
"value": ">"
431+
},
432+
{
433+
"loc": {
434+
"end": {
435+
"column": 12,
436+
"line": 2
437+
},
438+
"start": {
439+
"column": 11,
440+
"line": 2
441+
}
442+
},
443+
"range": [
444+
21,
445+
22
446+
],
447+
"type": "Punctuator",
448+
"value": "("
449+
},
450+
{
451+
"loc": {
452+
"end": {
453+
"column": 13,
454+
"line": 2
455+
},
456+
"start": {
457+
"column": 12,
458+
"line": 2
459+
}
460+
},
461+
"range": [
462+
22,
463+
23
464+
],
465+
"type": "Punctuator",
466+
"value": ")"
467+
},
468+
{
469+
"loc": {
470+
"end": {
471+
"column": 14,
472+
"line": 2
473+
},
474+
"start": {
475+
"column": 13,
476+
"line": 2
477+
}
478+
},
479+
"range": [
480+
23,
481+
24
482+
],
483+
"type": "Punctuator",
484+
"value": ";"
253485
}
254486
]
255487
};
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
foo<A>();
1+
foo<A>();
2+
foo<number>();

0 commit comments

Comments
 (0)