flow-api-translator 0.20.1 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,11 @@ import {EOL} from 'os';
30
30
 
31
31
  type DeclarationOrUnsupported<T> = T | TSESTree.TSTypeAliasDeclaration;
32
32
 
33
+ const DUMMY_LOC: FlowESTree.SourceLocation = {
34
+ start: {line: 1, column: 0},
35
+ end: {line: 1, column: 0},
36
+ };
37
+
33
38
  function constructFlowNode<T: FlowESTree.BaseNode>(
34
39
  node: $Diff<T, FlowESTree.BaseNode>,
35
40
  ): T {
@@ -62,6 +67,7 @@ function getReactIdentifier(hasReactImport: boolean) {
62
67
 
63
68
  return {
64
69
  type: 'Identifier',
70
+ loc: DUMMY_LOC,
65
71
  name: `React`,
66
72
  };
67
73
  }
@@ -77,6 +83,7 @@ export function flowDefToTSDef(
77
83
  type: 'Program',
78
84
  body: tsBody,
79
85
  sourceType: ast.sourceType,
86
+ loc: ast.loc,
80
87
  docblock:
81
88
  ast.docblock == null ? null : removeAtFlowFromDocblock(ast.docblock),
82
89
  };
@@ -110,16 +117,20 @@ export function flowDefToTSDef(
110
117
  tsBody.unshift({
111
118
  type: 'ImportDeclaration',
112
119
  assertions: [],
120
+ loc: DUMMY_LOC,
113
121
  source: {
114
122
  type: 'Literal',
123
+ loc: DUMMY_LOC,
115
124
  value: 'react',
116
125
  raw: "'react'",
117
126
  },
118
127
  specifiers: [
119
128
  {
120
129
  type: 'ImportNamespaceSpecifier',
130
+ loc: DUMMY_LOC,
121
131
  local: {
122
132
  type: 'Identifier',
133
+ loc: DUMMY_LOC,
123
134
  name: 'React',
124
135
  },
125
136
  },
@@ -150,8 +161,9 @@ const getTransforms = (
150
161
  return buildCodeFrame(node, message, code, false);
151
162
  }
152
163
  function addErrorComment(node: TSESTree.Node, message: string): void {
153
- const comment = {
164
+ const comment: TSESTree.Comment = {
154
165
  type: 'Block',
166
+ loc: DUMMY_LOC,
155
167
  value: `*${EOL} * ${message.replace(
156
168
  new RegExp(EOL, 'g'),
157
169
  `${EOL} * `,
@@ -165,7 +177,6 @@ const getTransforms = (
165
177
  // $FlowExpectedError[prop-missing]
166
178
  // $FlowExpectedError[cannot-write]
167
179
  node.comments ??= [];
168
- // $FlowExpectedError[prop-missing]
169
180
  // $FlowExpectedError[incompatible-cast]
170
181
  (node.comments: Array<TSESTree.Comment>).push(comment);
171
182
  }
@@ -176,8 +187,9 @@ const getTransforms = (
176
187
  const message = unsupportedFeatureMessage(thing);
177
188
  if (opts.recoverFromErrors) {
178
189
  const codeFrame = buildCodeFrameForComment(node, message);
179
- const newNode = {
190
+ const newNode: TSESTree.TSAnyKeyword = {
180
191
  type: 'TSAnyKeyword',
192
+ loc: DUMMY_LOC,
181
193
  };
182
194
  addErrorComment(newNode, codeFrame);
183
195
  return newNode;
@@ -195,12 +207,14 @@ const getTransforms = (
195
207
  const message = unsupportedFeatureMessage(thing);
196
208
  if (opts.recoverFromErrors) {
197
209
  const codeFrame = buildCodeFrameForComment(node, message);
198
- const newNode = {
210
+ const newNode: TSESTree.TSTypeAliasDeclaration = {
199
211
  type: 'TSTypeAliasDeclaration',
212
+ loc: DUMMY_LOC,
200
213
  declare,
201
214
  id: transform.Identifier(id, false),
202
215
  typeAnnotation: {
203
216
  type: 'TSAnyKeyword',
217
+ loc: DUMMY_LOC,
204
218
  },
205
219
  typeParameters:
206
220
  typeParameters == null
@@ -366,10 +380,12 @@ const getTransforms = (
366
380
  }
367
381
  members.push({
368
382
  type: 'TSEnumMember',
383
+ loc: DUMMY_LOC,
369
384
  computed: false,
370
385
  id: transform.Identifier(member.id, false),
371
386
  initializer: ({
372
387
  type: 'Literal',
388
+ loc: DUMMY_LOC,
373
389
  raw: `"${member.id.name}"`,
374
390
  value: member.id.name,
375
391
  }: TSESTree.StringLiteral),
@@ -381,6 +397,7 @@ const getTransforms = (
381
397
  case 'EnumStringMember':
382
398
  members.push({
383
399
  type: 'TSEnumMember',
400
+ loc: DUMMY_LOC,
384
401
  computed: false,
385
402
  id: transform.Identifier(member.id, false),
386
403
  initializer:
@@ -393,13 +410,14 @@ const getTransforms = (
393
410
 
394
411
  const bodyRepresentationType =
395
412
  body.type === 'EnumNumberBody'
396
- ? {type: 'TSNumberKeyword'}
397
- : {type: 'TSStringKeyword'};
413
+ ? {type: 'TSNumberKeyword', loc: DUMMY_LOC}
414
+ : {type: 'TSStringKeyword', loc: DUMMY_LOC};
398
415
 
399
416
  const enumName = transform.Identifier(node.id, false);
400
417
  return [
401
418
  {
402
419
  type: 'TSEnumDeclaration',
420
+ loc: DUMMY_LOC,
403
421
  const: false,
404
422
  declare: true,
405
423
  id: enumName,
@@ -421,18 +439,23 @@ const getTransforms = (
421
439
  */
422
440
  {
423
441
  type: 'TSModuleDeclaration',
442
+ loc: DUMMY_LOC,
424
443
  declare: true,
425
444
  id: enumName,
426
445
  body: {
427
446
  type: 'TSModuleBlock',
447
+ loc: DUMMY_LOC,
428
448
  body: [
429
449
  // export function cast(value: number | null | undefined): Foo
430
450
  {
431
451
  type: 'ExportNamedDeclaration',
452
+ loc: DUMMY_LOC,
432
453
  declaration: {
433
454
  type: 'TSDeclareFunction',
455
+ loc: DUMMY_LOC,
434
456
  id: {
435
457
  type: 'Identifier',
458
+ loc: DUMMY_LOC,
436
459
  name: 'cast',
437
460
  },
438
461
  generator: false,
@@ -441,18 +464,23 @@ const getTransforms = (
441
464
  params: [
442
465
  {
443
466
  type: 'Identifier',
467
+ loc: DUMMY_LOC,
444
468
  name: 'value',
445
469
  typeAnnotation: {
446
470
  type: 'TSTypeAnnotation',
471
+ loc: DUMMY_LOC,
447
472
  typeAnnotation: {
448
473
  type: 'TSUnionType',
474
+ loc: DUMMY_LOC,
449
475
  types: [
450
476
  bodyRepresentationType,
451
477
  {
452
478
  type: 'TSNullKeyword',
479
+ loc: DUMMY_LOC,
453
480
  },
454
481
  {
455
482
  type: 'TSUndefinedKeyword',
483
+ loc: DUMMY_LOC,
456
484
  },
457
485
  ],
458
486
  },
@@ -461,8 +489,10 @@ const getTransforms = (
461
489
  ],
462
490
  returnType: {
463
491
  type: 'TSTypeAnnotation',
492
+ loc: DUMMY_LOC,
464
493
  typeAnnotation: {
465
494
  type: 'TSTypeReference',
495
+ loc: DUMMY_LOC,
466
496
  typeName: enumName,
467
497
  },
468
498
  },
@@ -475,10 +505,13 @@ const getTransforms = (
475
505
  // export function isValid(value: number | null | undefined): value is Foo;
476
506
  {
477
507
  type: 'ExportNamedDeclaration',
508
+ loc: DUMMY_LOC,
478
509
  declaration: {
479
510
  type: 'TSDeclareFunction',
511
+ loc: DUMMY_LOC,
480
512
  id: {
481
513
  type: 'Identifier',
514
+ loc: DUMMY_LOC,
482
515
  name: 'isValid',
483
516
  },
484
517
  generator: false,
@@ -487,18 +520,23 @@ const getTransforms = (
487
520
  params: [
488
521
  {
489
522
  type: 'Identifier',
523
+ loc: DUMMY_LOC,
490
524
  name: 'value',
491
525
  typeAnnotation: {
492
526
  type: 'TSTypeAnnotation',
527
+ loc: DUMMY_LOC,
493
528
  typeAnnotation: {
494
529
  type: 'TSUnionType',
530
+ loc: DUMMY_LOC,
495
531
  types: [
496
532
  bodyRepresentationType,
497
533
  {
498
534
  type: 'TSNullKeyword',
535
+ loc: DUMMY_LOC,
499
536
  },
500
537
  {
501
538
  type: 'TSUndefinedKeyword',
539
+ loc: DUMMY_LOC,
502
540
  },
503
541
  ],
504
542
  },
@@ -507,17 +545,22 @@ const getTransforms = (
507
545
  ],
508
546
  returnType: {
509
547
  type: 'TSTypeAnnotation',
548
+ loc: DUMMY_LOC,
510
549
  typeAnnotation: {
511
550
  type: 'TSTypePredicate',
551
+ loc: DUMMY_LOC,
512
552
  asserts: false,
513
553
  parameterName: {
514
554
  type: 'Identifier',
555
+ loc: DUMMY_LOC,
515
556
  name: 'value',
516
557
  },
517
558
  typeAnnotation: {
518
559
  type: 'TSTypeAnnotation',
560
+ loc: DUMMY_LOC,
519
561
  typeAnnotation: {
520
562
  type: 'TSTypeReference',
563
+ loc: DUMMY_LOC,
521
564
  typeName: enumName,
522
565
  },
523
566
  },
@@ -532,10 +575,13 @@ const getTransforms = (
532
575
  // export function members(): IterableIterator<Foo>;
533
576
  {
534
577
  type: 'ExportNamedDeclaration',
578
+ loc: DUMMY_LOC,
535
579
  declaration: {
536
580
  type: 'TSDeclareFunction',
581
+ loc: DUMMY_LOC,
537
582
  id: {
538
583
  type: 'Identifier',
584
+ loc: DUMMY_LOC,
539
585
  name: 'members',
540
586
  },
541
587
  generator: false,
@@ -544,17 +590,22 @@ const getTransforms = (
544
590
  params: [],
545
591
  returnType: {
546
592
  type: 'TSTypeAnnotation',
593
+ loc: DUMMY_LOC,
547
594
  typeAnnotation: {
548
595
  type: 'TSTypeReference',
596
+ loc: DUMMY_LOC,
549
597
  typeName: {
550
598
  type: 'Identifier',
599
+ loc: DUMMY_LOC,
551
600
  name: 'IterableIterator',
552
601
  },
553
602
  typeParameters: {
554
603
  type: 'TSTypeParameterInstantiation',
604
+ loc: DUMMY_LOC,
555
605
  params: [
556
606
  {
557
607
  type: 'TSTypeReference',
608
+ loc: DUMMY_LOC,
558
609
  typeName: enumName,
559
610
  },
560
611
  ],
@@ -570,10 +621,13 @@ const getTransforms = (
570
621
  // export function getName(value: Foo): string;
571
622
  {
572
623
  type: 'ExportNamedDeclaration',
624
+ loc: DUMMY_LOC,
573
625
  declaration: {
574
626
  type: 'TSDeclareFunction',
627
+ loc: DUMMY_LOC,
575
628
  id: {
576
629
  type: 'Identifier',
630
+ loc: DUMMY_LOC,
577
631
  name: 'getName',
578
632
  },
579
633
  generator: false,
@@ -582,11 +636,14 @@ const getTransforms = (
582
636
  params: [
583
637
  {
584
638
  type: 'Identifier',
639
+ loc: DUMMY_LOC,
585
640
  name: 'value',
586
641
  typeAnnotation: {
587
642
  type: 'TSTypeAnnotation',
643
+ loc: DUMMY_LOC,
588
644
  typeAnnotation: {
589
645
  type: 'TSTypeReference',
646
+ loc: DUMMY_LOC,
590
647
  typeName: enumName,
591
648
  },
592
649
  },
@@ -594,8 +651,10 @@ const getTransforms = (
594
651
  ],
595
652
  returnType: {
596
653
  type: 'TSTypeAnnotation',
654
+ loc: DUMMY_LOC,
597
655
  typeAnnotation: {
598
656
  type: 'TSStringKeyword',
657
+ loc: DUMMY_LOC,
599
658
  },
600
659
  },
601
660
  },
@@ -700,6 +759,7 @@ const getTransforms = (
700
759
  ): TSESTree.TSAnyKeyword {
701
760
  return {
702
761
  type: 'TSAnyKeyword',
762
+ loc: DUMMY_LOC,
703
763
  };
704
764
  },
705
765
  ArrayTypeAnnotation(
@@ -707,12 +767,14 @@ const getTransforms = (
707
767
  ): TSESTree.TSArrayType {
708
768
  return {
709
769
  type: 'TSArrayType',
770
+ loc: DUMMY_LOC,
710
771
  elementType: transformTypeAnnotationType(node.elementType),
711
772
  };
712
773
  },
713
774
  BigIntLiteral(node: FlowESTree.BigIntLiteral): TSESTree.BigIntLiteral {
714
775
  return {
715
776
  type: 'Literal',
777
+ loc: DUMMY_LOC,
716
778
  bigint: node.bigint,
717
779
  raw: node.raw,
718
780
  value: node.value,
@@ -734,8 +796,10 @@ const getTransforms = (
734
796
  .replace(/_/, '');
735
797
  return {
736
798
  type: 'TSLiteralType',
799
+ loc: DUMMY_LOC,
737
800
  literal: ({
738
801
  type: 'Literal',
802
+ loc: DUMMY_LOC,
739
803
  value: node.value,
740
804
  raw: node.raw,
741
805
  bigint,
@@ -747,11 +811,13 @@ const getTransforms = (
747
811
  ): TSESTree.TSBigIntKeyword {
748
812
  return {
749
813
  type: 'TSBigIntKeyword',
814
+ loc: DUMMY_LOC,
750
815
  };
751
816
  },
752
817
  BooleanLiteral(node: FlowESTree.BooleanLiteral): TSESTree.BooleanLiteral {
753
818
  return {
754
819
  type: 'Literal',
820
+ loc: DUMMY_LOC,
755
821
  raw: node.raw,
756
822
  value: node.value,
757
823
  };
@@ -761,8 +827,10 @@ const getTransforms = (
761
827
  ): TSESTree.TSLiteralType {
762
828
  return {
763
829
  type: 'TSLiteralType',
830
+ loc: DUMMY_LOC,
764
831
  literal: ({
765
832
  type: 'Literal',
833
+ loc: DUMMY_LOC,
766
834
  value: node.value,
767
835
  raw: node.raw,
768
836
  }: TSESTree.BooleanLiteral),
@@ -773,6 +841,7 @@ const getTransforms = (
773
841
  ): TSESTree.TSBooleanKeyword {
774
842
  return {
775
843
  type: 'TSBooleanKeyword',
844
+ loc: DUMMY_LOC,
776
845
  };
777
846
  },
778
847
  ClassImplements(
@@ -780,6 +849,7 @@ const getTransforms = (
780
849
  ): TSESTree.TSClassImplements {
781
850
  return {
782
851
  type: 'TSClassImplements',
852
+ loc: DUMMY_LOC,
783
853
  expression: transform.Identifier(node.id, false),
784
854
  typeParameters:
785
855
  node.typeParameters == null
@@ -828,10 +898,12 @@ const getTransforms = (
828
898
  if (isConstructor) {
829
899
  const newNode: TSESTree.MethodDefinitionAmbiguous = {
830
900
  type: 'MethodDefinition',
901
+ loc: DUMMY_LOC,
831
902
  accessibility: undefined,
832
903
  computed: false,
833
904
  key: {
834
905
  type: 'Identifier',
906
+ loc: DUMMY_LOC,
835
907
  name: 'constructor',
836
908
  },
837
909
  kind: 'constructor',
@@ -840,6 +912,7 @@ const getTransforms = (
840
912
  static: false,
841
913
  value: {
842
914
  type: 'TSEmptyBodyFunctionExpression',
915
+ loc: DUMMY_LOC,
843
916
  async: false,
844
917
  body: null,
845
918
  declare: false,
@@ -857,6 +930,7 @@ const getTransforms = (
857
930
  } else {
858
931
  const newNode: TSESTree.MethodDefinitionAmbiguous = {
859
932
  type: 'MethodDefinition',
933
+ loc: DUMMY_LOC,
860
934
  accessibility: member.accessibility,
861
935
  computed: member.computed ?? false,
862
936
  key: member.key,
@@ -866,6 +940,7 @@ const getTransforms = (
866
940
  static: member.static ?? false,
867
941
  value: {
868
942
  type: 'TSEmptyBodyFunctionExpression',
943
+ loc: DUMMY_LOC,
869
944
  async: false,
870
945
  body: null,
871
946
  declare: false,
@@ -886,6 +961,7 @@ const getTransforms = (
886
961
  case 'TSPropertySignature': {
887
962
  const newNode: TSESTree.PropertyDefinitionAmbiguous = {
888
963
  type: 'PropertyDefinition',
964
+ loc: DUMMY_LOC,
889
965
  accessibility: member.accessibility,
890
966
  computed: member.computed ?? false,
891
967
  declare: false,
@@ -939,8 +1015,10 @@ const getTransforms = (
939
1015
 
940
1016
  return {
941
1017
  type: 'ClassDeclaration',
1018
+ loc: DUMMY_LOC,
942
1019
  body: {
943
1020
  type: 'ClassBody',
1021
+ loc: DUMMY_LOC,
944
1022
  body: classMembers,
945
1023
  },
946
1024
  declare: true,
@@ -952,7 +1030,8 @@ const getTransforms = (
952
1030
  superClass:
953
1031
  superClass == null
954
1032
  ? null
955
- : transform.Identifier(superClass.id, false),
1033
+ : // Bug: superclass.id can be qualified
1034
+ transform.Identifier((superClass.id: $FlowFixMe), false),
956
1035
  superTypeParameters:
957
1036
  superClass?.typeParameters == null
958
1037
  ? undefined
@@ -991,8 +1070,10 @@ const getTransforms = (
991
1070
  classDecl,
992
1071
  {
993
1072
  type: 'ExportDefaultDeclaration',
1073
+ loc: DUMMY_LOC,
994
1074
  declaration: {
995
1075
  type: 'Identifier',
1076
+ loc: DUMMY_LOC,
996
1077
  name,
997
1078
  },
998
1079
  exportKind: 'value',
@@ -1008,8 +1089,10 @@ const getTransforms = (
1008
1089
  functionDecl,
1009
1090
  {
1010
1091
  type: 'ExportDefaultDeclaration',
1092
+ loc: DUMMY_LOC,
1011
1093
  declaration: {
1012
1094
  type: 'Identifier',
1095
+ loc: DUMMY_LOC,
1013
1096
  name,
1014
1097
  },
1015
1098
  exportKind: 'value',
@@ -1025,8 +1108,10 @@ const getTransforms = (
1025
1108
  functionDecl,
1026
1109
  {
1027
1110
  type: 'ExportDefaultDeclaration',
1111
+ loc: DUMMY_LOC,
1028
1112
  declaration: {
1029
1113
  type: 'Identifier',
1114
+ loc: DUMMY_LOC,
1030
1115
  name,
1031
1116
  },
1032
1117
  exportKind: 'value',
@@ -1042,8 +1127,10 @@ const getTransforms = (
1042
1127
  functionDecl,
1043
1128
  {
1044
1129
  type: 'ExportDefaultDeclaration',
1130
+ loc: DUMMY_LOC,
1045
1131
  declaration: {
1046
1132
  type: 'Identifier',
1133
+ loc: DUMMY_LOC,
1047
1134
  name,
1048
1135
  },
1049
1136
  exportKind: 'value',
@@ -1090,8 +1177,10 @@ const getTransforms = (
1090
1177
  // there's already a variable defined to hold the type
1091
1178
  return {
1092
1179
  type: 'ExportDefaultDeclaration',
1180
+ loc: DUMMY_LOC,
1093
1181
  declaration: {
1094
1182
  type: 'Identifier',
1183
+ loc: DUMMY_LOC,
1095
1184
  name: referencedId.name,
1096
1185
  },
1097
1186
  exportKind: 'value',
@@ -1132,14 +1221,18 @@ const getTransforms = (
1132
1221
  return [
1133
1222
  {
1134
1223
  type: 'VariableDeclaration',
1224
+ loc: DUMMY_LOC,
1135
1225
  declarations: [
1136
1226
  {
1137
1227
  type: 'VariableDeclarator',
1228
+ loc: DUMMY_LOC,
1138
1229
  id: {
1139
1230
  type: 'Identifier',
1231
+ loc: DUMMY_LOC,
1140
1232
  name: SPECIFIER,
1141
1233
  typeAnnotation: {
1142
1234
  type: 'TSTypeAnnotation',
1235
+ loc: DUMMY_LOC,
1143
1236
  typeAnnotation:
1144
1237
  transformTypeAnnotationType(declaration),
1145
1238
  },
@@ -1152,8 +1245,10 @@ const getTransforms = (
1152
1245
  },
1153
1246
  {
1154
1247
  type: 'ExportDefaultDeclaration',
1248
+ loc: DUMMY_LOC,
1155
1249
  declaration: {
1156
1250
  type: 'Identifier',
1251
+ loc: DUMMY_LOC,
1157
1252
  name: SPECIFIER,
1158
1253
  },
1159
1254
  exportKind: 'value',
@@ -1168,6 +1263,7 @@ const getTransforms = (
1168
1263
  if (node.declaration === null) {
1169
1264
  return ({
1170
1265
  type: 'ExportNamedDeclaration',
1266
+ loc: DUMMY_LOC,
1171
1267
  // flow does not currently support assertions
1172
1268
  assertions: [],
1173
1269
  declaration: null,
@@ -1251,6 +1347,7 @@ const getTransforms = (
1251
1347
  ({declaration, exportKind}) =>
1252
1348
  ({
1253
1349
  type: 'ExportNamedDeclaration',
1350
+ loc: DUMMY_LOC,
1254
1351
  // flow does not currently support assertions
1255
1352
  assertions: [],
1256
1353
  declaration,
@@ -1262,6 +1359,7 @@ const getTransforms = (
1262
1359
  } else {
1263
1360
  return ({
1264
1361
  type: 'ExportNamedDeclaration',
1362
+ loc: DUMMY_LOC,
1265
1363
  // flow does not currently support assertions
1266
1364
  assertions: [],
1267
1365
  declaration: null,
@@ -1287,16 +1385,20 @@ const getTransforms = (
1287
1385
 
1288
1386
  // TS cannot support `renderType` so we always use ReactNode as the return type.
1289
1387
  const hasReactImport = isReactImport(node, 'React');
1290
- const returnType = {
1388
+ const returnType: TSESTree.TSTypeAnnotation = {
1291
1389
  type: 'TSTypeAnnotation',
1390
+ loc: DUMMY_LOC,
1292
1391
  // If no rendersType we assume its ReactNode type.
1293
1392
  typeAnnotation: {
1294
1393
  type: 'TSTypeReference',
1394
+ loc: DUMMY_LOC,
1295
1395
  typeName: {
1296
1396
  type: 'TSQualifiedName',
1397
+ loc: DUMMY_LOC,
1297
1398
  left: getReactIdentifier(hasReactImport),
1298
1399
  right: {
1299
1400
  type: 'Identifier',
1401
+ loc: DUMMY_LOC,
1300
1402
  name: `ReactNode`,
1301
1403
  },
1302
1404
  },
@@ -1306,6 +1408,7 @@ const getTransforms = (
1306
1408
 
1307
1409
  return {
1308
1410
  type: 'TSDeclareFunction',
1411
+ loc: DUMMY_LOC,
1309
1412
  async: false,
1310
1413
  body: undefined,
1311
1414
  declare: true,
@@ -1313,6 +1416,7 @@ const getTransforms = (
1313
1416
  generator: false,
1314
1417
  id: {
1315
1418
  type: 'Identifier',
1419
+ loc: DUMMY_LOC,
1316
1420
  name: id.name,
1317
1421
  },
1318
1422
  params,
@@ -1328,9 +1432,11 @@ const getTransforms = (
1328
1432
  return [
1329
1433
  {
1330
1434
  type: 'Identifier',
1435
+ loc: DUMMY_LOC,
1331
1436
  name: 'props',
1332
1437
  typeAnnotation: {
1333
1438
  type: 'TSTypeAnnotation',
1439
+ loc: DUMMY_LOC,
1334
1440
  typeAnnotation: transformTypeAnnotationType(rest.typeAnnotation),
1335
1441
  },
1336
1442
  optional: false,
@@ -1392,9 +1498,11 @@ const getTransforms = (
1392
1498
  return [
1393
1499
  {
1394
1500
  type: 'Identifier',
1501
+ loc: DUMMY_LOC,
1395
1502
  name: 'props',
1396
1503
  typeAnnotation: {
1397
1504
  type: 'TSTypeAnnotation',
1505
+ loc: DUMMY_LOC,
1398
1506
  typeAnnotation: tsPropsObjectType,
1399
1507
  },
1400
1508
  optional: false,
@@ -1410,6 +1518,7 @@ const getTransforms = (
1410
1518
 
1411
1519
  return {
1412
1520
  type: 'TSDeclareFunction',
1521
+ loc: DUMMY_LOC,
1413
1522
  async: false,
1414
1523
  body: undefined,
1415
1524
  declare: true,
@@ -1417,6 +1526,7 @@ const getTransforms = (
1417
1526
  generator: false,
1418
1527
  id: {
1419
1528
  type: 'Identifier',
1529
+ loc: DUMMY_LOC,
1420
1530
  name: id.name,
1421
1531
  },
1422
1532
  params: functionInfo.params,
@@ -1435,6 +1545,7 @@ const getTransforms = (
1435
1545
 
1436
1546
  return {
1437
1547
  type: 'TSDeclareFunction',
1548
+ loc: DUMMY_LOC,
1438
1549
  async: false,
1439
1550
  body: undefined,
1440
1551
  declare: true,
@@ -1442,6 +1553,7 @@ const getTransforms = (
1442
1553
  generator: false,
1443
1554
  id: {
1444
1555
  type: 'Identifier',
1556
+ loc: DUMMY_LOC,
1445
1557
  name: id.name,
1446
1558
  },
1447
1559
  params: functionInfo.params,
@@ -1462,8 +1574,10 @@ const getTransforms = (
1462
1574
 
1463
1575
  return {
1464
1576
  type: 'TSInterfaceDeclaration',
1577
+ loc: DUMMY_LOC,
1465
1578
  body: {
1466
1579
  type: 'TSInterfaceBody',
1580
+ loc: DUMMY_LOC,
1467
1581
  body: transformedBody.members,
1468
1582
  },
1469
1583
  declare: node.type !== 'InterfaceDeclaration',
@@ -1480,6 +1594,7 @@ const getTransforms = (
1480
1594
  ): TSESTree.TSTypeAliasDeclaration {
1481
1595
  return {
1482
1596
  type: 'TSTypeAliasDeclaration',
1597
+ loc: DUMMY_LOC,
1483
1598
  declare: node.type === 'DeclareTypeAlias',
1484
1599
  id: transform.Identifier(node.id, false),
1485
1600
  typeAnnotation: transformTypeAnnotationType(node.right),
@@ -1498,12 +1613,14 @@ const getTransforms = (
1498
1613
 
1499
1614
  return {
1500
1615
  type: 'TSTypeAliasDeclaration',
1616
+ loc: DUMMY_LOC,
1501
1617
  declare: true,
1502
1618
  id: transform.Identifier(node.id, false),
1503
1619
  typeAnnotation:
1504
1620
  node.supertype == null
1505
1621
  ? {
1506
1622
  type: 'TSUnknownKeyword',
1623
+ loc: DUMMY_LOC,
1507
1624
  }
1508
1625
  : transformTypeAnnotationType(node.supertype),
1509
1626
  typeParameters:
@@ -1517,10 +1634,12 @@ const getTransforms = (
1517
1634
  ): TSESTree.VariableDeclaration {
1518
1635
  return {
1519
1636
  type: 'VariableDeclaration',
1637
+ loc: DUMMY_LOC,
1520
1638
  declare: true,
1521
1639
  declarations: [
1522
1640
  {
1523
1641
  type: 'VariableDeclarator',
1642
+ loc: DUMMY_LOC,
1524
1643
  declare: true,
1525
1644
  id: transform.Identifier(node.id, true),
1526
1645
  init: null,
@@ -1569,6 +1688,7 @@ const getTransforms = (
1569
1688
  ): TSESTree.ExportAllDeclaration {
1570
1689
  return {
1571
1690
  type: 'ExportAllDeclaration',
1691
+ loc: DUMMY_LOC,
1572
1692
  // flow does not currently support import/export assertions
1573
1693
  assertions: [],
1574
1694
  exportKind: node.exportKind,
@@ -1586,6 +1706,7 @@ const getTransforms = (
1586
1706
  // can never have a declaration with a source
1587
1707
  return {
1588
1708
  type: 'ExportNamedDeclaration',
1709
+ loc: DUMMY_LOC,
1589
1710
  // flow does not currently support import/export assertions
1590
1711
  assertions: [],
1591
1712
  declaration: null,
@@ -1629,6 +1750,7 @@ const getTransforms = (
1629
1750
 
1630
1751
  const mainExport = {
1631
1752
  type: 'ExportNamedDeclaration',
1753
+ loc: DUMMY_LOC,
1632
1754
  assertions: [],
1633
1755
  declaration: exportedDeclaration,
1634
1756
  exportKind: node.exportKind,
@@ -1642,6 +1764,7 @@ const getTransforms = (
1642
1764
  mainExport,
1643
1765
  {
1644
1766
  type: 'ExportNamedDeclaration',
1767
+ loc: DUMMY_LOC,
1645
1768
  assertions: [],
1646
1769
  declaration: mergedDeclaration,
1647
1770
  exportKind: node.exportKind,
@@ -1658,6 +1781,7 @@ const getTransforms = (
1658
1781
  ): TSESTree.ExportSpecifier {
1659
1782
  return {
1660
1783
  type: 'ExportSpecifier',
1784
+ loc: DUMMY_LOC,
1661
1785
  exported: transform.Identifier(node.exported, false),
1662
1786
  local: transform.Identifier(node.local, false),
1663
1787
  // flow does not support inline exportKind for named exports
@@ -1671,9 +1795,11 @@ const getTransforms = (
1671
1795
  if (node.type === 'FunctionTypeAnnotation' && node.this != null) {
1672
1796
  params.unshift({
1673
1797
  type: 'Identifier',
1798
+ loc: DUMMY_LOC,
1674
1799
  name: 'this',
1675
1800
  typeAnnotation: {
1676
1801
  type: 'TSTypeAnnotation',
1802
+ loc: DUMMY_LOC,
1677
1803
  typeAnnotation: transformTypeAnnotationType(
1678
1804
  node.this.typeAnnotation,
1679
1805
  ),
@@ -1684,15 +1810,18 @@ const getTransforms = (
1684
1810
  const rest = node.rest;
1685
1811
  params.push({
1686
1812
  type: 'RestElement',
1813
+ loc: DUMMY_LOC,
1687
1814
  argument:
1688
1815
  rest.name == null
1689
1816
  ? {
1690
1817
  type: 'Identifier',
1818
+ loc: DUMMY_LOC,
1691
1819
  name: '$$REST$$',
1692
1820
  }
1693
1821
  : transform.Identifier(rest.name, false),
1694
1822
  typeAnnotation: {
1695
1823
  type: 'TSTypeAnnotation',
1824
+ loc: DUMMY_LOC,
1696
1825
  typeAnnotation: transformTypeAnnotationType(rest.typeAnnotation),
1697
1826
  },
1698
1827
  });
@@ -1700,9 +1829,11 @@ const getTransforms = (
1700
1829
 
1701
1830
  return {
1702
1831
  type: 'TSFunctionType',
1832
+ loc: DUMMY_LOC,
1703
1833
  params,
1704
1834
  returnType: {
1705
1835
  type: 'TSTypeAnnotation',
1836
+ loc: DUMMY_LOC,
1706
1837
  typeAnnotation: transformTypeAnnotationType(node.returnType),
1707
1838
  },
1708
1839
  typeParameters:
@@ -1717,9 +1848,11 @@ const getTransforms = (
1717
1848
  ): TSESTree.Parameter {
1718
1849
  return {
1719
1850
  type: 'Identifier',
1851
+ loc: DUMMY_LOC,
1720
1852
  name: node.name == null ? `$$PARAM_${idx}$$` : node.name.name,
1721
1853
  typeAnnotation: {
1722
1854
  type: 'TSTypeAnnotation',
1855
+ loc: DUMMY_LOC,
1723
1856
  typeAnnotation: transformTypeAnnotationType(node.typeAnnotation),
1724
1857
  },
1725
1858
  optional: node.optional,
@@ -1819,30 +1952,38 @@ const getTransforms = (
1819
1952
  const params = assertHasExactlyNTypeParameters(2);
1820
1953
  return {
1821
1954
  type: 'TSTypeReference',
1955
+ loc: DUMMY_LOC,
1822
1956
  typeName: {
1823
1957
  type: 'Identifier',
1958
+ loc: DUMMY_LOC,
1824
1959
  name: 'Pick',
1825
1960
  },
1826
1961
  typeParameters: {
1827
1962
  type: 'TSTypeParameterInstantiation',
1963
+ loc: DUMMY_LOC,
1828
1964
  params: [
1829
1965
  params[0],
1830
1966
  {
1831
1967
  type: 'TSTypeReference',
1968
+ loc: DUMMY_LOC,
1832
1969
  typeName: {
1833
1970
  type: 'Identifier',
1971
+ loc: DUMMY_LOC,
1834
1972
  name: 'Exclude',
1835
1973
  },
1836
1974
  typeParameters: {
1837
1975
  type: 'TSTypeParameterInstantiation',
1976
+ loc: DUMMY_LOC,
1838
1977
  params: [
1839
1978
  {
1840
1979
  type: 'TSTypeOperator',
1980
+ loc: DUMMY_LOC,
1841
1981
  operator: 'keyof',
1842
1982
  typeAnnotation: params[0],
1843
1983
  },
1844
1984
  {
1845
1985
  type: 'TSTypeOperator',
1986
+ loc: DUMMY_LOC,
1846
1987
  operator: 'keyof',
1847
1988
  typeAnnotation: params[1],
1848
1989
  },
@@ -1860,6 +2001,7 @@ const getTransforms = (
1860
2001
  const params = assertHasExactlyNTypeParameters(2);
1861
2002
  return {
1862
2003
  type: 'TSIndexedAccessType',
2004
+ loc: DUMMY_LOC,
1863
2005
  objectType: params[0],
1864
2006
  indexType: params[1],
1865
2007
  };
@@ -1887,6 +2029,7 @@ const getTransforms = (
1887
2029
 
1888
2030
  return {
1889
2031
  type: 'TSImportType',
2032
+ loc: DUMMY_LOC,
1890
2033
  isTypeOf: true,
1891
2034
  argument: moduleName,
1892
2035
  qualifier: null,
@@ -1898,6 +2041,7 @@ const getTransforms = (
1898
2041
  // `$FlowFixMe` => `any`
1899
2042
  return {
1900
2043
  type: 'TSAnyKeyword',
2044
+ loc: DUMMY_LOC,
1901
2045
  };
1902
2046
  }
1903
2047
 
@@ -1905,14 +2049,18 @@ const getTransforms = (
1905
2049
  // `$KeyMirror<T>` => `{[K in keyof T]: K}`
1906
2050
  return {
1907
2051
  type: 'TSMappedType',
2052
+ loc: DUMMY_LOC,
1908
2053
  typeParameter: {
1909
2054
  type: 'TSTypeParameter',
2055
+ loc: DUMMY_LOC,
1910
2056
  name: {
1911
2057
  type: 'Identifier',
2058
+ loc: DUMMY_LOC,
1912
2059
  name: 'K',
1913
2060
  },
1914
2061
  constraint: {
1915
2062
  type: 'TSTypeOperator',
2063
+ loc: DUMMY_LOC,
1916
2064
  operator: 'keyof',
1917
2065
  typeAnnotation: assertHasExactlyNTypeParameters(1)[0],
1918
2066
  },
@@ -1922,8 +2070,10 @@ const getTransforms = (
1922
2070
  nameType: null,
1923
2071
  typeAnnotation: {
1924
2072
  type: 'TSTypeReference',
2073
+ loc: DUMMY_LOC,
1925
2074
  typeName: {
1926
2075
  type: 'Identifier',
2076
+ loc: DUMMY_LOC,
1927
2077
  name: 'K',
1928
2078
  },
1929
2079
  },
@@ -1934,6 +2084,7 @@ const getTransforms = (
1934
2084
  // `$Keys<T>` => `keyof T`
1935
2085
  return {
1936
2086
  type: 'TSTypeOperator',
2087
+ loc: DUMMY_LOC,
1937
2088
  operator: 'keyof',
1938
2089
  typeAnnotation: assertHasExactlyNTypeParameters(1)[0],
1939
2090
  };
@@ -1944,12 +2095,15 @@ const getTransforms = (
1944
2095
  // Not a great name because `NonNullable` also excludes `undefined`
1945
2096
  return {
1946
2097
  type: 'TSTypeReference',
2098
+ loc: DUMMY_LOC,
1947
2099
  typeName: {
1948
2100
  type: 'Identifier',
2101
+ loc: DUMMY_LOC,
1949
2102
  name: 'NonNullable',
1950
2103
  },
1951
2104
  typeParameters: {
1952
2105
  type: 'TSTypeParameterInstantiation',
2106
+ loc: DUMMY_LOC,
1953
2107
  params: assertHasExactlyNTypeParameters(1),
1954
2108
  },
1955
2109
  };
@@ -1959,12 +2113,15 @@ const getTransforms = (
1959
2113
  // `$ReadOnly<T>` => `Readonly<T>`
1960
2114
  return {
1961
2115
  type: 'TSTypeReference',
2116
+ loc: DUMMY_LOC,
1962
2117
  typeName: {
1963
2118
  type: 'Identifier',
2119
+ loc: DUMMY_LOC,
1964
2120
  name: 'Readonly',
1965
2121
  },
1966
2122
  typeParameters: {
1967
2123
  type: 'TSTypeParameterInstantiation',
2124
+ loc: DUMMY_LOC,
1968
2125
  params: assertHasExactlyNTypeParameters(1),
1969
2126
  },
1970
2127
  };
@@ -1977,12 +2134,15 @@ const getTransforms = (
1977
2134
  // TODO - maybe a config option?
1978
2135
  return {
1979
2136
  type: 'TSTypeReference',
2137
+ loc: DUMMY_LOC,
1980
2138
  typeName: {
1981
2139
  type: 'Identifier',
2140
+ loc: DUMMY_LOC,
1982
2141
  name: 'ReadonlyArray',
1983
2142
  },
1984
2143
  typeParameters: {
1985
2144
  type: 'TSTypeParameterInstantiation',
2145
+ loc: DUMMY_LOC,
1986
2146
  params: assertHasExactlyNTypeParameters(1),
1987
2147
  },
1988
2148
  };
@@ -1991,12 +2151,15 @@ const getTransforms = (
1991
2151
  case '$ReadOnlyMap': {
1992
2152
  return {
1993
2153
  type: 'TSTypeReference',
2154
+ loc: DUMMY_LOC,
1994
2155
  typeName: {
1995
2156
  type: 'Identifier',
2157
+ loc: DUMMY_LOC,
1996
2158
  name: 'ReadonlyMap',
1997
2159
  },
1998
2160
  typeParameters: {
1999
2161
  type: 'TSTypeParameterInstantiation',
2162
+ loc: DUMMY_LOC,
2000
2163
  params: assertHasExactlyNTypeParameters(2),
2001
2164
  },
2002
2165
  };
@@ -2005,12 +2168,15 @@ const getTransforms = (
2005
2168
  case '$ReadOnlySet': {
2006
2169
  return {
2007
2170
  type: 'TSTypeReference',
2171
+ loc: DUMMY_LOC,
2008
2172
  typeName: {
2009
2173
  type: 'Identifier',
2174
+ loc: DUMMY_LOC,
2010
2175
  name: 'ReadonlySet',
2011
2176
  },
2012
2177
  typeParameters: {
2013
2178
  type: 'TSTypeParameterInstantiation',
2179
+ loc: DUMMY_LOC,
2014
2180
  params: assertHasExactlyNTypeParameters(1),
2015
2181
  },
2016
2182
  };
@@ -2021,9 +2187,11 @@ const getTransforms = (
2021
2187
  const transformedType = assertHasExactlyNTypeParameters(1)[0];
2022
2188
  return {
2023
2189
  type: 'TSIndexedAccessType',
2190
+ loc: DUMMY_LOC,
2024
2191
  objectType: transformedType,
2025
2192
  indexType: {
2026
2193
  type: 'TSTypeOperator',
2194
+ loc: DUMMY_LOC,
2027
2195
  operator: 'keyof',
2028
2196
  typeAnnotation: transformedType,
2029
2197
  },
@@ -2042,20 +2210,26 @@ const getTransforms = (
2042
2210
 
2043
2211
  return {
2044
2212
  type: 'TSConstructorType',
2213
+ loc: DUMMY_LOC,
2045
2214
  abstract: false,
2046
2215
  params: [
2047
2216
  {
2048
2217
  type: 'RestElement',
2218
+ loc: DUMMY_LOC,
2049
2219
  argument: {
2050
2220
  type: 'Identifier',
2221
+ loc: DUMMY_LOC,
2051
2222
  name: 'args',
2052
2223
  },
2053
2224
  typeAnnotation: {
2054
2225
  type: 'TSTypeAnnotation',
2226
+ loc: DUMMY_LOC,
2055
2227
  typeAnnotation: {
2056
2228
  type: 'TSArrayType',
2229
+ loc: DUMMY_LOC,
2057
2230
  elementType: {
2058
2231
  type: 'TSAnyKeyword',
2232
+ loc: DUMMY_LOC,
2059
2233
  },
2060
2234
  },
2061
2235
  },
@@ -2063,6 +2237,7 @@ const getTransforms = (
2063
2237
  ],
2064
2238
  returnType: {
2065
2239
  type: 'TSTypeAnnotation',
2240
+ loc: DUMMY_LOC,
2066
2241
  typeAnnotation: param,
2067
2242
  },
2068
2243
  };
@@ -2085,16 +2260,20 @@ const getTransforms = (
2085
2260
  const [param] = assertHasExactlyNTypeParameters(1);
2086
2261
  return {
2087
2262
  type: 'TSUnionType',
2263
+ loc: DUMMY_LOC,
2088
2264
  types: [
2089
2265
  param,
2090
2266
  {
2091
2267
  type: 'TSTypeReference',
2268
+ loc: DUMMY_LOC,
2092
2269
  typeName: {
2093
2270
  type: 'Identifier',
2271
+ loc: DUMMY_LOC,
2094
2272
  name: 'ReadonlyArray',
2095
2273
  },
2096
2274
  typeParameters: {
2097
2275
  type: 'TSTypeParameterInstantiation',
2276
+ loc: DUMMY_LOC,
2098
2277
  params: [param],
2099
2278
  },
2100
2279
  },
@@ -2122,16 +2301,20 @@ const getTransforms = (
2122
2301
 
2123
2302
  return {
2124
2303
  type: 'TSTypeReference',
2304
+ loc: DUMMY_LOC,
2125
2305
  typeName: {
2126
2306
  type: 'TSQualifiedName',
2307
+ loc: DUMMY_LOC,
2127
2308
  left: getReactIdentifier(hasReactImport),
2128
2309
  right: {
2129
2310
  type: 'Identifier',
2311
+ loc: DUMMY_LOC,
2130
2312
  name: 'Component',
2131
2313
  },
2132
2314
  },
2133
2315
  typeParameters: {
2134
2316
  type: 'TSTypeParameterInstantiation',
2317
+ loc: DUMMY_LOC,
2135
2318
  params: params.map(param => transformTypeAnnotationType(param)),
2136
2319
  },
2137
2320
  };
@@ -2143,16 +2326,20 @@ const getTransforms = (
2143
2326
  case 'React.Context':
2144
2327
  return {
2145
2328
  type: 'TSTypeReference',
2329
+ loc: DUMMY_LOC,
2146
2330
  typeName: {
2147
2331
  type: 'TSQualifiedName',
2332
+ loc: DUMMY_LOC,
2148
2333
  left: getReactIdentifier(hasReactImport),
2149
2334
  right: {
2150
2335
  type: 'Identifier',
2336
+ loc: DUMMY_LOC,
2151
2337
  name: `Context`,
2152
2338
  },
2153
2339
  },
2154
2340
  typeParameters: {
2155
2341
  type: 'TSTypeParameterInstantiation',
2342
+ loc: DUMMY_LOC,
2156
2343
  params: assertHasExactlyNTypeParameters(1),
2157
2344
  },
2158
2345
  };
@@ -2163,11 +2350,14 @@ const getTransforms = (
2163
2350
  assertHasExactlyNTypeParameters(0);
2164
2351
  return {
2165
2352
  type: 'TSTypeReference',
2353
+ loc: DUMMY_LOC,
2166
2354
  typeName: {
2167
2355
  type: 'TSQualifiedName',
2356
+ loc: DUMMY_LOC,
2168
2357
  left: getReactIdentifier(hasReactImport),
2169
2358
  right: {
2170
2359
  type: 'Identifier',
2360
+ loc: DUMMY_LOC,
2171
2361
  name: 'Key',
2172
2362
  },
2173
2363
  },
@@ -2179,11 +2369,14 @@ const getTransforms = (
2179
2369
  assertHasExactlyNTypeParameters(0);
2180
2370
  return {
2181
2371
  type: 'TSTypeReference',
2372
+ loc: DUMMY_LOC,
2182
2373
  typeName: {
2183
2374
  type: 'TSQualifiedName',
2375
+ loc: DUMMY_LOC,
2184
2376
  left: getReactIdentifier(hasReactImport),
2185
2377
  right: {
2186
2378
  type: 'Identifier',
2379
+ loc: DUMMY_LOC,
2187
2380
  name: `ElementType`,
2188
2381
  },
2189
2382
  },
@@ -2196,11 +2389,14 @@ const getTransforms = (
2196
2389
  assertHasExactlyNTypeParameters(0);
2197
2390
  return {
2198
2391
  type: 'TSTypeReference',
2392
+ loc: DUMMY_LOC,
2199
2393
  typeName: {
2200
2394
  type: 'TSQualifiedName',
2395
+ loc: DUMMY_LOC,
2201
2396
  left: getReactIdentifier(hasReactImport),
2202
2397
  right: {
2203
2398
  type: 'Identifier',
2399
+ loc: DUMMY_LOC,
2204
2400
  name: `ReactNode`,
2205
2401
  },
2206
2402
  },
@@ -2212,16 +2408,20 @@ const getTransforms = (
2212
2408
  case 'React.Element': {
2213
2409
  return {
2214
2410
  type: 'TSTypeReference',
2411
+ loc: DUMMY_LOC,
2215
2412
  typeName: {
2216
2413
  type: 'TSQualifiedName',
2414
+ loc: DUMMY_LOC,
2217
2415
  left: getReactIdentifier(hasReactImport),
2218
2416
  right: {
2219
2417
  type: 'Identifier',
2418
+ loc: DUMMY_LOC,
2220
2419
  name: `ReactElement`,
2221
2420
  },
2222
2421
  },
2223
2422
  typeParameters: {
2224
2423
  type: 'TSTypeParameterInstantiation',
2424
+ loc: DUMMY_LOC,
2225
2425
  params: assertHasExactlyNTypeParameters(1),
2226
2426
  },
2227
2427
  };
@@ -2232,16 +2432,20 @@ const getTransforms = (
2232
2432
  case 'React.ElementRef':
2233
2433
  return {
2234
2434
  type: 'TSTypeReference',
2435
+ loc: DUMMY_LOC,
2235
2436
  typeName: {
2236
2437
  type: 'TSQualifiedName',
2438
+ loc: DUMMY_LOC,
2237
2439
  left: getReactIdentifier(hasReactImport),
2238
2440
  right: {
2239
2441
  type: 'Identifier',
2442
+ loc: DUMMY_LOC,
2240
2443
  name: `ElementRef`,
2241
2444
  },
2242
2445
  },
2243
2446
  typeParameters: {
2244
2447
  type: 'TSTypeParameterInstantiation',
2448
+ loc: DUMMY_LOC,
2245
2449
  params: assertHasExactlyNTypeParameters(1),
2246
2450
  },
2247
2451
  };
@@ -2252,11 +2456,14 @@ const getTransforms = (
2252
2456
  assertHasExactlyNTypeParameters(0);
2253
2457
  return {
2254
2458
  type: 'TSTypeReference',
2459
+ loc: DUMMY_LOC,
2255
2460
  typeName: {
2256
2461
  type: 'TSQualifiedName',
2462
+ loc: DUMMY_LOC,
2257
2463
  left: getReactIdentifier(hasReactImport),
2258
2464
  right: {
2259
2465
  type: 'Identifier',
2466
+ loc: DUMMY_LOC,
2260
2467
  name: `Fragment`,
2261
2468
  },
2262
2469
  },
@@ -2267,14 +2474,18 @@ const getTransforms = (
2267
2474
  assertHasExactlyNTypeParameters(0);
2268
2475
  return {
2269
2476
  type: 'TSTypeReference',
2477
+ loc: DUMMY_LOC,
2270
2478
  typeName: {
2271
2479
  type: 'TSQualifiedName',
2480
+ loc: DUMMY_LOC,
2272
2481
  left: {
2273
2482
  type: 'Identifier',
2483
+ loc: DUMMY_LOC,
2274
2484
  name: 'JSX',
2275
2485
  },
2276
2486
  right: {
2277
2487
  type: 'Identifier',
2488
+ loc: DUMMY_LOC,
2278
2489
  name: 'Element',
2279
2490
  },
2280
2491
  },
@@ -2287,16 +2498,20 @@ const getTransforms = (
2287
2498
  case 'React$ComponentType': {
2288
2499
  return {
2289
2500
  type: 'TSTypeReference',
2501
+ loc: DUMMY_LOC,
2290
2502
  typeName: {
2291
2503
  type: 'TSQualifiedName',
2504
+ loc: DUMMY_LOC,
2292
2505
  left: getReactIdentifier(hasReactImport),
2293
2506
  right: {
2294
2507
  type: 'Identifier',
2508
+ loc: DUMMY_LOC,
2295
2509
  name: 'ComponentType',
2296
2510
  },
2297
2511
  },
2298
2512
  typeParameters: {
2299
2513
  type: 'TSTypeParameterInstantiation',
2514
+ loc: DUMMY_LOC,
2300
2515
  params: assertHasExactlyNTypeParameters(1),
2301
2516
  },
2302
2517
  };
@@ -2315,10 +2530,10 @@ const getTransforms = (
2315
2530
  );
2316
2531
  }
2317
2532
  const params = typeParameters.params;
2318
- if (params.length > 2) {
2533
+ if (params.length > 3) {
2319
2534
  throw translationError(
2320
2535
  node,
2321
- `Expected at no more than 2 type parameters with \`${fullTypeName}\``,
2536
+ `Expected at no more than 3 type parameters with \`${fullTypeName}\``,
2322
2537
  );
2323
2538
  }
2324
2539
 
@@ -2327,28 +2542,35 @@ const getTransforms = (
2327
2542
  return assertHasExactlyNTypeParameters(1);
2328
2543
  }
2329
2544
 
2330
- const [props, ref] = assertHasExactlyNTypeParameters(2);
2545
+ const props = transformTypeAnnotationType(params[0]);
2546
+ const ref = transformTypeAnnotationType(params[1]);
2331
2547
 
2332
2548
  return [
2333
2549
  {
2334
2550
  type: 'TSIntersectionType',
2551
+ loc: DUMMY_LOC,
2335
2552
  types: [
2336
2553
  props,
2337
2554
  {
2338
2555
  type: 'TSTypeReference',
2556
+ loc: DUMMY_LOC,
2339
2557
  typeName: {
2340
2558
  type: 'TSQualifiedName',
2559
+ loc: DUMMY_LOC,
2341
2560
  left: {
2342
2561
  type: 'Identifier',
2562
+ loc: DUMMY_LOC,
2343
2563
  name: 'React',
2344
2564
  },
2345
2565
  right: {
2346
2566
  type: 'Identifier',
2567
+ loc: DUMMY_LOC,
2347
2568
  name: 'RefAttributes',
2348
2569
  },
2349
2570
  },
2350
2571
  typeParameters: {
2351
2572
  type: 'TSTypeParameterInstantiation',
2573
+ loc: DUMMY_LOC,
2352
2574
  params: [ref],
2353
2575
  },
2354
2576
  },
@@ -2359,16 +2581,20 @@ const getTransforms = (
2359
2581
 
2360
2582
  return {
2361
2583
  type: 'TSTypeReference',
2584
+ loc: DUMMY_LOC,
2362
2585
  typeName: {
2363
2586
  type: 'TSQualifiedName',
2587
+ loc: DUMMY_LOC,
2364
2588
  left: getReactIdentifier(hasReactImport),
2365
2589
  right: {
2366
2590
  type: 'Identifier',
2591
+ loc: DUMMY_LOC,
2367
2592
  name: 'ComponentType',
2368
2593
  },
2369
2594
  },
2370
2595
  typeParameters: {
2371
2596
  type: 'TSTypeParameterInstantiation',
2597
+ loc: DUMMY_LOC,
2372
2598
  params: newParams,
2373
2599
  },
2374
2600
  };
@@ -2379,16 +2605,20 @@ const getTransforms = (
2379
2605
  case 'React$ElementProps': {
2380
2606
  return {
2381
2607
  type: 'TSTypeReference',
2608
+ loc: DUMMY_LOC,
2382
2609
  typeName: {
2383
2610
  type: 'TSQualifiedName',
2611
+ loc: DUMMY_LOC,
2384
2612
  left: getReactIdentifier(hasReactImport),
2385
2613
  right: {
2386
2614
  type: 'Identifier',
2615
+ loc: DUMMY_LOC,
2387
2616
  name: 'ComponentProps',
2388
2617
  },
2389
2618
  },
2390
2619
  typeParameters: {
2391
2620
  type: 'TSTypeParameterInstantiation',
2621
+ loc: DUMMY_LOC,
2392
2622
  params: assertHasExactlyNTypeParameters(1),
2393
2623
  },
2394
2624
  };
@@ -2400,33 +2630,42 @@ const getTransforms = (
2400
2630
  const [param] = assertHasExactlyNTypeParameters(1);
2401
2631
  return {
2402
2632
  type: 'TSTypeReference',
2633
+ loc: DUMMY_LOC,
2403
2634
  typeName: {
2404
2635
  type: 'TSQualifiedName',
2636
+ loc: DUMMY_LOC,
2405
2637
  left: {
2406
2638
  type: 'Identifier',
2639
+ loc: DUMMY_LOC,
2407
2640
  name: 'JSX',
2408
2641
  },
2409
2642
  right: {
2410
2643
  type: 'Identifier',
2644
+ loc: DUMMY_LOC,
2411
2645
  name: 'LibraryManagedAttributes',
2412
2646
  },
2413
2647
  },
2414
2648
  typeParameters: {
2415
2649
  type: 'TSTypeParameterInstantiation',
2650
+ loc: DUMMY_LOC,
2416
2651
  params: [
2417
2652
  param,
2418
2653
  {
2419
2654
  type: 'TSTypeReference',
2655
+ loc: DUMMY_LOC,
2420
2656
  typeName: {
2421
2657
  type: 'TSQualifiedName',
2658
+ loc: DUMMY_LOC,
2422
2659
  left: getReactIdentifier(hasReactImport),
2423
2660
  right: {
2424
2661
  type: 'Identifier',
2662
+ loc: DUMMY_LOC,
2425
2663
  name: `ComponentProps`,
2426
2664
  },
2427
2665
  },
2428
2666
  typeParameters: {
2429
2667
  type: 'TSTypeParameterInstantiation',
2668
+ loc: DUMMY_LOC,
2430
2669
  params: [param],
2431
2670
  },
2432
2671
  },
@@ -2440,36 +2679,46 @@ const getTransforms = (
2440
2679
  case 'React$Ref':
2441
2680
  return {
2442
2681
  type: 'TSTypeReference',
2682
+ loc: DUMMY_LOC,
2443
2683
  typeName: {
2444
2684
  type: 'Identifier',
2685
+ loc: DUMMY_LOC,
2445
2686
  name: 'NonNullable',
2446
2687
  },
2447
2688
  typeParameters: {
2448
2689
  type: 'TSTypeParameterInstantiation',
2690
+ loc: DUMMY_LOC,
2449
2691
  params: [
2450
2692
  {
2451
2693
  type: 'TSUnionType',
2694
+ loc: DUMMY_LOC,
2452
2695
  types: [
2453
2696
  {
2454
2697
  type: 'TSTypeReference',
2698
+ loc: DUMMY_LOC,
2455
2699
  typeName: {
2456
2700
  type: 'TSQualifiedName',
2701
+ loc: DUMMY_LOC,
2457
2702
  left: getReactIdentifier(hasReactImport),
2458
2703
  right: {
2459
2704
  type: 'Identifier',
2705
+ loc: DUMMY_LOC,
2460
2706
  name: 'Ref',
2461
2707
  },
2462
2708
  },
2463
2709
  typeParameters: {
2464
2710
  type: 'TSTypeParameterInstantiation',
2711
+ loc: DUMMY_LOC,
2465
2712
  params: assertHasExactlyNTypeParameters(1),
2466
2713
  },
2467
2714
  },
2468
2715
  {
2469
2716
  type: 'TSStringKeyword',
2717
+ loc: DUMMY_LOC,
2470
2718
  },
2471
2719
  {
2472
2720
  type: 'TSNumberKeyword',
2721
+ loc: DUMMY_LOC,
2473
2722
  },
2474
2723
  ],
2475
2724
  },
@@ -2483,6 +2732,7 @@ const getTransforms = (
2483
2732
 
2484
2733
  return {
2485
2734
  type: 'TSTypeReference',
2735
+ loc: DUMMY_LOC,
2486
2736
  typeName:
2487
2737
  node.id.type === 'Identifier'
2488
2738
  ? transform.Identifier(node.id, false)
@@ -2499,6 +2749,7 @@ const getTransforms = (
2499
2749
  ): TSESTree.Identifier {
2500
2750
  return {
2501
2751
  type: 'Identifier',
2752
+ loc: DUMMY_LOC,
2502
2753
  name: node.name,
2503
2754
  ...(includeTypeAnnotation && node.typeAnnotation != null
2504
2755
  ? {
@@ -2512,6 +2763,7 @@ const getTransforms = (
2512
2763
  ): TSESTree.TSIndexedAccessType {
2513
2764
  return {
2514
2765
  type: 'TSIndexedAccessType',
2766
+ loc: DUMMY_LOC,
2515
2767
  objectType: transformTypeAnnotationType(node.objectType),
2516
2768
  indexType: transformTypeAnnotationType(node.indexType),
2517
2769
  };
@@ -2526,6 +2778,7 @@ const getTransforms = (
2526
2778
  ): TSESTree.ImportAttribute {
2527
2779
  return {
2528
2780
  type: 'ImportAttribute',
2781
+ loc: DUMMY_LOC,
2529
2782
  key:
2530
2783
  node.key.type === 'Identifier'
2531
2784
  ? transform.Identifier(node.key)
@@ -2539,20 +2792,23 @@ const getTransforms = (
2539
2792
  const importKind = node.importKind;
2540
2793
 
2541
2794
  const specifiers = [];
2542
- const unsupportedSpecifiers = [];
2795
+ const unsupportedSpecifiers: Array<TSESTree.TSTypeAliasDeclaration> = [];
2543
2796
  node.specifiers.forEach(spec => {
2544
2797
  let id = (() => {
2545
2798
  if (node.importKind === 'typeof' || spec.importKind === 'typeof') {
2546
2799
  const id = {
2547
2800
  type: 'Identifier',
2801
+ loc: DUMMY_LOC,
2548
2802
  name: getPlaceholderNameForTypeofImport(),
2549
2803
  };
2550
2804
 
2551
2805
  unsupportedSpecifiers.push({
2552
2806
  type: 'TSTypeAliasDeclaration',
2807
+ loc: DUMMY_LOC,
2553
2808
  id: transform.Identifier(spec.local, false),
2554
2809
  typeAnnotation: {
2555
2810
  type: 'TSTypeQuery',
2811
+ loc: DUMMY_LOC,
2556
2812
  exprName: id,
2557
2813
  },
2558
2814
  });
@@ -2567,6 +2823,7 @@ const getTransforms = (
2567
2823
  case 'ImportDefaultSpecifier':
2568
2824
  specifiers.push({
2569
2825
  type: 'ImportDefaultSpecifier',
2826
+ loc: DUMMY_LOC,
2570
2827
  local: id,
2571
2828
  });
2572
2829
  return;
@@ -2574,6 +2831,7 @@ const getTransforms = (
2574
2831
  case 'ImportNamespaceSpecifier':
2575
2832
  specifiers.push({
2576
2833
  type: 'ImportNamespaceSpecifier',
2834
+ loc: DUMMY_LOC,
2577
2835
  local: id,
2578
2836
  });
2579
2837
  return;
@@ -2581,6 +2839,7 @@ const getTransforms = (
2581
2839
  case 'ImportSpecifier':
2582
2840
  specifiers.push({
2583
2841
  type: 'ImportSpecifier',
2842
+ loc: DUMMY_LOC,
2584
2843
  importKind:
2585
2844
  spec.importKind === 'typeof' || spec.importKind === 'type'
2586
2845
  ? 'type'
@@ -2592,10 +2851,11 @@ const getTransforms = (
2592
2851
  }
2593
2852
  });
2594
2853
 
2595
- const out = specifiers.length
2854
+ const out: Array<TSESTree.ImportDeclaration> = specifiers.length
2596
2855
  ? [
2597
2856
  {
2598
2857
  type: 'ImportDeclaration',
2858
+ loc: DUMMY_LOC,
2599
2859
  assertions: node.assertions.map(transform.ImportAttribute),
2600
2860
  importKind:
2601
2861
  importKind === 'typeof' ? 'type' : importKind ?? 'value',
@@ -2612,7 +2872,9 @@ const getTransforms = (
2612
2872
  ): TSESTree.TSInterfaceHeritage {
2613
2873
  return {
2614
2874
  type: 'TSInterfaceHeritage',
2615
- expression: transform.Identifier(node.id, false),
2875
+ loc: DUMMY_LOC,
2876
+ // Bug: node.id can be qualified
2877
+ expression: transform.Identifier((node.id: $FlowFixMe), false),
2616
2878
  typeParameters:
2617
2879
  node.typeParameters == null
2618
2880
  ? undefined
@@ -2628,10 +2890,13 @@ const getTransforms = (
2628
2890
  // type T = U & V & { ... }
2629
2891
  return {
2630
2892
  type: 'TSIntersectionType',
2893
+ loc: DUMMY_LOC,
2631
2894
  types: [
2632
2895
  ...node.extends.map(ex => ({
2633
2896
  type: 'TSTypeReference',
2634
- typeName: transform.Identifier(ex.id, false),
2897
+ loc: DUMMY_LOC,
2898
+ // Bug: ex.id can be qualified
2899
+ typeName: transform.Identifier((ex.id: $FlowFixMe), false),
2635
2900
  typeParameters:
2636
2901
  ex.typeParameters == null
2637
2902
  ? undefined
@@ -2649,6 +2914,7 @@ const getTransforms = (
2649
2914
  ): TSESTree.TSIntersectionType {
2650
2915
  return {
2651
2916
  type: 'TSIntersectionType',
2917
+ loc: DUMMY_LOC,
2652
2918
  types: node.types.map(transformTypeAnnotationType),
2653
2919
  };
2654
2920
  },
@@ -2673,11 +2939,13 @@ const getTransforms = (
2673
2939
  ): TSESTree.TSUnknownKeyword {
2674
2940
  return {
2675
2941
  type: 'TSUnknownKeyword',
2942
+ loc: DUMMY_LOC,
2676
2943
  };
2677
2944
  },
2678
2945
  NullLiteral(_node: FlowESTree.NullLiteral): TSESTree.NullLiteral {
2679
2946
  return {
2680
2947
  type: 'Literal',
2948
+ loc: DUMMY_LOC,
2681
2949
  raw: 'null',
2682
2950
  value: null,
2683
2951
  };
@@ -2687,6 +2955,7 @@ const getTransforms = (
2687
2955
  ): TSESTree.TSNullKeyword {
2688
2956
  return {
2689
2957
  type: 'TSNullKeyword',
2958
+ loc: DUMMY_LOC,
2690
2959
  };
2691
2960
  },
2692
2961
  NullableTypeAnnotation(
@@ -2696,12 +2965,15 @@ const getTransforms = (
2696
2965
  // `?T` becomes `null | undefined | T`
2697
2966
  return {
2698
2967
  type: 'TSUnionType',
2968
+ loc: DUMMY_LOC,
2699
2969
  types: [
2700
2970
  {
2701
2971
  type: 'TSNullKeyword',
2972
+ loc: DUMMY_LOC,
2702
2973
  },
2703
2974
  {
2704
2975
  type: 'TSUndefinedKeyword',
2976
+ loc: DUMMY_LOC,
2705
2977
  },
2706
2978
  transformTypeAnnotationType(node.typeAnnotation),
2707
2979
  ],
@@ -2712,8 +2984,10 @@ const getTransforms = (
2712
2984
  ): TSESTree.TSLiteralType {
2713
2985
  return {
2714
2986
  type: 'TSLiteralType',
2987
+ loc: DUMMY_LOC,
2715
2988
  literal: ({
2716
2989
  type: 'Literal',
2990
+ loc: DUMMY_LOC,
2717
2991
  value: node.value,
2718
2992
  raw: node.raw,
2719
2993
  }: TSESTree.NumberLiteral),
@@ -2724,11 +2998,13 @@ const getTransforms = (
2724
2998
  ): TSESTree.TSNumberKeyword {
2725
2999
  return {
2726
3000
  type: 'TSNumberKeyword',
3001
+ loc: DUMMY_LOC,
2727
3002
  };
2728
3003
  },
2729
3004
  NumericLiteral(node: FlowESTree.NumericLiteral): TSESTree.NumberLiteral {
2730
3005
  return {
2731
3006
  type: 'Literal',
3007
+ loc: DUMMY_LOC,
2732
3008
  raw: node.raw,
2733
3009
  value: node.value,
2734
3010
  };
@@ -2749,10 +3025,13 @@ const getTransforms = (
2749
3025
  node.properties[0];
2750
3026
  const tsProp: TSESTree.TSMappedType = {
2751
3027
  type: 'TSMappedType',
3028
+ loc: DUMMY_LOC,
2752
3029
  typeParameter: {
2753
3030
  type: 'TSTypeParameter',
3031
+ loc: DUMMY_LOC,
2754
3032
  name: {
2755
3033
  type: 'Identifier',
3034
+ loc: DUMMY_LOC,
2756
3035
  name: prop.keyTparam.name,
2757
3036
  },
2758
3037
  constraint: transformTypeAnnotationType(prop.sourceType),
@@ -2824,6 +3103,7 @@ const getTransforms = (
2824
3103
 
2825
3104
  return {
2826
3105
  type: 'TSTypeLiteral',
3106
+ loc: DUMMY_LOC,
2827
3107
  members: tsBody,
2828
3108
  };
2829
3109
  } else {
@@ -2942,6 +3222,7 @@ const getTransforms = (
2942
3222
  .map(({node}) => node);
2943
3223
  const objectType = {
2944
3224
  type: 'TSTypeLiteral',
3225
+ loc: DUMMY_LOC,
2945
3226
  members: tsBody,
2946
3227
  };
2947
3228
 
@@ -2951,19 +3232,24 @@ const getTransforms = (
2951
3232
  const remainingTypes = typesToIntersect.slice(i + 1);
2952
3233
  intersectionMembers.push({
2953
3234
  type: 'TSTypeReference',
3235
+ loc: DUMMY_LOC,
2954
3236
  typeName: {
2955
3237
  type: 'Identifier',
3238
+ loc: DUMMY_LOC,
2956
3239
  name: 'Omit',
2957
3240
  },
2958
3241
  typeParameters: {
2959
3242
  type: 'TSTypeParameterInstantiation',
3243
+ loc: DUMMY_LOC,
2960
3244
  params: [
2961
3245
  currentType,
2962
3246
  {
2963
3247
  type: 'TSTypeOperator',
3248
+ loc: DUMMY_LOC,
2964
3249
  operator: 'keyof',
2965
3250
  typeAnnotation: {
2966
3251
  type: 'TSUnionType',
3252
+ loc: DUMMY_LOC,
2967
3253
  types: [...remainingTypes, objectType],
2968
3254
  },
2969
3255
  },
@@ -2975,6 +3261,7 @@ const getTransforms = (
2975
3261
 
2976
3262
  return {
2977
3263
  type: 'TSIntersectionType',
3264
+ loc: DUMMY_LOC,
2978
3265
  types: intersectionMembers,
2979
3266
  };
2980
3267
  }
@@ -2986,6 +3273,7 @@ const getTransforms = (
2986
3273
  const func = transform.FunctionTypeAnnotation(node.value);
2987
3274
  return {
2988
3275
  type: 'TSCallSignatureDeclaration',
3276
+ loc: DUMMY_LOC,
2989
3277
  params: func.params,
2990
3278
  returnType: func.returnType,
2991
3279
  typeParameters: func.typeParameters,
@@ -2996,12 +3284,15 @@ const getTransforms = (
2996
3284
  ): TSESTree.TSIndexSignature {
2997
3285
  return {
2998
3286
  type: 'TSIndexSignature',
3287
+ loc: DUMMY_LOC,
2999
3288
  parameters: [
3000
3289
  {
3001
3290
  type: 'Identifier',
3291
+ loc: DUMMY_LOC,
3002
3292
  name: node.id == null ? '$$Key$$' : node.id.name,
3003
3293
  typeAnnotation: {
3004
3294
  type: 'TSTypeAnnotation',
3295
+ loc: DUMMY_LOC,
3005
3296
  typeAnnotation: transformTypeAnnotationType(node.key),
3006
3297
  },
3007
3298
  },
@@ -3010,6 +3301,7 @@ const getTransforms = (
3010
3301
  static: node.static,
3011
3302
  typeAnnotation: {
3012
3303
  type: 'TSTypeAnnotation',
3304
+ loc: DUMMY_LOC,
3013
3305
  typeAnnotation: transformTypeAnnotationType(node.value),
3014
3306
  },
3015
3307
  };
@@ -3028,6 +3320,7 @@ const getTransforms = (
3028
3320
  const func = transform.FunctionTypeAnnotation(node.value);
3029
3321
  return {
3030
3322
  type: 'TSMethodSignature',
3323
+ loc: DUMMY_LOC,
3031
3324
  computed: false,
3032
3325
  key,
3033
3326
  kind: node.kind === 'init' ? 'method' : node.kind,
@@ -3045,6 +3338,7 @@ const getTransforms = (
3045
3338
  const func = transform.FunctionTypeAnnotation(node.value);
3046
3339
  return {
3047
3340
  type: 'TSMethodSignature',
3341
+ loc: DUMMY_LOC,
3048
3342
  computed: false,
3049
3343
  key,
3050
3344
  kind: node.kind,
@@ -3060,6 +3354,7 @@ const getTransforms = (
3060
3354
 
3061
3355
  return {
3062
3356
  type: 'TSPropertySignature',
3357
+ loc: DUMMY_LOC,
3063
3358
  computed: false,
3064
3359
  key,
3065
3360
  optional: node.optional,
@@ -3067,6 +3362,7 @@ const getTransforms = (
3067
3362
  static: node.static,
3068
3363
  typeAnnotation: {
3069
3364
  type: 'TSTypeAnnotation',
3365
+ loc: DUMMY_LOC,
3070
3366
  typeAnnotation: transformTypeAnnotationType(node.value),
3071
3367
  },
3072
3368
  };
@@ -3088,14 +3384,18 @@ const getTransforms = (
3088
3384
  // `T?.[K]` becomes `NonNullable<T>[K]`
3089
3385
  return {
3090
3386
  type: 'TSIndexedAccessType',
3387
+ loc: DUMMY_LOC,
3091
3388
  objectType: {
3092
3389
  type: 'TSTypeReference',
3390
+ loc: DUMMY_LOC,
3093
3391
  typeName: {
3094
3392
  type: 'Identifier',
3393
+ loc: DUMMY_LOC,
3095
3394
  name: 'NonNullable',
3096
3395
  },
3097
3396
  typeParameters: {
3098
3397
  type: 'TSTypeParameterInstantiation',
3398
+ loc: DUMMY_LOC,
3099
3399
  params: [transformTypeAnnotationType(node.objectType)],
3100
3400
  },
3101
3401
  },
@@ -3109,6 +3409,7 @@ const getTransforms = (
3109
3409
 
3110
3410
  return {
3111
3411
  type: 'TSQualifiedName',
3412
+ loc: DUMMY_LOC,
3112
3413
  left:
3113
3414
  qual.type === 'Identifier'
3114
3415
  ? transform.Identifier(qual, false)
@@ -3123,6 +3424,7 @@ const getTransforms = (
3123
3424
 
3124
3425
  return {
3125
3426
  type: 'TSQualifiedName',
3427
+ loc: DUMMY_LOC,
3126
3428
  left:
3127
3429
  qual.type === 'Identifier'
3128
3430
  ? transform.Identifier(qual, false)
@@ -3133,6 +3435,7 @@ const getTransforms = (
3133
3435
  RegExpLiteral(node: FlowESTree.RegExpLiteral): TSESTree.RegExpLiteral {
3134
3436
  return {
3135
3437
  type: 'Literal',
3438
+ loc: DUMMY_LOC,
3136
3439
  raw: node.raw,
3137
3440
  regex: {
3138
3441
  pattern: node.regex.pattern,
@@ -3144,6 +3447,7 @@ const getTransforms = (
3144
3447
  StringLiteral(node: FlowESTree.StringLiteral): TSESTree.StringLiteral {
3145
3448
  return {
3146
3449
  type: 'Literal',
3450
+ loc: DUMMY_LOC,
3147
3451
  raw: node.raw,
3148
3452
  value: node.value,
3149
3453
  };
@@ -3153,8 +3457,10 @@ const getTransforms = (
3153
3457
  ): TSESTree.TSLiteralType {
3154
3458
  return {
3155
3459
  type: 'TSLiteralType',
3460
+ loc: DUMMY_LOC,
3156
3461
  literal: ({
3157
3462
  type: 'Literal',
3463
+ loc: DUMMY_LOC,
3158
3464
  value: node.value,
3159
3465
  raw: node.raw,
3160
3466
  }: TSESTree.StringLiteral),
@@ -3165,6 +3471,7 @@ const getTransforms = (
3165
3471
  ): TSESTree.TSStringKeyword {
3166
3472
  return {
3167
3473
  type: 'TSStringKeyword',
3474
+ loc: DUMMY_LOC,
3168
3475
  };
3169
3476
  },
3170
3477
  SymbolTypeAnnotation(
@@ -3172,6 +3479,7 @@ const getTransforms = (
3172
3479
  ): TSESTree.TSSymbolKeyword {
3173
3480
  return {
3174
3481
  type: 'TSSymbolKeyword',
3482
+ loc: DUMMY_LOC,
3175
3483
  };
3176
3484
  },
3177
3485
  ThisTypeAnnotation(
@@ -3179,6 +3487,7 @@ const getTransforms = (
3179
3487
  ): TSESTree.TSThisType {
3180
3488
  return {
3181
3489
  type: 'TSThisType',
3490
+ loc: DUMMY_LOC,
3182
3491
  };
3183
3492
  },
3184
3493
  TupleTypeAnnotation(
@@ -3192,8 +3501,9 @@ const getTransforms = (
3192
3501
  element.variance != null &&
3193
3502
  element.variance.kind === 'plus',
3194
3503
  );
3195
- const tupleAnnot = {
3504
+ const tupleAnnot: TSESTree.TSTupleType = {
3196
3505
  type: 'TSTupleType',
3506
+ loc: DUMMY_LOC,
3197
3507
  elementTypes: node.types.map(element => {
3198
3508
  switch (element.type) {
3199
3509
  case 'TupleTypeLabeledElement':
@@ -3205,6 +3515,7 @@ const getTransforms = (
3205
3515
  }
3206
3516
  return {
3207
3517
  type: 'TSNamedTupleMember',
3518
+ loc: DUMMY_LOC,
3208
3519
  label: transform.Identifier(element.label),
3209
3520
  optional: element.optional,
3210
3521
  elementType: transformTypeAnnotationType(element.elementType),
@@ -3213,10 +3524,12 @@ const getTransforms = (
3213
3524
  const annot = transformTypeAnnotationType(element.typeAnnotation);
3214
3525
  return {
3215
3526
  type: 'TSRestType',
3527
+ loc: DUMMY_LOC,
3216
3528
  typeAnnotation:
3217
3529
  element.label != null
3218
3530
  ? {
3219
3531
  type: 'TSNamedTupleMember',
3532
+ loc: DUMMY_LOC,
3220
3533
  label: transform.Identifier(element.label),
3221
3534
  optional: false,
3222
3535
  elementType: annot,
@@ -3232,6 +3545,7 @@ const getTransforms = (
3232
3545
  return allReadOnly
3233
3546
  ? {
3234
3547
  type: 'TSTypeOperator',
3548
+ loc: DUMMY_LOC,
3235
3549
  operator: 'readonly',
3236
3550
  typeAnnotation: tupleAnnot,
3237
3551
  }
@@ -3243,6 +3557,7 @@ const getTransforms = (
3243
3557
  TypeAnnotation(node: FlowESTree.TypeAnnotation): TSESTree.TSTypeAnnotation {
3244
3558
  return {
3245
3559
  type: 'TSTypeAnnotation',
3560
+ loc: DUMMY_LOC,
3246
3561
  typeAnnotation: transformTypeAnnotationType(node.typeAnnotation),
3247
3562
  };
3248
3563
  },
@@ -3253,12 +3568,14 @@ const getTransforms = (
3253
3568
  case 'Identifier':
3254
3569
  return {
3255
3570
  type: 'TSTypeQuery',
3571
+ loc: DUMMY_LOC,
3256
3572
  exprName: transform.Identifier(node.argument),
3257
3573
  typeParameters: undefined,
3258
3574
  };
3259
3575
  case 'QualifiedTypeofIdentifier':
3260
3576
  return {
3261
3577
  type: 'TSTypeQuery',
3578
+ loc: DUMMY_LOC,
3262
3579
  exprName: transform.QualifiedTypeofIdentifier(node.argument),
3263
3580
  typeParameters: undefined,
3264
3581
  };
@@ -3288,8 +3605,10 @@ const getTransforms = (
3288
3605
  */
3289
3606
  return {
3290
3607
  type: 'TSTypeParameter',
3608
+ loc: DUMMY_LOC,
3291
3609
  name: {
3292
3610
  type: 'Identifier',
3611
+ loc: DUMMY_LOC,
3293
3612
  name: node.name,
3294
3613
  },
3295
3614
  constraint:
@@ -3311,6 +3630,7 @@ const getTransforms = (
3311
3630
  ): TSESTree.TSTypeParameterDeclaration {
3312
3631
  return {
3313
3632
  type: 'TSTypeParameterDeclaration',
3633
+ loc: DUMMY_LOC,
3314
3634
  params: node.params.map(transform.TypeParameter),
3315
3635
  };
3316
3636
  },
@@ -3319,6 +3639,7 @@ const getTransforms = (
3319
3639
  ): TSESTree.TSTypeParameterInstantiation {
3320
3640
  return {
3321
3641
  type: 'TSTypeParameterInstantiation',
3642
+ loc: DUMMY_LOC,
3322
3643
  params: node.params.map(transformTypeAnnotationType),
3323
3644
  };
3324
3645
  },
@@ -3327,6 +3648,7 @@ const getTransforms = (
3327
3648
  ): TSESTree.TSUnionType {
3328
3649
  return {
3329
3650
  type: 'TSUnionType',
3651
+ loc: DUMMY_LOC,
3330
3652
  types: node.types.map(transformTypeAnnotationType),
3331
3653
  };
3332
3654
  },
@@ -3335,6 +3657,7 @@ const getTransforms = (
3335
3657
  ): TSESTree.TSVoidKeyword {
3336
3658
  return {
3337
3659
  type: 'TSVoidKeyword',
3660
+ loc: DUMMY_LOC,
3338
3661
  };
3339
3662
  },
3340
3663
  ConditionalTypeAnnotation(
@@ -3342,6 +3665,7 @@ const getTransforms = (
3342
3665
  ): TSESTree.TSConditionalType {
3343
3666
  return {
3344
3667
  type: 'TSConditionalType',
3668
+ loc: DUMMY_LOC,
3345
3669
  checkType: transformTypeAnnotationType(node.checkType),
3346
3670
  extendsType: transformTypeAnnotationType(node.extendsType),
3347
3671
  trueType: transformTypeAnnotationType(node.trueType),
@@ -3353,10 +3677,12 @@ const getTransforms = (
3353
3677
  ): TSESTree.TSTypePredicate {
3354
3678
  return {
3355
3679
  type: 'TSTypePredicate',
3356
- asserts: node.asserts,
3680
+ loc: DUMMY_LOC,
3681
+ asserts: node.kind != null && node.kind === 'asserts',
3357
3682
  parameterName: transform.Identifier(node.parameterName, false),
3358
3683
  typeAnnotation: node.typeAnnotation && {
3359
3684
  type: 'TSTypeAnnotation',
3685
+ loc: DUMMY_LOC,
3360
3686
  typeAnnotation: transformTypeAnnotationType(node.typeAnnotation),
3361
3687
  },
3362
3688
  };
@@ -3366,6 +3692,7 @@ const getTransforms = (
3366
3692
  ): TSESTree.TSInferType {
3367
3693
  return {
3368
3694
  type: 'TSInferType',
3695
+ loc: DUMMY_LOC,
3369
3696
  typeParameter: transform.TypeParameter(node.typeParameter),
3370
3697
  };
3371
3698
  },
@@ -3374,6 +3701,7 @@ const getTransforms = (
3374
3701
  ): TSESTree.TSTypeOperator {
3375
3702
  return {
3376
3703
  type: 'TSTypeOperator',
3704
+ loc: DUMMY_LOC,
3377
3705
  operator: 'keyof',
3378
3706
  typeAnnotation: transformTypeAnnotationType(node.argument),
3379
3707
  };
@@ -3386,11 +3714,14 @@ const getTransforms = (
3386
3714
  const hasReactImport = isReactImport(node, 'React');
3387
3715
  return {
3388
3716
  type: 'TSTypeReference',
3717
+ loc: DUMMY_LOC,
3389
3718
  typeName: {
3390
3719
  type: 'TSQualifiedName',
3720
+ loc: DUMMY_LOC,
3391
3721
  left: getReactIdentifier(hasReactImport),
3392
3722
  right: {
3393
3723
  type: 'Identifier',
3724
+ loc: DUMMY_LOC,
3394
3725
  name: `ReactNode`,
3395
3726
  },
3396
3727
  },
@@ -3413,14 +3744,18 @@ const getTransforms = (
3413
3744
  const hasReactImport = isReactImport(node, 'React');
3414
3745
  const returnType = {
3415
3746
  type: 'TSTypeAnnotation',
3747
+ loc: DUMMY_LOC,
3416
3748
  // If no rendersType we assume its ReactNode type.
3417
3749
  typeAnnotation: {
3418
3750
  type: 'TSTypeReference',
3751
+ loc: DUMMY_LOC,
3419
3752
  typeName: {
3420
3753
  type: 'TSQualifiedName',
3754
+ loc: DUMMY_LOC,
3421
3755
  left: getReactIdentifier(hasReactImport),
3422
3756
  right: {
3423
3757
  type: 'Identifier',
3758
+ loc: DUMMY_LOC,
3424
3759
  name: `ReactNode`,
3425
3760
  },
3426
3761
  },
@@ -3430,6 +3765,7 @@ const getTransforms = (
3430
3765
 
3431
3766
  return {
3432
3767
  type: 'TSFunctionType',
3768
+ loc: DUMMY_LOC,
3433
3769
  typeParameters,
3434
3770
  params,
3435
3771
  returnType,