@@ -452,6 +452,42 @@ module.exports = function(ast, extra) {
452
452
} ;
453
453
}
454
454
455
+ /**
456
+ * Converts a TSNode's typeArguments array to a flow-like typeParameters node
457
+ * @param {Array } typeArguments TSNode typeArguments
458
+ * @returns {TypeParameterInstantiation } TypeParameterInstantiation node
459
+ */
460
+ function convertTypeArgumentsToTypeParameters ( typeArguments ) {
461
+ var firstTypeArgument = typeArguments [ 0 ] ;
462
+ var lastTypeArgument = typeArguments [ typeArguments . length - 1 ] ;
463
+ return {
464
+ type : "TypeParameterInstantiation" ,
465
+ range : [
466
+ firstTypeArgument . pos - 1 ,
467
+ lastTypeArgument . end + 1
468
+ ] ,
469
+ loc : getLocFor ( firstTypeArgument . pos - 1 , lastTypeArgument . end + 1 , ast ) ,
470
+ params : typeArguments . map ( function ( typeArgument ) {
471
+ /**
472
+ * Have to manually calculate the start of the range,
473
+ * because TypeScript includes leading whitespace but Flow does not
474
+ */
475
+ var typeArgumentStart = ( typeArgument . typeName && typeArgument . typeName . text )
476
+ ? typeArgument . end - typeArgument . typeName . text . length
477
+ : typeArgument . pos ;
478
+ return {
479
+ type : "GenericTypeAnnotation" ,
480
+ range : [
481
+ typeArgumentStart ,
482
+ typeArgument . end
483
+ ] ,
484
+ loc : getLocFor ( typeArgumentStart , typeArgument . end , ast ) ,
485
+ id : convertChild ( typeArgument . typeName )
486
+ } ;
487
+ } )
488
+ } ;
489
+ }
490
+
455
491
/**
456
492
* Converts a child into a class implements node. This creates an intermediary
457
493
* ClassImplements node to match what Flow does.
@@ -460,12 +496,16 @@ module.exports = function(ast, extra) {
460
496
*/
461
497
function convertClassImplements ( child ) {
462
498
var id = convertChild ( child . expression ) ;
463
- return {
499
+ var classImplementsNode = {
464
500
type : "ClassImplements" ,
465
501
loc : id . loc ,
466
502
range : id . range ,
467
503
id : id
468
504
} ;
505
+ if ( child . typeArguments && child . typeArguments . length ) {
506
+ classImplementsNode . typeParameters = convertTypeArgumentsToTypeParameters ( child . typeArguments ) ;
507
+ }
508
+ return classImplementsNode ;
469
509
}
470
510
471
511
/**
0 commit comments