flow-api-translator 0.20.0 → 0.21.0
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.
- package/dist/TSDefToFlowDef.js +1812 -0
- package/dist/TSDefToFlowDef.js.flow +2030 -0
- package/dist/flowDefToTSDef.js +373 -30
- package/dist/flowDefToTSDef.js.flow +349 -14
- package/dist/index.js +34 -0
- package/dist/index.js.flow +28 -0
- package/dist/utils/ts-estree-ast-types.js.flow +11 -1
- package/package.json +8 -6
package/dist/flowDefToTSDef.js
CHANGED
|
@@ -30,6 +30,17 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
30
30
|
|
|
31
31
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
32
32
|
|
|
33
|
+
const DUMMY_LOC = {
|
|
34
|
+
start: {
|
|
35
|
+
line: 1,
|
|
36
|
+
column: 0
|
|
37
|
+
},
|
|
38
|
+
end: {
|
|
39
|
+
line: 1,
|
|
40
|
+
column: 0
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
33
44
|
function constructFlowNode(node) {
|
|
34
45
|
// $FlowFixMe[prop-missing]
|
|
35
46
|
return node;
|
|
@@ -55,6 +66,7 @@ function getReactIdentifier(hasReactImport) {
|
|
|
55
66
|
|
|
56
67
|
return {
|
|
57
68
|
type: 'Identifier',
|
|
69
|
+
loc: DUMMY_LOC,
|
|
58
70
|
name: `React`
|
|
59
71
|
};
|
|
60
72
|
}
|
|
@@ -65,6 +77,7 @@ function flowDefToTSDef(originalCode, ast, scopeManager, opts) {
|
|
|
65
77
|
type: 'Program',
|
|
66
78
|
body: tsBody,
|
|
67
79
|
sourceType: ast.sourceType,
|
|
80
|
+
loc: ast.loc,
|
|
68
81
|
docblock: ast.docblock == null ? null : (0, _DocblockUtils.removeAtFlowFromDocblock)(ast.docblock)
|
|
69
82
|
};
|
|
70
83
|
shouldAddReactImport = null;
|
|
@@ -89,15 +102,19 @@ function flowDefToTSDef(originalCode, ast, scopeManager, opts) {
|
|
|
89
102
|
tsBody.unshift({
|
|
90
103
|
type: 'ImportDeclaration',
|
|
91
104
|
assertions: [],
|
|
105
|
+
loc: DUMMY_LOC,
|
|
92
106
|
source: {
|
|
93
107
|
type: 'Literal',
|
|
108
|
+
loc: DUMMY_LOC,
|
|
94
109
|
value: 'react',
|
|
95
110
|
raw: "'react'"
|
|
96
111
|
},
|
|
97
112
|
specifiers: [{
|
|
98
113
|
type: 'ImportNamespaceSpecifier',
|
|
114
|
+
loc: DUMMY_LOC,
|
|
99
115
|
local: {
|
|
100
116
|
type: 'Identifier',
|
|
117
|
+
loc: DUMMY_LOC,
|
|
101
118
|
name: 'React'
|
|
102
119
|
}
|
|
103
120
|
}],
|
|
@@ -136,6 +153,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
136
153
|
|
|
137
154
|
const comment = {
|
|
138
155
|
type: 'Block',
|
|
156
|
+
loc: DUMMY_LOC,
|
|
139
157
|
value: `*${_os.EOL} * ${message.replace(new RegExp(_os.EOL, 'g'), `${_os.EOL} * `)}${_os.EOL}*`,
|
|
140
158
|
leading: true,
|
|
141
159
|
printed: false
|
|
@@ -143,8 +161,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
143
161
|
code = makeCommentOwnLine(code, comment); // $FlowExpectedError[prop-missing]
|
|
144
162
|
// $FlowExpectedError[cannot-write]
|
|
145
163
|
|
|
146
|
-
(_node$comments = node.comments) != null ? _node$comments : node.comments = []; // $FlowExpectedError[
|
|
147
|
-
// $FlowExpectedError[incompatible-cast]
|
|
164
|
+
(_node$comments = node.comments) != null ? _node$comments : node.comments = []; // $FlowExpectedError[incompatible-cast]
|
|
148
165
|
|
|
149
166
|
node.comments.push(comment);
|
|
150
167
|
}
|
|
@@ -155,7 +172,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
155
172
|
if (opts.recoverFromErrors) {
|
|
156
173
|
const codeFrame = buildCodeFrameForComment(node, message);
|
|
157
174
|
const newNode = {
|
|
158
|
-
type: 'TSAnyKeyword'
|
|
175
|
+
type: 'TSAnyKeyword',
|
|
176
|
+
loc: DUMMY_LOC
|
|
159
177
|
};
|
|
160
178
|
addErrorComment(newNode, codeFrame);
|
|
161
179
|
return newNode;
|
|
@@ -171,10 +189,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
171
189
|
const codeFrame = buildCodeFrameForComment(node, message);
|
|
172
190
|
const newNode = {
|
|
173
191
|
type: 'TSTypeAliasDeclaration',
|
|
192
|
+
loc: DUMMY_LOC,
|
|
174
193
|
declare,
|
|
175
194
|
id: transform.Identifier(id, false),
|
|
176
195
|
typeAnnotation: {
|
|
177
|
-
type: 'TSAnyKeyword'
|
|
196
|
+
type: 'TSAnyKeyword',
|
|
197
|
+
loc: DUMMY_LOC
|
|
178
198
|
},
|
|
179
199
|
typeParameters: typeParameters == null ? undefined : transform.TypeParameterDeclaration(typeParameters)
|
|
180
200
|
};
|
|
@@ -320,10 +340,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
320
340
|
|
|
321
341
|
members.push({
|
|
322
342
|
type: 'TSEnumMember',
|
|
343
|
+
loc: DUMMY_LOC,
|
|
323
344
|
computed: false,
|
|
324
345
|
id: transform.Identifier(member.id, false),
|
|
325
346
|
initializer: {
|
|
326
347
|
type: 'Literal',
|
|
348
|
+
loc: DUMMY_LOC,
|
|
327
349
|
raw: `"${member.id.name}"`,
|
|
328
350
|
value: member.id.name
|
|
329
351
|
}
|
|
@@ -335,6 +357,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
335
357
|
case 'EnumStringMember':
|
|
336
358
|
members.push({
|
|
337
359
|
type: 'TSEnumMember',
|
|
360
|
+
loc: DUMMY_LOC,
|
|
338
361
|
computed: false,
|
|
339
362
|
id: transform.Identifier(member.id, false),
|
|
340
363
|
initializer: member.init.literalType === 'string' ? transform.StringLiteral(member.init) : transform.NumericLiteral(member.init)
|
|
@@ -343,13 +366,16 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
343
366
|
}
|
|
344
367
|
|
|
345
368
|
const bodyRepresentationType = body.type === 'EnumNumberBody' ? {
|
|
346
|
-
type: 'TSNumberKeyword'
|
|
369
|
+
type: 'TSNumberKeyword',
|
|
370
|
+
loc: DUMMY_LOC
|
|
347
371
|
} : {
|
|
348
|
-
type: 'TSStringKeyword'
|
|
372
|
+
type: 'TSStringKeyword',
|
|
373
|
+
loc: DUMMY_LOC
|
|
349
374
|
};
|
|
350
375
|
const enumName = transform.Identifier(node.id, false);
|
|
351
376
|
return [{
|
|
352
377
|
type: 'TSEnumDeclaration',
|
|
378
|
+
loc: DUMMY_LOC,
|
|
353
379
|
const: false,
|
|
354
380
|
declare: true,
|
|
355
381
|
id: enumName,
|
|
@@ -371,17 +397,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
371
397
|
*/
|
|
372
398
|
{
|
|
373
399
|
type: 'TSModuleDeclaration',
|
|
400
|
+
loc: DUMMY_LOC,
|
|
374
401
|
declare: true,
|
|
375
402
|
id: enumName,
|
|
376
403
|
body: {
|
|
377
404
|
type: 'TSModuleBlock',
|
|
405
|
+
loc: DUMMY_LOC,
|
|
378
406
|
body: [// export function cast(value: number | null | undefined): Foo
|
|
379
407
|
{
|
|
380
408
|
type: 'ExportNamedDeclaration',
|
|
409
|
+
loc: DUMMY_LOC,
|
|
381
410
|
declaration: {
|
|
382
411
|
type: 'TSDeclareFunction',
|
|
412
|
+
loc: DUMMY_LOC,
|
|
383
413
|
id: {
|
|
384
414
|
type: 'Identifier',
|
|
415
|
+
loc: DUMMY_LOC,
|
|
385
416
|
name: 'cast'
|
|
386
417
|
},
|
|
387
418
|
generator: false,
|
|
@@ -389,23 +420,30 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
389
420
|
async: false,
|
|
390
421
|
params: [{
|
|
391
422
|
type: 'Identifier',
|
|
423
|
+
loc: DUMMY_LOC,
|
|
392
424
|
name: 'value',
|
|
393
425
|
typeAnnotation: {
|
|
394
426
|
type: 'TSTypeAnnotation',
|
|
427
|
+
loc: DUMMY_LOC,
|
|
395
428
|
typeAnnotation: {
|
|
396
429
|
type: 'TSUnionType',
|
|
430
|
+
loc: DUMMY_LOC,
|
|
397
431
|
types: [bodyRepresentationType, {
|
|
398
|
-
type: 'TSNullKeyword'
|
|
432
|
+
type: 'TSNullKeyword',
|
|
433
|
+
loc: DUMMY_LOC
|
|
399
434
|
}, {
|
|
400
|
-
type: 'TSUndefinedKeyword'
|
|
435
|
+
type: 'TSUndefinedKeyword',
|
|
436
|
+
loc: DUMMY_LOC
|
|
401
437
|
}]
|
|
402
438
|
}
|
|
403
439
|
}
|
|
404
440
|
}],
|
|
405
441
|
returnType: {
|
|
406
442
|
type: 'TSTypeAnnotation',
|
|
443
|
+
loc: DUMMY_LOC,
|
|
407
444
|
typeAnnotation: {
|
|
408
445
|
type: 'TSTypeReference',
|
|
446
|
+
loc: DUMMY_LOC,
|
|
409
447
|
typeName: enumName
|
|
410
448
|
}
|
|
411
449
|
}
|
|
@@ -417,10 +455,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
417
455
|
}, // export function isValid(value: number | null | undefined): value is Foo;
|
|
418
456
|
{
|
|
419
457
|
type: 'ExportNamedDeclaration',
|
|
458
|
+
loc: DUMMY_LOC,
|
|
420
459
|
declaration: {
|
|
421
460
|
type: 'TSDeclareFunction',
|
|
461
|
+
loc: DUMMY_LOC,
|
|
422
462
|
id: {
|
|
423
463
|
type: 'Identifier',
|
|
464
|
+
loc: DUMMY_LOC,
|
|
424
465
|
name: 'isValid'
|
|
425
466
|
},
|
|
426
467
|
generator: false,
|
|
@@ -428,32 +469,42 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
428
469
|
async: false,
|
|
429
470
|
params: [{
|
|
430
471
|
type: 'Identifier',
|
|
472
|
+
loc: DUMMY_LOC,
|
|
431
473
|
name: 'value',
|
|
432
474
|
typeAnnotation: {
|
|
433
475
|
type: 'TSTypeAnnotation',
|
|
476
|
+
loc: DUMMY_LOC,
|
|
434
477
|
typeAnnotation: {
|
|
435
478
|
type: 'TSUnionType',
|
|
479
|
+
loc: DUMMY_LOC,
|
|
436
480
|
types: [bodyRepresentationType, {
|
|
437
|
-
type: 'TSNullKeyword'
|
|
481
|
+
type: 'TSNullKeyword',
|
|
482
|
+
loc: DUMMY_LOC
|
|
438
483
|
}, {
|
|
439
|
-
type: 'TSUndefinedKeyword'
|
|
484
|
+
type: 'TSUndefinedKeyword',
|
|
485
|
+
loc: DUMMY_LOC
|
|
440
486
|
}]
|
|
441
487
|
}
|
|
442
488
|
}
|
|
443
489
|
}],
|
|
444
490
|
returnType: {
|
|
445
491
|
type: 'TSTypeAnnotation',
|
|
492
|
+
loc: DUMMY_LOC,
|
|
446
493
|
typeAnnotation: {
|
|
447
494
|
type: 'TSTypePredicate',
|
|
495
|
+
loc: DUMMY_LOC,
|
|
448
496
|
asserts: false,
|
|
449
497
|
parameterName: {
|
|
450
498
|
type: 'Identifier',
|
|
499
|
+
loc: DUMMY_LOC,
|
|
451
500
|
name: 'value'
|
|
452
501
|
},
|
|
453
502
|
typeAnnotation: {
|
|
454
503
|
type: 'TSTypeAnnotation',
|
|
504
|
+
loc: DUMMY_LOC,
|
|
455
505
|
typeAnnotation: {
|
|
456
506
|
type: 'TSTypeReference',
|
|
507
|
+
loc: DUMMY_LOC,
|
|
457
508
|
typeName: enumName
|
|
458
509
|
}
|
|
459
510
|
}
|
|
@@ -467,10 +518,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
467
518
|
}, // export function members(): IterableIterator<Foo>;
|
|
468
519
|
{
|
|
469
520
|
type: 'ExportNamedDeclaration',
|
|
521
|
+
loc: DUMMY_LOC,
|
|
470
522
|
declaration: {
|
|
471
523
|
type: 'TSDeclareFunction',
|
|
524
|
+
loc: DUMMY_LOC,
|
|
472
525
|
id: {
|
|
473
526
|
type: 'Identifier',
|
|
527
|
+
loc: DUMMY_LOC,
|
|
474
528
|
name: 'members'
|
|
475
529
|
},
|
|
476
530
|
generator: false,
|
|
@@ -479,16 +533,21 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
479
533
|
params: [],
|
|
480
534
|
returnType: {
|
|
481
535
|
type: 'TSTypeAnnotation',
|
|
536
|
+
loc: DUMMY_LOC,
|
|
482
537
|
typeAnnotation: {
|
|
483
538
|
type: 'TSTypeReference',
|
|
539
|
+
loc: DUMMY_LOC,
|
|
484
540
|
typeName: {
|
|
485
541
|
type: 'Identifier',
|
|
542
|
+
loc: DUMMY_LOC,
|
|
486
543
|
name: 'IterableIterator'
|
|
487
544
|
},
|
|
488
545
|
typeParameters: {
|
|
489
546
|
type: 'TSTypeParameterInstantiation',
|
|
547
|
+
loc: DUMMY_LOC,
|
|
490
548
|
params: [{
|
|
491
549
|
type: 'TSTypeReference',
|
|
550
|
+
loc: DUMMY_LOC,
|
|
492
551
|
typeName: enumName
|
|
493
552
|
}]
|
|
494
553
|
}
|
|
@@ -502,10 +561,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
502
561
|
}, // export function getName(value: Foo): string;
|
|
503
562
|
{
|
|
504
563
|
type: 'ExportNamedDeclaration',
|
|
564
|
+
loc: DUMMY_LOC,
|
|
505
565
|
declaration: {
|
|
506
566
|
type: 'TSDeclareFunction',
|
|
567
|
+
loc: DUMMY_LOC,
|
|
507
568
|
id: {
|
|
508
569
|
type: 'Identifier',
|
|
570
|
+
loc: DUMMY_LOC,
|
|
509
571
|
name: 'getName'
|
|
510
572
|
},
|
|
511
573
|
generator: false,
|
|
@@ -513,19 +575,24 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
513
575
|
async: false,
|
|
514
576
|
params: [{
|
|
515
577
|
type: 'Identifier',
|
|
578
|
+
loc: DUMMY_LOC,
|
|
516
579
|
name: 'value',
|
|
517
580
|
typeAnnotation: {
|
|
518
581
|
type: 'TSTypeAnnotation',
|
|
582
|
+
loc: DUMMY_LOC,
|
|
519
583
|
typeAnnotation: {
|
|
520
584
|
type: 'TSTypeReference',
|
|
585
|
+
loc: DUMMY_LOC,
|
|
521
586
|
typeName: enumName
|
|
522
587
|
}
|
|
523
588
|
}
|
|
524
589
|
}],
|
|
525
590
|
returnType: {
|
|
526
591
|
type: 'TSTypeAnnotation',
|
|
592
|
+
loc: DUMMY_LOC,
|
|
527
593
|
typeAnnotation: {
|
|
528
|
-
type: 'TSStringKeyword'
|
|
594
|
+
type: 'TSStringKeyword',
|
|
595
|
+
loc: DUMMY_LOC
|
|
529
596
|
}
|
|
530
597
|
}
|
|
531
598
|
},
|
|
@@ -658,13 +725,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
658
725
|
const transform = {
|
|
659
726
|
AnyTypeAnnotation(_node) {
|
|
660
727
|
return {
|
|
661
|
-
type: 'TSAnyKeyword'
|
|
728
|
+
type: 'TSAnyKeyword',
|
|
729
|
+
loc: DUMMY_LOC
|
|
662
730
|
};
|
|
663
731
|
},
|
|
664
732
|
|
|
665
733
|
ArrayTypeAnnotation(node) {
|
|
666
734
|
return {
|
|
667
735
|
type: 'TSArrayType',
|
|
736
|
+
loc: DUMMY_LOC,
|
|
668
737
|
elementType: transformTypeAnnotationType(node.elementType)
|
|
669
738
|
};
|
|
670
739
|
},
|
|
@@ -672,6 +741,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
672
741
|
BigIntLiteral(node) {
|
|
673
742
|
return {
|
|
674
743
|
type: 'Literal',
|
|
744
|
+
loc: DUMMY_LOC,
|
|
675
745
|
bigint: node.bigint,
|
|
676
746
|
raw: node.raw,
|
|
677
747
|
value: node.value
|
|
@@ -690,8 +760,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
690
760
|
.replace(/_/, '');
|
|
691
761
|
return {
|
|
692
762
|
type: 'TSLiteralType',
|
|
763
|
+
loc: DUMMY_LOC,
|
|
693
764
|
literal: {
|
|
694
765
|
type: 'Literal',
|
|
766
|
+
loc: DUMMY_LOC,
|
|
695
767
|
value: node.value,
|
|
696
768
|
raw: node.raw,
|
|
697
769
|
bigint
|
|
@@ -701,13 +773,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
701
773
|
|
|
702
774
|
BigIntTypeAnnotation(_node) {
|
|
703
775
|
return {
|
|
704
|
-
type: 'TSBigIntKeyword'
|
|
776
|
+
type: 'TSBigIntKeyword',
|
|
777
|
+
loc: DUMMY_LOC
|
|
705
778
|
};
|
|
706
779
|
},
|
|
707
780
|
|
|
708
781
|
BooleanLiteral(node) {
|
|
709
782
|
return {
|
|
710
783
|
type: 'Literal',
|
|
784
|
+
loc: DUMMY_LOC,
|
|
711
785
|
raw: node.raw,
|
|
712
786
|
value: node.value
|
|
713
787
|
};
|
|
@@ -716,8 +790,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
716
790
|
BooleanLiteralTypeAnnotation(node) {
|
|
717
791
|
return {
|
|
718
792
|
type: 'TSLiteralType',
|
|
793
|
+
loc: DUMMY_LOC,
|
|
719
794
|
literal: {
|
|
720
795
|
type: 'Literal',
|
|
796
|
+
loc: DUMMY_LOC,
|
|
721
797
|
value: node.value,
|
|
722
798
|
raw: node.raw
|
|
723
799
|
}
|
|
@@ -726,13 +802,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
726
802
|
|
|
727
803
|
BooleanTypeAnnotation(_node) {
|
|
728
804
|
return {
|
|
729
|
-
type: 'TSBooleanKeyword'
|
|
805
|
+
type: 'TSBooleanKeyword',
|
|
806
|
+
loc: DUMMY_LOC
|
|
730
807
|
};
|
|
731
808
|
},
|
|
732
809
|
|
|
733
810
|
ClassImplements(node) {
|
|
734
811
|
return {
|
|
735
812
|
type: 'TSClassImplements',
|
|
813
|
+
loc: DUMMY_LOC,
|
|
736
814
|
expression: transform.Identifier(node.id, false),
|
|
737
815
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterInstantiation(node.typeParameters)
|
|
738
816
|
};
|
|
@@ -771,10 +849,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
771
849
|
if (isConstructor) {
|
|
772
850
|
const newNode = {
|
|
773
851
|
type: 'MethodDefinition',
|
|
852
|
+
loc: DUMMY_LOC,
|
|
774
853
|
accessibility: undefined,
|
|
775
854
|
computed: false,
|
|
776
855
|
key: {
|
|
777
856
|
type: 'Identifier',
|
|
857
|
+
loc: DUMMY_LOC,
|
|
778
858
|
name: 'constructor'
|
|
779
859
|
},
|
|
780
860
|
kind: 'constructor',
|
|
@@ -783,6 +863,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
783
863
|
static: false,
|
|
784
864
|
value: {
|
|
785
865
|
type: 'TSEmptyBodyFunctionExpression',
|
|
866
|
+
loc: DUMMY_LOC,
|
|
786
867
|
async: false,
|
|
787
868
|
body: null,
|
|
788
869
|
declare: false,
|
|
@@ -802,6 +883,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
802
883
|
|
|
803
884
|
const newNode = {
|
|
804
885
|
type: 'MethodDefinition',
|
|
886
|
+
loc: DUMMY_LOC,
|
|
805
887
|
accessibility: member.accessibility,
|
|
806
888
|
computed: (_member$computed = member.computed) != null ? _member$computed : false,
|
|
807
889
|
key: member.key,
|
|
@@ -811,6 +893,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
811
893
|
static: (_member$static = member.static) != null ? _member$static : false,
|
|
812
894
|
value: {
|
|
813
895
|
type: 'TSEmptyBodyFunctionExpression',
|
|
896
|
+
loc: DUMMY_LOC,
|
|
814
897
|
async: false,
|
|
815
898
|
body: null,
|
|
816
899
|
declare: false,
|
|
@@ -835,6 +918,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
835
918
|
|
|
836
919
|
const newNode = {
|
|
837
920
|
type: 'PropertyDefinition',
|
|
921
|
+
loc: DUMMY_LOC,
|
|
838
922
|
accessibility: member.accessibility,
|
|
839
923
|
computed: (_member$computed2 = member.computed) != null ? _member$computed2 : false,
|
|
840
924
|
declare: false,
|
|
@@ -881,14 +965,17 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
881
965
|
const superClass = node.extends.length > 0 ? node.extends[0] : undefined;
|
|
882
966
|
return {
|
|
883
967
|
type: 'ClassDeclaration',
|
|
968
|
+
loc: DUMMY_LOC,
|
|
884
969
|
body: {
|
|
885
970
|
type: 'ClassBody',
|
|
971
|
+
loc: DUMMY_LOC,
|
|
886
972
|
body: classMembers
|
|
887
973
|
},
|
|
888
974
|
declare: true,
|
|
889
975
|
id: transform.Identifier(node.id, false),
|
|
890
976
|
implements: node.implements == null ? undefined : node.implements.map(transform.ClassImplements),
|
|
891
|
-
superClass: superClass == null ? null :
|
|
977
|
+
superClass: superClass == null ? null : // Bug: superclass.id can be qualified
|
|
978
|
+
transform.Identifier(superClass.id, false),
|
|
892
979
|
superTypeParameters: (superClass == null ? void 0 : superClass.typeParameters) == null ? undefined : transform.TypeParameterInstantiation(superClass.typeParameters),
|
|
893
980
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterDeclaration(node.typeParameters) // TODO - mixins??
|
|
894
981
|
|
|
@@ -907,8 +994,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
907
994
|
const name = declaration.id.name;
|
|
908
995
|
return [classDecl, {
|
|
909
996
|
type: 'ExportDefaultDeclaration',
|
|
997
|
+
loc: DUMMY_LOC,
|
|
910
998
|
declaration: {
|
|
911
999
|
type: 'Identifier',
|
|
1000
|
+
loc: DUMMY_LOC,
|
|
912
1001
|
name
|
|
913
1002
|
},
|
|
914
1003
|
exportKind: 'value'
|
|
@@ -922,8 +1011,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
922
1011
|
const name = declaration.id.name;
|
|
923
1012
|
return [functionDecl, {
|
|
924
1013
|
type: 'ExportDefaultDeclaration',
|
|
1014
|
+
loc: DUMMY_LOC,
|
|
925
1015
|
declaration: {
|
|
926
1016
|
type: 'Identifier',
|
|
1017
|
+
loc: DUMMY_LOC,
|
|
927
1018
|
name
|
|
928
1019
|
},
|
|
929
1020
|
exportKind: 'value'
|
|
@@ -937,8 +1028,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
937
1028
|
const name = declaration.id.name;
|
|
938
1029
|
return [functionDecl, {
|
|
939
1030
|
type: 'ExportDefaultDeclaration',
|
|
1031
|
+
loc: DUMMY_LOC,
|
|
940
1032
|
declaration: {
|
|
941
1033
|
type: 'Identifier',
|
|
1034
|
+
loc: DUMMY_LOC,
|
|
942
1035
|
name
|
|
943
1036
|
},
|
|
944
1037
|
exportKind: 'value'
|
|
@@ -952,8 +1045,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
952
1045
|
const name = declaration.id.name;
|
|
953
1046
|
return [functionDecl, {
|
|
954
1047
|
type: 'ExportDefaultDeclaration',
|
|
1048
|
+
loc: DUMMY_LOC,
|
|
955
1049
|
declaration: {
|
|
956
1050
|
type: 'Identifier',
|
|
1051
|
+
loc: DUMMY_LOC,
|
|
957
1052
|
name
|
|
958
1053
|
},
|
|
959
1054
|
exportKind: 'value'
|
|
@@ -999,8 +1094,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
999
1094
|
// there's already a variable defined to hold the type
|
|
1000
1095
|
return {
|
|
1001
1096
|
type: 'ExportDefaultDeclaration',
|
|
1097
|
+
loc: DUMMY_LOC,
|
|
1002
1098
|
declaration: {
|
|
1003
1099
|
type: 'Identifier',
|
|
1100
|
+
loc: DUMMY_LOC,
|
|
1004
1101
|
name: referencedId.name
|
|
1005
1102
|
},
|
|
1006
1103
|
exportKind: 'value'
|
|
@@ -1037,13 +1134,17 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1037
1134
|
const SPECIFIER = '$$EXPORT_DEFAULT_DECLARATION$$';
|
|
1038
1135
|
return [{
|
|
1039
1136
|
type: 'VariableDeclaration',
|
|
1137
|
+
loc: DUMMY_LOC,
|
|
1040
1138
|
declarations: [{
|
|
1041
1139
|
type: 'VariableDeclarator',
|
|
1140
|
+
loc: DUMMY_LOC,
|
|
1042
1141
|
id: {
|
|
1043
1142
|
type: 'Identifier',
|
|
1143
|
+
loc: DUMMY_LOC,
|
|
1044
1144
|
name: SPECIFIER,
|
|
1045
1145
|
typeAnnotation: {
|
|
1046
1146
|
type: 'TSTypeAnnotation',
|
|
1147
|
+
loc: DUMMY_LOC,
|
|
1047
1148
|
typeAnnotation: transformTypeAnnotationType(declaration)
|
|
1048
1149
|
}
|
|
1049
1150
|
},
|
|
@@ -1053,8 +1154,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1053
1154
|
kind: 'const'
|
|
1054
1155
|
}, {
|
|
1055
1156
|
type: 'ExportDefaultDeclaration',
|
|
1157
|
+
loc: DUMMY_LOC,
|
|
1056
1158
|
declaration: {
|
|
1057
1159
|
type: 'Identifier',
|
|
1160
|
+
loc: DUMMY_LOC,
|
|
1058
1161
|
name: SPECIFIER
|
|
1059
1162
|
},
|
|
1060
1163
|
exportKind: 'value'
|
|
@@ -1068,6 +1171,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1068
1171
|
if (node.declaration === null) {
|
|
1069
1172
|
return {
|
|
1070
1173
|
type: 'ExportNamedDeclaration',
|
|
1174
|
+
loc: DUMMY_LOC,
|
|
1071
1175
|
// flow does not currently support assertions
|
|
1072
1176
|
assertions: [],
|
|
1073
1177
|
declaration: null,
|
|
@@ -1144,6 +1248,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1144
1248
|
exportKind
|
|
1145
1249
|
}) => ({
|
|
1146
1250
|
type: 'ExportNamedDeclaration',
|
|
1251
|
+
loc: DUMMY_LOC,
|
|
1147
1252
|
// flow does not currently support assertions
|
|
1148
1253
|
assertions: [],
|
|
1149
1254
|
declaration,
|
|
@@ -1154,6 +1259,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1154
1259
|
} else {
|
|
1155
1260
|
return {
|
|
1156
1261
|
type: 'ExportNamedDeclaration',
|
|
1262
|
+
loc: DUMMY_LOC,
|
|
1157
1263
|
// flow does not currently support assertions
|
|
1158
1264
|
assertions: [],
|
|
1159
1265
|
declaration: null,
|
|
@@ -1174,14 +1280,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1174
1280
|
const hasReactImport = isReactImport(node, 'React');
|
|
1175
1281
|
const returnType = {
|
|
1176
1282
|
type: 'TSTypeAnnotation',
|
|
1283
|
+
loc: DUMMY_LOC,
|
|
1177
1284
|
// If no rendersType we assume its ReactNode type.
|
|
1178
1285
|
typeAnnotation: {
|
|
1179
1286
|
type: 'TSTypeReference',
|
|
1287
|
+
loc: DUMMY_LOC,
|
|
1180
1288
|
typeName: {
|
|
1181
1289
|
type: 'TSQualifiedName',
|
|
1290
|
+
loc: DUMMY_LOC,
|
|
1182
1291
|
left: getReactIdentifier(hasReactImport),
|
|
1183
1292
|
right: {
|
|
1184
1293
|
type: 'Identifier',
|
|
1294
|
+
loc: DUMMY_LOC,
|
|
1185
1295
|
name: `ReactNode`
|
|
1186
1296
|
}
|
|
1187
1297
|
},
|
|
@@ -1190,6 +1300,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1190
1300
|
};
|
|
1191
1301
|
return {
|
|
1192
1302
|
type: 'TSDeclareFunction',
|
|
1303
|
+
loc: DUMMY_LOC,
|
|
1193
1304
|
async: false,
|
|
1194
1305
|
body: undefined,
|
|
1195
1306
|
declare: true,
|
|
@@ -1197,6 +1308,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1197
1308
|
generator: false,
|
|
1198
1309
|
id: {
|
|
1199
1310
|
type: 'Identifier',
|
|
1311
|
+
loc: DUMMY_LOC,
|
|
1200
1312
|
name: id.name
|
|
1201
1313
|
},
|
|
1202
1314
|
params,
|
|
@@ -1209,9 +1321,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1209
1321
|
if (params.length === 0 && rest != null) {
|
|
1210
1322
|
return [{
|
|
1211
1323
|
type: 'Identifier',
|
|
1324
|
+
loc: DUMMY_LOC,
|
|
1212
1325
|
name: 'props',
|
|
1213
1326
|
typeAnnotation: {
|
|
1214
1327
|
type: 'TSTypeAnnotation',
|
|
1328
|
+
loc: DUMMY_LOC,
|
|
1215
1329
|
typeAnnotation: transformTypeAnnotationType(rest.typeAnnotation)
|
|
1216
1330
|
},
|
|
1217
1331
|
optional: false
|
|
@@ -1264,9 +1378,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1264
1378
|
}));
|
|
1265
1379
|
return [{
|
|
1266
1380
|
type: 'Identifier',
|
|
1381
|
+
loc: DUMMY_LOC,
|
|
1267
1382
|
name: 'props',
|
|
1268
1383
|
typeAnnotation: {
|
|
1269
1384
|
type: 'TSTypeAnnotation',
|
|
1385
|
+
loc: DUMMY_LOC,
|
|
1270
1386
|
typeAnnotation: tsPropsObjectType
|
|
1271
1387
|
},
|
|
1272
1388
|
optional: false
|
|
@@ -1279,6 +1395,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1279
1395
|
const functionInfo = transform.FunctionTypeAnnotation(node.id.typeAnnotation.typeAnnotation);
|
|
1280
1396
|
return {
|
|
1281
1397
|
type: 'TSDeclareFunction',
|
|
1398
|
+
loc: DUMMY_LOC,
|
|
1282
1399
|
async: false,
|
|
1283
1400
|
body: undefined,
|
|
1284
1401
|
declare: true,
|
|
@@ -1286,6 +1403,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1286
1403
|
generator: false,
|
|
1287
1404
|
id: {
|
|
1288
1405
|
type: 'Identifier',
|
|
1406
|
+
loc: DUMMY_LOC,
|
|
1289
1407
|
name: id.name
|
|
1290
1408
|
},
|
|
1291
1409
|
params: functionInfo.params,
|
|
@@ -1300,6 +1418,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1300
1418
|
const functionInfo = transform.FunctionTypeAnnotation(node.id.typeAnnotation.typeAnnotation);
|
|
1301
1419
|
return {
|
|
1302
1420
|
type: 'TSDeclareFunction',
|
|
1421
|
+
loc: DUMMY_LOC,
|
|
1303
1422
|
async: false,
|
|
1304
1423
|
body: undefined,
|
|
1305
1424
|
declare: true,
|
|
@@ -1307,6 +1426,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1307
1426
|
generator: false,
|
|
1308
1427
|
id: {
|
|
1309
1428
|
type: 'Identifier',
|
|
1429
|
+
loc: DUMMY_LOC,
|
|
1310
1430
|
name: id.name
|
|
1311
1431
|
},
|
|
1312
1432
|
params: functionInfo.params,
|
|
@@ -1324,8 +1444,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1324
1444
|
|
|
1325
1445
|
return {
|
|
1326
1446
|
type: 'TSInterfaceDeclaration',
|
|
1447
|
+
loc: DUMMY_LOC,
|
|
1327
1448
|
body: {
|
|
1328
1449
|
type: 'TSInterfaceBody',
|
|
1450
|
+
loc: DUMMY_LOC,
|
|
1329
1451
|
body: transformedBody.members
|
|
1330
1452
|
},
|
|
1331
1453
|
declare: node.type !== 'InterfaceDeclaration',
|
|
@@ -1338,6 +1460,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1338
1460
|
DeclareTypeAlias(node) {
|
|
1339
1461
|
return {
|
|
1340
1462
|
type: 'TSTypeAliasDeclaration',
|
|
1463
|
+
loc: DUMMY_LOC,
|
|
1341
1464
|
declare: node.type === 'DeclareTypeAlias',
|
|
1342
1465
|
id: transform.Identifier(node.id, false),
|
|
1343
1466
|
typeAnnotation: transformTypeAnnotationType(node.right),
|
|
@@ -1351,10 +1474,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1351
1474
|
// Examples - https://basarat.gitbook.io/typescript/main-1/nominaltyping
|
|
1352
1475
|
return {
|
|
1353
1476
|
type: 'TSTypeAliasDeclaration',
|
|
1477
|
+
loc: DUMMY_LOC,
|
|
1354
1478
|
declare: true,
|
|
1355
1479
|
id: transform.Identifier(node.id, false),
|
|
1356
1480
|
typeAnnotation: node.supertype == null ? {
|
|
1357
|
-
type: 'TSUnknownKeyword'
|
|
1481
|
+
type: 'TSUnknownKeyword',
|
|
1482
|
+
loc: DUMMY_LOC
|
|
1358
1483
|
} : transformTypeAnnotationType(node.supertype),
|
|
1359
1484
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterDeclaration(node.typeParameters)
|
|
1360
1485
|
};
|
|
@@ -1363,9 +1488,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1363
1488
|
DeclareVariable(node) {
|
|
1364
1489
|
return {
|
|
1365
1490
|
type: 'VariableDeclaration',
|
|
1491
|
+
loc: DUMMY_LOC,
|
|
1366
1492
|
declare: true,
|
|
1367
1493
|
declarations: [{
|
|
1368
1494
|
type: 'VariableDeclarator',
|
|
1495
|
+
loc: DUMMY_LOC,
|
|
1369
1496
|
declare: true,
|
|
1370
1497
|
id: transform.Identifier(node.id, true),
|
|
1371
1498
|
init: null
|
|
@@ -1403,6 +1530,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1403
1530
|
ExportAllDeclaration(node) {
|
|
1404
1531
|
return {
|
|
1405
1532
|
type: 'ExportAllDeclaration',
|
|
1533
|
+
loc: DUMMY_LOC,
|
|
1406
1534
|
// flow does not currently support import/export assertions
|
|
1407
1535
|
assertions: [],
|
|
1408
1536
|
exportKind: node.exportKind,
|
|
@@ -1416,6 +1544,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1416
1544
|
// can never have a declaration with a source
|
|
1417
1545
|
return {
|
|
1418
1546
|
type: 'ExportNamedDeclaration',
|
|
1547
|
+
loc: DUMMY_LOC,
|
|
1419
1548
|
// flow does not currently support import/export assertions
|
|
1420
1549
|
assertions: [],
|
|
1421
1550
|
declaration: null,
|
|
@@ -1459,6 +1588,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1459
1588
|
|
|
1460
1589
|
const mainExport = {
|
|
1461
1590
|
type: 'ExportNamedDeclaration',
|
|
1591
|
+
loc: DUMMY_LOC,
|
|
1462
1592
|
assertions: [],
|
|
1463
1593
|
declaration: exportedDeclaration,
|
|
1464
1594
|
exportKind: node.exportKind,
|
|
@@ -1470,6 +1600,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1470
1600
|
// for cases where there is a merged declaration, TS enforces BOTH are exported
|
|
1471
1601
|
return [mainExport, {
|
|
1472
1602
|
type: 'ExportNamedDeclaration',
|
|
1603
|
+
loc: DUMMY_LOC,
|
|
1473
1604
|
assertions: [],
|
|
1474
1605
|
declaration: mergedDeclaration,
|
|
1475
1606
|
exportKind: node.exportKind,
|
|
@@ -1484,6 +1615,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1484
1615
|
ExportSpecifier(node) {
|
|
1485
1616
|
return {
|
|
1486
1617
|
type: 'ExportSpecifier',
|
|
1618
|
+
loc: DUMMY_LOC,
|
|
1487
1619
|
exported: transform.Identifier(node.exported, false),
|
|
1488
1620
|
local: transform.Identifier(node.local, false),
|
|
1489
1621
|
// flow does not support inline exportKind for named exports
|
|
@@ -1497,9 +1629,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1497
1629
|
if (node.type === 'FunctionTypeAnnotation' && node.this != null) {
|
|
1498
1630
|
params.unshift({
|
|
1499
1631
|
type: 'Identifier',
|
|
1632
|
+
loc: DUMMY_LOC,
|
|
1500
1633
|
name: 'this',
|
|
1501
1634
|
typeAnnotation: {
|
|
1502
1635
|
type: 'TSTypeAnnotation',
|
|
1636
|
+
loc: DUMMY_LOC,
|
|
1503
1637
|
typeAnnotation: transformTypeAnnotationType(node.this.typeAnnotation)
|
|
1504
1638
|
}
|
|
1505
1639
|
});
|
|
@@ -1509,12 +1643,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1509
1643
|
const rest = node.rest;
|
|
1510
1644
|
params.push({
|
|
1511
1645
|
type: 'RestElement',
|
|
1646
|
+
loc: DUMMY_LOC,
|
|
1512
1647
|
argument: rest.name == null ? {
|
|
1513
1648
|
type: 'Identifier',
|
|
1649
|
+
loc: DUMMY_LOC,
|
|
1514
1650
|
name: '$$REST$$'
|
|
1515
1651
|
} : transform.Identifier(rest.name, false),
|
|
1516
1652
|
typeAnnotation: {
|
|
1517
1653
|
type: 'TSTypeAnnotation',
|
|
1654
|
+
loc: DUMMY_LOC,
|
|
1518
1655
|
typeAnnotation: transformTypeAnnotationType(rest.typeAnnotation)
|
|
1519
1656
|
}
|
|
1520
1657
|
});
|
|
@@ -1522,9 +1659,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1522
1659
|
|
|
1523
1660
|
return {
|
|
1524
1661
|
type: 'TSFunctionType',
|
|
1662
|
+
loc: DUMMY_LOC,
|
|
1525
1663
|
params,
|
|
1526
1664
|
returnType: {
|
|
1527
1665
|
type: 'TSTypeAnnotation',
|
|
1666
|
+
loc: DUMMY_LOC,
|
|
1528
1667
|
typeAnnotation: transformTypeAnnotationType(node.returnType)
|
|
1529
1668
|
},
|
|
1530
1669
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterDeclaration(node.typeParameters)
|
|
@@ -1534,9 +1673,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1534
1673
|
FunctionTypeParam(node, idx = 0) {
|
|
1535
1674
|
return {
|
|
1536
1675
|
type: 'Identifier',
|
|
1676
|
+
loc: DUMMY_LOC,
|
|
1537
1677
|
name: node.name == null ? `$$PARAM_${idx}$$` : node.name.name,
|
|
1538
1678
|
typeAnnotation: {
|
|
1539
1679
|
type: 'TSTypeAnnotation',
|
|
1680
|
+
loc: DUMMY_LOC,
|
|
1540
1681
|
typeAnnotation: transformTypeAnnotationType(node.typeAnnotation)
|
|
1541
1682
|
},
|
|
1542
1683
|
optional: node.optional
|
|
@@ -1626,26 +1767,34 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1626
1767
|
const params = assertHasExactlyNTypeParameters(2);
|
|
1627
1768
|
return {
|
|
1628
1769
|
type: 'TSTypeReference',
|
|
1770
|
+
loc: DUMMY_LOC,
|
|
1629
1771
|
typeName: {
|
|
1630
1772
|
type: 'Identifier',
|
|
1773
|
+
loc: DUMMY_LOC,
|
|
1631
1774
|
name: 'Pick'
|
|
1632
1775
|
},
|
|
1633
1776
|
typeParameters: {
|
|
1634
1777
|
type: 'TSTypeParameterInstantiation',
|
|
1778
|
+
loc: DUMMY_LOC,
|
|
1635
1779
|
params: [params[0], {
|
|
1636
1780
|
type: 'TSTypeReference',
|
|
1781
|
+
loc: DUMMY_LOC,
|
|
1637
1782
|
typeName: {
|
|
1638
1783
|
type: 'Identifier',
|
|
1784
|
+
loc: DUMMY_LOC,
|
|
1639
1785
|
name: 'Exclude'
|
|
1640
1786
|
},
|
|
1641
1787
|
typeParameters: {
|
|
1642
1788
|
type: 'TSTypeParameterInstantiation',
|
|
1789
|
+
loc: DUMMY_LOC,
|
|
1643
1790
|
params: [{
|
|
1644
1791
|
type: 'TSTypeOperator',
|
|
1792
|
+
loc: DUMMY_LOC,
|
|
1645
1793
|
operator: 'keyof',
|
|
1646
1794
|
typeAnnotation: params[0]
|
|
1647
1795
|
}, {
|
|
1648
1796
|
type: 'TSTypeOperator',
|
|
1797
|
+
loc: DUMMY_LOC,
|
|
1649
1798
|
operator: 'keyof',
|
|
1650
1799
|
typeAnnotation: params[1]
|
|
1651
1800
|
}]
|
|
@@ -1662,6 +1811,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1662
1811
|
const params = assertHasExactlyNTypeParameters(2);
|
|
1663
1812
|
return {
|
|
1664
1813
|
type: 'TSIndexedAccessType',
|
|
1814
|
+
loc: DUMMY_LOC,
|
|
1665
1815
|
objectType: params[0],
|
|
1666
1816
|
indexType: params[1]
|
|
1667
1817
|
};
|
|
@@ -1685,6 +1835,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1685
1835
|
|
|
1686
1836
|
return {
|
|
1687
1837
|
type: 'TSImportType',
|
|
1838
|
+
loc: DUMMY_LOC,
|
|
1688
1839
|
isTypeOf: true,
|
|
1689
1840
|
argument: moduleName,
|
|
1690
1841
|
qualifier: null,
|
|
@@ -1696,7 +1847,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1696
1847
|
{
|
|
1697
1848
|
// `$FlowFixMe` => `any`
|
|
1698
1849
|
return {
|
|
1699
|
-
type: 'TSAnyKeyword'
|
|
1850
|
+
type: 'TSAnyKeyword',
|
|
1851
|
+
loc: DUMMY_LOC
|
|
1700
1852
|
};
|
|
1701
1853
|
}
|
|
1702
1854
|
|
|
@@ -1705,14 +1857,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1705
1857
|
// `$KeyMirror<T>` => `{[K in keyof T]: K}`
|
|
1706
1858
|
return {
|
|
1707
1859
|
type: 'TSMappedType',
|
|
1860
|
+
loc: DUMMY_LOC,
|
|
1708
1861
|
typeParameter: {
|
|
1709
1862
|
type: 'TSTypeParameter',
|
|
1863
|
+
loc: DUMMY_LOC,
|
|
1710
1864
|
name: {
|
|
1711
1865
|
type: 'Identifier',
|
|
1866
|
+
loc: DUMMY_LOC,
|
|
1712
1867
|
name: 'K'
|
|
1713
1868
|
},
|
|
1714
1869
|
constraint: {
|
|
1715
1870
|
type: 'TSTypeOperator',
|
|
1871
|
+
loc: DUMMY_LOC,
|
|
1716
1872
|
operator: 'keyof',
|
|
1717
1873
|
typeAnnotation: assertHasExactlyNTypeParameters(1)[0]
|
|
1718
1874
|
},
|
|
@@ -1722,8 +1878,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1722
1878
|
nameType: null,
|
|
1723
1879
|
typeAnnotation: {
|
|
1724
1880
|
type: 'TSTypeReference',
|
|
1881
|
+
loc: DUMMY_LOC,
|
|
1725
1882
|
typeName: {
|
|
1726
1883
|
type: 'Identifier',
|
|
1884
|
+
loc: DUMMY_LOC,
|
|
1727
1885
|
name: 'K'
|
|
1728
1886
|
}
|
|
1729
1887
|
}
|
|
@@ -1735,6 +1893,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1735
1893
|
// `$Keys<T>` => `keyof T`
|
|
1736
1894
|
return {
|
|
1737
1895
|
type: 'TSTypeOperator',
|
|
1896
|
+
loc: DUMMY_LOC,
|
|
1738
1897
|
operator: 'keyof',
|
|
1739
1898
|
typeAnnotation: assertHasExactlyNTypeParameters(1)[0]
|
|
1740
1899
|
};
|
|
@@ -1746,12 +1905,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1746
1905
|
// Not a great name because `NonNullable` also excludes `undefined`
|
|
1747
1906
|
return {
|
|
1748
1907
|
type: 'TSTypeReference',
|
|
1908
|
+
loc: DUMMY_LOC,
|
|
1749
1909
|
typeName: {
|
|
1750
1910
|
type: 'Identifier',
|
|
1911
|
+
loc: DUMMY_LOC,
|
|
1751
1912
|
name: 'NonNullable'
|
|
1752
1913
|
},
|
|
1753
1914
|
typeParameters: {
|
|
1754
1915
|
type: 'TSTypeParameterInstantiation',
|
|
1916
|
+
loc: DUMMY_LOC,
|
|
1755
1917
|
params: assertHasExactlyNTypeParameters(1)
|
|
1756
1918
|
}
|
|
1757
1919
|
};
|
|
@@ -1762,12 +1924,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1762
1924
|
// `$ReadOnly<T>` => `Readonly<T>`
|
|
1763
1925
|
return {
|
|
1764
1926
|
type: 'TSTypeReference',
|
|
1927
|
+
loc: DUMMY_LOC,
|
|
1765
1928
|
typeName: {
|
|
1766
1929
|
type: 'Identifier',
|
|
1930
|
+
loc: DUMMY_LOC,
|
|
1767
1931
|
name: 'Readonly'
|
|
1768
1932
|
},
|
|
1769
1933
|
typeParameters: {
|
|
1770
1934
|
type: 'TSTypeParameterInstantiation',
|
|
1935
|
+
loc: DUMMY_LOC,
|
|
1771
1936
|
params: assertHasExactlyNTypeParameters(1)
|
|
1772
1937
|
}
|
|
1773
1938
|
};
|
|
@@ -1781,12 +1946,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1781
1946
|
// TODO - maybe a config option?
|
|
1782
1947
|
return {
|
|
1783
1948
|
type: 'TSTypeReference',
|
|
1949
|
+
loc: DUMMY_LOC,
|
|
1784
1950
|
typeName: {
|
|
1785
1951
|
type: 'Identifier',
|
|
1952
|
+
loc: DUMMY_LOC,
|
|
1786
1953
|
name: 'ReadonlyArray'
|
|
1787
1954
|
},
|
|
1788
1955
|
typeParameters: {
|
|
1789
1956
|
type: 'TSTypeParameterInstantiation',
|
|
1957
|
+
loc: DUMMY_LOC,
|
|
1790
1958
|
params: assertHasExactlyNTypeParameters(1)
|
|
1791
1959
|
}
|
|
1792
1960
|
};
|
|
@@ -1796,12 +1964,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1796
1964
|
{
|
|
1797
1965
|
return {
|
|
1798
1966
|
type: 'TSTypeReference',
|
|
1967
|
+
loc: DUMMY_LOC,
|
|
1799
1968
|
typeName: {
|
|
1800
1969
|
type: 'Identifier',
|
|
1970
|
+
loc: DUMMY_LOC,
|
|
1801
1971
|
name: 'ReadonlyMap'
|
|
1802
1972
|
},
|
|
1803
1973
|
typeParameters: {
|
|
1804
1974
|
type: 'TSTypeParameterInstantiation',
|
|
1975
|
+
loc: DUMMY_LOC,
|
|
1805
1976
|
params: assertHasExactlyNTypeParameters(2)
|
|
1806
1977
|
}
|
|
1807
1978
|
};
|
|
@@ -1811,12 +1982,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1811
1982
|
{
|
|
1812
1983
|
return {
|
|
1813
1984
|
type: 'TSTypeReference',
|
|
1985
|
+
loc: DUMMY_LOC,
|
|
1814
1986
|
typeName: {
|
|
1815
1987
|
type: 'Identifier',
|
|
1988
|
+
loc: DUMMY_LOC,
|
|
1816
1989
|
name: 'ReadonlySet'
|
|
1817
1990
|
},
|
|
1818
1991
|
typeParameters: {
|
|
1819
1992
|
type: 'TSTypeParameterInstantiation',
|
|
1993
|
+
loc: DUMMY_LOC,
|
|
1820
1994
|
params: assertHasExactlyNTypeParameters(1)
|
|
1821
1995
|
}
|
|
1822
1996
|
};
|
|
@@ -1828,9 +2002,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1828
2002
|
const transformedType = assertHasExactlyNTypeParameters(1)[0];
|
|
1829
2003
|
return {
|
|
1830
2004
|
type: 'TSIndexedAccessType',
|
|
2005
|
+
loc: DUMMY_LOC,
|
|
1831
2006
|
objectType: transformedType,
|
|
1832
2007
|
indexType: {
|
|
1833
2008
|
type: 'TSTypeOperator',
|
|
2009
|
+
loc: DUMMY_LOC,
|
|
1834
2010
|
operator: 'keyof',
|
|
1835
2011
|
typeAnnotation: transformedType
|
|
1836
2012
|
}
|
|
@@ -1848,25 +2024,32 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1848
2024
|
|
|
1849
2025
|
return {
|
|
1850
2026
|
type: 'TSConstructorType',
|
|
2027
|
+
loc: DUMMY_LOC,
|
|
1851
2028
|
abstract: false,
|
|
1852
2029
|
params: [{
|
|
1853
2030
|
type: 'RestElement',
|
|
2031
|
+
loc: DUMMY_LOC,
|
|
1854
2032
|
argument: {
|
|
1855
2033
|
type: 'Identifier',
|
|
2034
|
+
loc: DUMMY_LOC,
|
|
1856
2035
|
name: 'args'
|
|
1857
2036
|
},
|
|
1858
2037
|
typeAnnotation: {
|
|
1859
2038
|
type: 'TSTypeAnnotation',
|
|
2039
|
+
loc: DUMMY_LOC,
|
|
1860
2040
|
typeAnnotation: {
|
|
1861
2041
|
type: 'TSArrayType',
|
|
2042
|
+
loc: DUMMY_LOC,
|
|
1862
2043
|
elementType: {
|
|
1863
|
-
type: 'TSAnyKeyword'
|
|
2044
|
+
type: 'TSAnyKeyword',
|
|
2045
|
+
loc: DUMMY_LOC
|
|
1864
2046
|
}
|
|
1865
2047
|
}
|
|
1866
2048
|
}
|
|
1867
2049
|
}],
|
|
1868
2050
|
returnType: {
|
|
1869
2051
|
type: 'TSTypeAnnotation',
|
|
2052
|
+
loc: DUMMY_LOC,
|
|
1870
2053
|
typeAnnotation: param
|
|
1871
2054
|
}
|
|
1872
2055
|
};
|
|
@@ -1891,14 +2074,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1891
2074
|
const [param] = assertHasExactlyNTypeParameters(1);
|
|
1892
2075
|
return {
|
|
1893
2076
|
type: 'TSUnionType',
|
|
2077
|
+
loc: DUMMY_LOC,
|
|
1894
2078
|
types: [param, {
|
|
1895
2079
|
type: 'TSTypeReference',
|
|
2080
|
+
loc: DUMMY_LOC,
|
|
1896
2081
|
typeName: {
|
|
1897
2082
|
type: 'Identifier',
|
|
2083
|
+
loc: DUMMY_LOC,
|
|
1898
2084
|
name: 'ReadonlyArray'
|
|
1899
2085
|
},
|
|
1900
2086
|
typeParameters: {
|
|
1901
2087
|
type: 'TSTypeParameterInstantiation',
|
|
2088
|
+
loc: DUMMY_LOC,
|
|
1902
2089
|
params: [param]
|
|
1903
2090
|
}
|
|
1904
2091
|
}]
|
|
@@ -1924,16 +2111,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1924
2111
|
|
|
1925
2112
|
return {
|
|
1926
2113
|
type: 'TSTypeReference',
|
|
2114
|
+
loc: DUMMY_LOC,
|
|
1927
2115
|
typeName: {
|
|
1928
2116
|
type: 'TSQualifiedName',
|
|
2117
|
+
loc: DUMMY_LOC,
|
|
1929
2118
|
left: getReactIdentifier(hasReactImport),
|
|
1930
2119
|
right: {
|
|
1931
2120
|
type: 'Identifier',
|
|
2121
|
+
loc: DUMMY_LOC,
|
|
1932
2122
|
name: 'Component'
|
|
1933
2123
|
}
|
|
1934
2124
|
},
|
|
1935
2125
|
typeParameters: {
|
|
1936
2126
|
type: 'TSTypeParameterInstantiation',
|
|
2127
|
+
loc: DUMMY_LOC,
|
|
1937
2128
|
params: params.map(param => transformTypeAnnotationType(param))
|
|
1938
2129
|
}
|
|
1939
2130
|
};
|
|
@@ -1945,16 +2136,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1945
2136
|
case 'React.Context':
|
|
1946
2137
|
return {
|
|
1947
2138
|
type: 'TSTypeReference',
|
|
2139
|
+
loc: DUMMY_LOC,
|
|
1948
2140
|
typeName: {
|
|
1949
2141
|
type: 'TSQualifiedName',
|
|
2142
|
+
loc: DUMMY_LOC,
|
|
1950
2143
|
left: getReactIdentifier(hasReactImport),
|
|
1951
2144
|
right: {
|
|
1952
2145
|
type: 'Identifier',
|
|
2146
|
+
loc: DUMMY_LOC,
|
|
1953
2147
|
name: `Context`
|
|
1954
2148
|
}
|
|
1955
2149
|
},
|
|
1956
2150
|
typeParameters: {
|
|
1957
2151
|
type: 'TSTypeParameterInstantiation',
|
|
2152
|
+
loc: DUMMY_LOC,
|
|
1958
2153
|
params: assertHasExactlyNTypeParameters(1)
|
|
1959
2154
|
}
|
|
1960
2155
|
};
|
|
@@ -1966,11 +2161,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1966
2161
|
assertHasExactlyNTypeParameters(0);
|
|
1967
2162
|
return {
|
|
1968
2163
|
type: 'TSTypeReference',
|
|
2164
|
+
loc: DUMMY_LOC,
|
|
1969
2165
|
typeName: {
|
|
1970
2166
|
type: 'TSQualifiedName',
|
|
2167
|
+
loc: DUMMY_LOC,
|
|
1971
2168
|
left: getReactIdentifier(hasReactImport),
|
|
1972
2169
|
right: {
|
|
1973
2170
|
type: 'Identifier',
|
|
2171
|
+
loc: DUMMY_LOC,
|
|
1974
2172
|
name: 'Key'
|
|
1975
2173
|
}
|
|
1976
2174
|
}
|
|
@@ -1984,11 +2182,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
1984
2182
|
assertHasExactlyNTypeParameters(0);
|
|
1985
2183
|
return {
|
|
1986
2184
|
type: 'TSTypeReference',
|
|
2185
|
+
loc: DUMMY_LOC,
|
|
1987
2186
|
typeName: {
|
|
1988
2187
|
type: 'TSQualifiedName',
|
|
2188
|
+
loc: DUMMY_LOC,
|
|
1989
2189
|
left: getReactIdentifier(hasReactImport),
|
|
1990
2190
|
right: {
|
|
1991
2191
|
type: 'Identifier',
|
|
2192
|
+
loc: DUMMY_LOC,
|
|
1992
2193
|
name: `ElementType`
|
|
1993
2194
|
}
|
|
1994
2195
|
},
|
|
@@ -2003,11 +2204,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2003
2204
|
assertHasExactlyNTypeParameters(0);
|
|
2004
2205
|
return {
|
|
2005
2206
|
type: 'TSTypeReference',
|
|
2207
|
+
loc: DUMMY_LOC,
|
|
2006
2208
|
typeName: {
|
|
2007
2209
|
type: 'TSQualifiedName',
|
|
2210
|
+
loc: DUMMY_LOC,
|
|
2008
2211
|
left: getReactIdentifier(hasReactImport),
|
|
2009
2212
|
right: {
|
|
2010
2213
|
type: 'Identifier',
|
|
2214
|
+
loc: DUMMY_LOC,
|
|
2011
2215
|
name: `ReactNode`
|
|
2012
2216
|
}
|
|
2013
2217
|
},
|
|
@@ -2021,16 +2225,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2021
2225
|
{
|
|
2022
2226
|
return {
|
|
2023
2227
|
type: 'TSTypeReference',
|
|
2228
|
+
loc: DUMMY_LOC,
|
|
2024
2229
|
typeName: {
|
|
2025
2230
|
type: 'TSQualifiedName',
|
|
2231
|
+
loc: DUMMY_LOC,
|
|
2026
2232
|
left: getReactIdentifier(hasReactImport),
|
|
2027
2233
|
right: {
|
|
2028
2234
|
type: 'Identifier',
|
|
2235
|
+
loc: DUMMY_LOC,
|
|
2029
2236
|
name: `ReactElement`
|
|
2030
2237
|
}
|
|
2031
2238
|
},
|
|
2032
2239
|
typeParameters: {
|
|
2033
2240
|
type: 'TSTypeParameterInstantiation',
|
|
2241
|
+
loc: DUMMY_LOC,
|
|
2034
2242
|
params: assertHasExactlyNTypeParameters(1)
|
|
2035
2243
|
}
|
|
2036
2244
|
};
|
|
@@ -2042,16 +2250,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2042
2250
|
case 'React.ElementRef':
|
|
2043
2251
|
return {
|
|
2044
2252
|
type: 'TSTypeReference',
|
|
2253
|
+
loc: DUMMY_LOC,
|
|
2045
2254
|
typeName: {
|
|
2046
2255
|
type: 'TSQualifiedName',
|
|
2256
|
+
loc: DUMMY_LOC,
|
|
2047
2257
|
left: getReactIdentifier(hasReactImport),
|
|
2048
2258
|
right: {
|
|
2049
2259
|
type: 'Identifier',
|
|
2260
|
+
loc: DUMMY_LOC,
|
|
2050
2261
|
name: `ElementRef`
|
|
2051
2262
|
}
|
|
2052
2263
|
},
|
|
2053
2264
|
typeParameters: {
|
|
2054
2265
|
type: 'TSTypeParameterInstantiation',
|
|
2266
|
+
loc: DUMMY_LOC,
|
|
2055
2267
|
params: assertHasExactlyNTypeParameters(1)
|
|
2056
2268
|
}
|
|
2057
2269
|
};
|
|
@@ -2063,11 +2275,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2063
2275
|
assertHasExactlyNTypeParameters(0);
|
|
2064
2276
|
return {
|
|
2065
2277
|
type: 'TSTypeReference',
|
|
2278
|
+
loc: DUMMY_LOC,
|
|
2066
2279
|
typeName: {
|
|
2067
2280
|
type: 'TSQualifiedName',
|
|
2281
|
+
loc: DUMMY_LOC,
|
|
2068
2282
|
left: getReactIdentifier(hasReactImport),
|
|
2069
2283
|
right: {
|
|
2070
2284
|
type: 'Identifier',
|
|
2285
|
+
loc: DUMMY_LOC,
|
|
2071
2286
|
name: `Fragment`
|
|
2072
2287
|
}
|
|
2073
2288
|
}
|
|
@@ -2080,14 +2295,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2080
2295
|
assertHasExactlyNTypeParameters(0);
|
|
2081
2296
|
return {
|
|
2082
2297
|
type: 'TSTypeReference',
|
|
2298
|
+
loc: DUMMY_LOC,
|
|
2083
2299
|
typeName: {
|
|
2084
2300
|
type: 'TSQualifiedName',
|
|
2301
|
+
loc: DUMMY_LOC,
|
|
2085
2302
|
left: {
|
|
2086
2303
|
type: 'Identifier',
|
|
2304
|
+
loc: DUMMY_LOC,
|
|
2087
2305
|
name: 'JSX'
|
|
2088
2306
|
},
|
|
2089
2307
|
right: {
|
|
2090
2308
|
type: 'Identifier',
|
|
2309
|
+
loc: DUMMY_LOC,
|
|
2091
2310
|
name: 'Element'
|
|
2092
2311
|
}
|
|
2093
2312
|
},
|
|
@@ -2102,16 +2321,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2102
2321
|
{
|
|
2103
2322
|
return {
|
|
2104
2323
|
type: 'TSTypeReference',
|
|
2324
|
+
loc: DUMMY_LOC,
|
|
2105
2325
|
typeName: {
|
|
2106
2326
|
type: 'TSQualifiedName',
|
|
2327
|
+
loc: DUMMY_LOC,
|
|
2107
2328
|
left: getReactIdentifier(hasReactImport),
|
|
2108
2329
|
right: {
|
|
2109
2330
|
type: 'Identifier',
|
|
2331
|
+
loc: DUMMY_LOC,
|
|
2110
2332
|
name: 'ComponentType'
|
|
2111
2333
|
}
|
|
2112
2334
|
},
|
|
2113
2335
|
typeParameters: {
|
|
2114
2336
|
type: 'TSTypeParameterInstantiation',
|
|
2337
|
+
loc: DUMMY_LOC,
|
|
2115
2338
|
params: assertHasExactlyNTypeParameters(1)
|
|
2116
2339
|
}
|
|
2117
2340
|
};
|
|
@@ -2144,21 +2367,27 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2144
2367
|
const [props, ref] = assertHasExactlyNTypeParameters(2);
|
|
2145
2368
|
return [{
|
|
2146
2369
|
type: 'TSIntersectionType',
|
|
2370
|
+
loc: DUMMY_LOC,
|
|
2147
2371
|
types: [props, {
|
|
2148
2372
|
type: 'TSTypeReference',
|
|
2373
|
+
loc: DUMMY_LOC,
|
|
2149
2374
|
typeName: {
|
|
2150
2375
|
type: 'TSQualifiedName',
|
|
2376
|
+
loc: DUMMY_LOC,
|
|
2151
2377
|
left: {
|
|
2152
2378
|
type: 'Identifier',
|
|
2379
|
+
loc: DUMMY_LOC,
|
|
2153
2380
|
name: 'React'
|
|
2154
2381
|
},
|
|
2155
2382
|
right: {
|
|
2156
2383
|
type: 'Identifier',
|
|
2384
|
+
loc: DUMMY_LOC,
|
|
2157
2385
|
name: 'RefAttributes'
|
|
2158
2386
|
}
|
|
2159
2387
|
},
|
|
2160
2388
|
typeParameters: {
|
|
2161
2389
|
type: 'TSTypeParameterInstantiation',
|
|
2390
|
+
loc: DUMMY_LOC,
|
|
2162
2391
|
params: [ref]
|
|
2163
2392
|
}
|
|
2164
2393
|
}]
|
|
@@ -2167,16 +2396,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2167
2396
|
|
|
2168
2397
|
return {
|
|
2169
2398
|
type: 'TSTypeReference',
|
|
2399
|
+
loc: DUMMY_LOC,
|
|
2170
2400
|
typeName: {
|
|
2171
2401
|
type: 'TSQualifiedName',
|
|
2402
|
+
loc: DUMMY_LOC,
|
|
2172
2403
|
left: getReactIdentifier(hasReactImport),
|
|
2173
2404
|
right: {
|
|
2174
2405
|
type: 'Identifier',
|
|
2406
|
+
loc: DUMMY_LOC,
|
|
2175
2407
|
name: 'ComponentType'
|
|
2176
2408
|
}
|
|
2177
2409
|
},
|
|
2178
2410
|
typeParameters: {
|
|
2179
2411
|
type: 'TSTypeParameterInstantiation',
|
|
2412
|
+
loc: DUMMY_LOC,
|
|
2180
2413
|
params: newParams
|
|
2181
2414
|
}
|
|
2182
2415
|
};
|
|
@@ -2189,16 +2422,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2189
2422
|
{
|
|
2190
2423
|
return {
|
|
2191
2424
|
type: 'TSTypeReference',
|
|
2425
|
+
loc: DUMMY_LOC,
|
|
2192
2426
|
typeName: {
|
|
2193
2427
|
type: 'TSQualifiedName',
|
|
2428
|
+
loc: DUMMY_LOC,
|
|
2194
2429
|
left: getReactIdentifier(hasReactImport),
|
|
2195
2430
|
right: {
|
|
2196
2431
|
type: 'Identifier',
|
|
2432
|
+
loc: DUMMY_LOC,
|
|
2197
2433
|
name: 'ComponentProps'
|
|
2198
2434
|
}
|
|
2199
2435
|
},
|
|
2200
2436
|
typeParameters: {
|
|
2201
2437
|
type: 'TSTypeParameterInstantiation',
|
|
2438
|
+
loc: DUMMY_LOC,
|
|
2202
2439
|
params: assertHasExactlyNTypeParameters(1)
|
|
2203
2440
|
}
|
|
2204
2441
|
};
|
|
@@ -2212,31 +2449,40 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2212
2449
|
const [param] = assertHasExactlyNTypeParameters(1);
|
|
2213
2450
|
return {
|
|
2214
2451
|
type: 'TSTypeReference',
|
|
2452
|
+
loc: DUMMY_LOC,
|
|
2215
2453
|
typeName: {
|
|
2216
2454
|
type: 'TSQualifiedName',
|
|
2455
|
+
loc: DUMMY_LOC,
|
|
2217
2456
|
left: {
|
|
2218
2457
|
type: 'Identifier',
|
|
2458
|
+
loc: DUMMY_LOC,
|
|
2219
2459
|
name: 'JSX'
|
|
2220
2460
|
},
|
|
2221
2461
|
right: {
|
|
2222
2462
|
type: 'Identifier',
|
|
2463
|
+
loc: DUMMY_LOC,
|
|
2223
2464
|
name: 'LibraryManagedAttributes'
|
|
2224
2465
|
}
|
|
2225
2466
|
},
|
|
2226
2467
|
typeParameters: {
|
|
2227
2468
|
type: 'TSTypeParameterInstantiation',
|
|
2469
|
+
loc: DUMMY_LOC,
|
|
2228
2470
|
params: [param, {
|
|
2229
2471
|
type: 'TSTypeReference',
|
|
2472
|
+
loc: DUMMY_LOC,
|
|
2230
2473
|
typeName: {
|
|
2231
2474
|
type: 'TSQualifiedName',
|
|
2475
|
+
loc: DUMMY_LOC,
|
|
2232
2476
|
left: getReactIdentifier(hasReactImport),
|
|
2233
2477
|
right: {
|
|
2234
2478
|
type: 'Identifier',
|
|
2479
|
+
loc: DUMMY_LOC,
|
|
2235
2480
|
name: `ComponentProps`
|
|
2236
2481
|
}
|
|
2237
2482
|
},
|
|
2238
2483
|
typeParameters: {
|
|
2239
2484
|
type: 'TSTypeParameterInstantiation',
|
|
2485
|
+
loc: DUMMY_LOC,
|
|
2240
2486
|
params: [param]
|
|
2241
2487
|
}
|
|
2242
2488
|
}]
|
|
@@ -2250,32 +2496,42 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2250
2496
|
case 'React$Ref':
|
|
2251
2497
|
return {
|
|
2252
2498
|
type: 'TSTypeReference',
|
|
2499
|
+
loc: DUMMY_LOC,
|
|
2253
2500
|
typeName: {
|
|
2254
2501
|
type: 'Identifier',
|
|
2502
|
+
loc: DUMMY_LOC,
|
|
2255
2503
|
name: 'NonNullable'
|
|
2256
2504
|
},
|
|
2257
2505
|
typeParameters: {
|
|
2258
2506
|
type: 'TSTypeParameterInstantiation',
|
|
2507
|
+
loc: DUMMY_LOC,
|
|
2259
2508
|
params: [{
|
|
2260
2509
|
type: 'TSUnionType',
|
|
2510
|
+
loc: DUMMY_LOC,
|
|
2261
2511
|
types: [{
|
|
2262
2512
|
type: 'TSTypeReference',
|
|
2513
|
+
loc: DUMMY_LOC,
|
|
2263
2514
|
typeName: {
|
|
2264
2515
|
type: 'TSQualifiedName',
|
|
2516
|
+
loc: DUMMY_LOC,
|
|
2265
2517
|
left: getReactIdentifier(hasReactImport),
|
|
2266
2518
|
right: {
|
|
2267
2519
|
type: 'Identifier',
|
|
2520
|
+
loc: DUMMY_LOC,
|
|
2268
2521
|
name: 'Ref'
|
|
2269
2522
|
}
|
|
2270
2523
|
},
|
|
2271
2524
|
typeParameters: {
|
|
2272
2525
|
type: 'TSTypeParameterInstantiation',
|
|
2526
|
+
loc: DUMMY_LOC,
|
|
2273
2527
|
params: assertHasExactlyNTypeParameters(1)
|
|
2274
2528
|
}
|
|
2275
2529
|
}, {
|
|
2276
|
-
type: 'TSStringKeyword'
|
|
2530
|
+
type: 'TSStringKeyword',
|
|
2531
|
+
loc: DUMMY_LOC
|
|
2277
2532
|
}, {
|
|
2278
|
-
type: 'TSNumberKeyword'
|
|
2533
|
+
type: 'TSNumberKeyword',
|
|
2534
|
+
loc: DUMMY_LOC
|
|
2279
2535
|
}]
|
|
2280
2536
|
}]
|
|
2281
2537
|
}
|
|
@@ -2288,6 +2544,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2288
2544
|
|
|
2289
2545
|
return {
|
|
2290
2546
|
type: 'TSTypeReference',
|
|
2547
|
+
loc: DUMMY_LOC,
|
|
2291
2548
|
typeName: node.id.type === 'Identifier' ? transform.Identifier(node.id, false) : transform.QualifiedTypeIdentifier(node.id),
|
|
2292
2549
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterInstantiation(node.typeParameters)
|
|
2293
2550
|
};
|
|
@@ -2296,6 +2553,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2296
2553
|
Identifier(node, includeTypeAnnotation = true) {
|
|
2297
2554
|
return {
|
|
2298
2555
|
type: 'Identifier',
|
|
2556
|
+
loc: DUMMY_LOC,
|
|
2299
2557
|
name: node.name,
|
|
2300
2558
|
...(includeTypeAnnotation && node.typeAnnotation != null ? {
|
|
2301
2559
|
typeAnnotation: transform.TypeAnnotation(node.typeAnnotation)
|
|
@@ -2306,6 +2564,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2306
2564
|
IndexedAccessType(node) {
|
|
2307
2565
|
return {
|
|
2308
2566
|
type: 'TSIndexedAccessType',
|
|
2567
|
+
loc: DUMMY_LOC,
|
|
2309
2568
|
objectType: transformTypeAnnotationType(node.objectType),
|
|
2310
2569
|
indexType: transformTypeAnnotationType(node.indexType)
|
|
2311
2570
|
};
|
|
@@ -2318,6 +2577,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2318
2577
|
ImportAttribute(node) {
|
|
2319
2578
|
return {
|
|
2320
2579
|
type: 'ImportAttribute',
|
|
2580
|
+
loc: DUMMY_LOC,
|
|
2321
2581
|
key: node.key.type === 'Identifier' ? transform.Identifier(node.key) : transform.Literal(node.key),
|
|
2322
2582
|
value: transform.Literal(node.value)
|
|
2323
2583
|
};
|
|
@@ -2332,13 +2592,16 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2332
2592
|
if (node.importKind === 'typeof' || spec.importKind === 'typeof') {
|
|
2333
2593
|
const id = {
|
|
2334
2594
|
type: 'Identifier',
|
|
2595
|
+
loc: DUMMY_LOC,
|
|
2335
2596
|
name: getPlaceholderNameForTypeofImport()
|
|
2336
2597
|
};
|
|
2337
2598
|
unsupportedSpecifiers.push({
|
|
2338
2599
|
type: 'TSTypeAliasDeclaration',
|
|
2600
|
+
loc: DUMMY_LOC,
|
|
2339
2601
|
id: transform.Identifier(spec.local, false),
|
|
2340
2602
|
typeAnnotation: {
|
|
2341
2603
|
type: 'TSTypeQuery',
|
|
2604
|
+
loc: DUMMY_LOC,
|
|
2342
2605
|
exprName: id
|
|
2343
2606
|
}
|
|
2344
2607
|
});
|
|
@@ -2352,6 +2615,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2352
2615
|
case 'ImportDefaultSpecifier':
|
|
2353
2616
|
specifiers.push({
|
|
2354
2617
|
type: 'ImportDefaultSpecifier',
|
|
2618
|
+
loc: DUMMY_LOC,
|
|
2355
2619
|
local: id
|
|
2356
2620
|
});
|
|
2357
2621
|
return;
|
|
@@ -2359,6 +2623,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2359
2623
|
case 'ImportNamespaceSpecifier':
|
|
2360
2624
|
specifiers.push({
|
|
2361
2625
|
type: 'ImportNamespaceSpecifier',
|
|
2626
|
+
loc: DUMMY_LOC,
|
|
2362
2627
|
local: id
|
|
2363
2628
|
});
|
|
2364
2629
|
return;
|
|
@@ -2366,6 +2631,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2366
2631
|
case 'ImportSpecifier':
|
|
2367
2632
|
specifiers.push({
|
|
2368
2633
|
type: 'ImportSpecifier',
|
|
2634
|
+
loc: DUMMY_LOC,
|
|
2369
2635
|
importKind: spec.importKind === 'typeof' || spec.importKind === 'type' ? 'type' : null,
|
|
2370
2636
|
imported: transform.Identifier(spec.imported, false),
|
|
2371
2637
|
local: id
|
|
@@ -2375,6 +2641,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2375
2641
|
});
|
|
2376
2642
|
const out = specifiers.length ? [{
|
|
2377
2643
|
type: 'ImportDeclaration',
|
|
2644
|
+
loc: DUMMY_LOC,
|
|
2378
2645
|
assertions: node.assertions.map(transform.ImportAttribute),
|
|
2379
2646
|
importKind: importKind === 'typeof' ? 'type' : importKind != null ? importKind : 'value',
|
|
2380
2647
|
source: transform.StringLiteral(node.source),
|
|
@@ -2386,6 +2653,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2386
2653
|
InterfaceExtends(node) {
|
|
2387
2654
|
return {
|
|
2388
2655
|
type: 'TSInterfaceHeritage',
|
|
2656
|
+
loc: DUMMY_LOC,
|
|
2657
|
+
// Bug: node.id can be qualified
|
|
2389
2658
|
expression: transform.Identifier(node.id, false),
|
|
2390
2659
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterInstantiation(node.typeParameters)
|
|
2391
2660
|
};
|
|
@@ -2398,8 +2667,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2398
2667
|
// type T = U & V & { ... }
|
|
2399
2668
|
return {
|
|
2400
2669
|
type: 'TSIntersectionType',
|
|
2670
|
+
loc: DUMMY_LOC,
|
|
2401
2671
|
types: [...node.extends.map(ex => ({
|
|
2402
2672
|
type: 'TSTypeReference',
|
|
2673
|
+
loc: DUMMY_LOC,
|
|
2674
|
+
// Bug: ex.id can be qualified
|
|
2403
2675
|
typeName: transform.Identifier(ex.id, false),
|
|
2404
2676
|
typeParameters: ex.typeParameters == null ? undefined : transform.TypeParameterInstantiation(ex.typeParameters)
|
|
2405
2677
|
})), transform.ObjectTypeAnnotation(node.body)]
|
|
@@ -2412,6 +2684,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2412
2684
|
IntersectionTypeAnnotation(node) {
|
|
2413
2685
|
return {
|
|
2414
2686
|
type: 'TSIntersectionType',
|
|
2687
|
+
loc: DUMMY_LOC,
|
|
2415
2688
|
types: node.types.map(transformTypeAnnotationType)
|
|
2416
2689
|
};
|
|
2417
2690
|
},
|
|
@@ -2440,13 +2713,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2440
2713
|
|
|
2441
2714
|
MixedTypeAnnotation(_node) {
|
|
2442
2715
|
return {
|
|
2443
|
-
type: 'TSUnknownKeyword'
|
|
2716
|
+
type: 'TSUnknownKeyword',
|
|
2717
|
+
loc: DUMMY_LOC
|
|
2444
2718
|
};
|
|
2445
2719
|
},
|
|
2446
2720
|
|
|
2447
2721
|
NullLiteral(_node) {
|
|
2448
2722
|
return {
|
|
2449
2723
|
type: 'Literal',
|
|
2724
|
+
loc: DUMMY_LOC,
|
|
2450
2725
|
raw: 'null',
|
|
2451
2726
|
value: null
|
|
2452
2727
|
};
|
|
@@ -2454,7 +2729,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2454
2729
|
|
|
2455
2730
|
NullLiteralTypeAnnotation(_node) {
|
|
2456
2731
|
return {
|
|
2457
|
-
type: 'TSNullKeyword'
|
|
2732
|
+
type: 'TSNullKeyword',
|
|
2733
|
+
loc: DUMMY_LOC
|
|
2458
2734
|
};
|
|
2459
2735
|
},
|
|
2460
2736
|
|
|
@@ -2463,10 +2739,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2463
2739
|
// `?T` becomes `null | undefined | T`
|
|
2464
2740
|
return {
|
|
2465
2741
|
type: 'TSUnionType',
|
|
2742
|
+
loc: DUMMY_LOC,
|
|
2466
2743
|
types: [{
|
|
2467
|
-
type: 'TSNullKeyword'
|
|
2744
|
+
type: 'TSNullKeyword',
|
|
2745
|
+
loc: DUMMY_LOC
|
|
2468
2746
|
}, {
|
|
2469
|
-
type: 'TSUndefinedKeyword'
|
|
2747
|
+
type: 'TSUndefinedKeyword',
|
|
2748
|
+
loc: DUMMY_LOC
|
|
2470
2749
|
}, transformTypeAnnotationType(node.typeAnnotation)]
|
|
2471
2750
|
};
|
|
2472
2751
|
},
|
|
@@ -2474,8 +2753,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2474
2753
|
NumberLiteralTypeAnnotation(node) {
|
|
2475
2754
|
return {
|
|
2476
2755
|
type: 'TSLiteralType',
|
|
2756
|
+
loc: DUMMY_LOC,
|
|
2477
2757
|
literal: {
|
|
2478
2758
|
type: 'Literal',
|
|
2759
|
+
loc: DUMMY_LOC,
|
|
2479
2760
|
value: node.value,
|
|
2480
2761
|
raw: node.raw
|
|
2481
2762
|
}
|
|
@@ -2484,13 +2765,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2484
2765
|
|
|
2485
2766
|
NumberTypeAnnotation(_node) {
|
|
2486
2767
|
return {
|
|
2487
|
-
type: 'TSNumberKeyword'
|
|
2768
|
+
type: 'TSNumberKeyword',
|
|
2769
|
+
loc: DUMMY_LOC
|
|
2488
2770
|
};
|
|
2489
2771
|
},
|
|
2490
2772
|
|
|
2491
2773
|
NumericLiteral(node) {
|
|
2492
2774
|
return {
|
|
2493
2775
|
type: 'Literal',
|
|
2776
|
+
loc: DUMMY_LOC,
|
|
2494
2777
|
raw: node.raw,
|
|
2495
2778
|
value: node.value
|
|
2496
2779
|
};
|
|
@@ -2504,10 +2787,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2504
2787
|
const prop = node.properties[0];
|
|
2505
2788
|
const tsProp = {
|
|
2506
2789
|
type: 'TSMappedType',
|
|
2790
|
+
loc: DUMMY_LOC,
|
|
2507
2791
|
typeParameter: {
|
|
2508
2792
|
type: 'TSTypeParameter',
|
|
2793
|
+
loc: DUMMY_LOC,
|
|
2509
2794
|
name: {
|
|
2510
2795
|
type: 'Identifier',
|
|
2796
|
+
loc: DUMMY_LOC,
|
|
2511
2797
|
name: prop.keyTparam.name
|
|
2512
2798
|
},
|
|
2513
2799
|
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
@@ -2575,6 +2861,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2575
2861
|
}) => node);
|
|
2576
2862
|
return {
|
|
2577
2863
|
type: 'TSTypeLiteral',
|
|
2864
|
+
loc: DUMMY_LOC,
|
|
2578
2865
|
members: tsBody
|
|
2579
2866
|
};
|
|
2580
2867
|
} else {
|
|
@@ -2674,6 +2961,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2674
2961
|
}) => node);
|
|
2675
2962
|
const objectType = {
|
|
2676
2963
|
type: 'TSTypeLiteral',
|
|
2964
|
+
loc: DUMMY_LOC,
|
|
2677
2965
|
members: tsBody
|
|
2678
2966
|
};
|
|
2679
2967
|
const intersectionMembers = [];
|
|
@@ -2683,17 +2971,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2683
2971
|
const remainingTypes = typesToIntersect.slice(i + 1);
|
|
2684
2972
|
intersectionMembers.push({
|
|
2685
2973
|
type: 'TSTypeReference',
|
|
2974
|
+
loc: DUMMY_LOC,
|
|
2686
2975
|
typeName: {
|
|
2687
2976
|
type: 'Identifier',
|
|
2977
|
+
loc: DUMMY_LOC,
|
|
2688
2978
|
name: 'Omit'
|
|
2689
2979
|
},
|
|
2690
2980
|
typeParameters: {
|
|
2691
2981
|
type: 'TSTypeParameterInstantiation',
|
|
2982
|
+
loc: DUMMY_LOC,
|
|
2692
2983
|
params: [currentType, {
|
|
2693
2984
|
type: 'TSTypeOperator',
|
|
2985
|
+
loc: DUMMY_LOC,
|
|
2694
2986
|
operator: 'keyof',
|
|
2695
2987
|
typeAnnotation: {
|
|
2696
2988
|
type: 'TSUnionType',
|
|
2989
|
+
loc: DUMMY_LOC,
|
|
2697
2990
|
types: [...remainingTypes, objectType]
|
|
2698
2991
|
}
|
|
2699
2992
|
}]
|
|
@@ -2704,6 +2997,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2704
2997
|
intersectionMembers.push(objectType);
|
|
2705
2998
|
return {
|
|
2706
2999
|
type: 'TSIntersectionType',
|
|
3000
|
+
loc: DUMMY_LOC,
|
|
2707
3001
|
types: intersectionMembers
|
|
2708
3002
|
};
|
|
2709
3003
|
}
|
|
@@ -2714,6 +3008,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2714
3008
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2715
3009
|
return {
|
|
2716
3010
|
type: 'TSCallSignatureDeclaration',
|
|
3011
|
+
loc: DUMMY_LOC,
|
|
2717
3012
|
params: func.params,
|
|
2718
3013
|
returnType: func.returnType,
|
|
2719
3014
|
typeParameters: func.typeParameters
|
|
@@ -2725,11 +3020,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2725
3020
|
|
|
2726
3021
|
return {
|
|
2727
3022
|
type: 'TSIndexSignature',
|
|
3023
|
+
loc: DUMMY_LOC,
|
|
2728
3024
|
parameters: [{
|
|
2729
3025
|
type: 'Identifier',
|
|
3026
|
+
loc: DUMMY_LOC,
|
|
2730
3027
|
name: node.id == null ? '$$Key$$' : node.id.name,
|
|
2731
3028
|
typeAnnotation: {
|
|
2732
3029
|
type: 'TSTypeAnnotation',
|
|
3030
|
+
loc: DUMMY_LOC,
|
|
2733
3031
|
typeAnnotation: transformTypeAnnotationType(node.key)
|
|
2734
3032
|
}
|
|
2735
3033
|
}],
|
|
@@ -2737,6 +3035,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2737
3035
|
static: node.static,
|
|
2738
3036
|
typeAnnotation: {
|
|
2739
3037
|
type: 'TSTypeAnnotation',
|
|
3038
|
+
loc: DUMMY_LOC,
|
|
2740
3039
|
typeAnnotation: transformTypeAnnotationType(node.value)
|
|
2741
3040
|
}
|
|
2742
3041
|
};
|
|
@@ -2753,6 +3052,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2753
3052
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2754
3053
|
return {
|
|
2755
3054
|
type: 'TSMethodSignature',
|
|
3055
|
+
loc: DUMMY_LOC,
|
|
2756
3056
|
computed: false,
|
|
2757
3057
|
key,
|
|
2758
3058
|
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
@@ -2770,6 +3070,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2770
3070
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2771
3071
|
return {
|
|
2772
3072
|
type: 'TSMethodSignature',
|
|
3073
|
+
loc: DUMMY_LOC,
|
|
2773
3074
|
computed: false,
|
|
2774
3075
|
key,
|
|
2775
3076
|
kind: node.kind,
|
|
@@ -2785,6 +3086,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2785
3086
|
|
|
2786
3087
|
return {
|
|
2787
3088
|
type: 'TSPropertySignature',
|
|
3089
|
+
loc: DUMMY_LOC,
|
|
2788
3090
|
computed: false,
|
|
2789
3091
|
key,
|
|
2790
3092
|
optional: node.optional,
|
|
@@ -2792,6 +3094,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2792
3094
|
static: node.static,
|
|
2793
3095
|
typeAnnotation: {
|
|
2794
3096
|
type: 'TSTypeAnnotation',
|
|
3097
|
+
loc: DUMMY_LOC,
|
|
2795
3098
|
typeAnnotation: transformTypeAnnotationType(node.value)
|
|
2796
3099
|
}
|
|
2797
3100
|
};
|
|
@@ -2813,14 +3116,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2813
3116
|
|
|
2814
3117
|
return {
|
|
2815
3118
|
type: 'TSIndexedAccessType',
|
|
3119
|
+
loc: DUMMY_LOC,
|
|
2816
3120
|
objectType: {
|
|
2817
3121
|
type: 'TSTypeReference',
|
|
3122
|
+
loc: DUMMY_LOC,
|
|
2818
3123
|
typeName: {
|
|
2819
3124
|
type: 'Identifier',
|
|
3125
|
+
loc: DUMMY_LOC,
|
|
2820
3126
|
name: 'NonNullable'
|
|
2821
3127
|
},
|
|
2822
3128
|
typeParameters: {
|
|
2823
3129
|
type: 'TSTypeParameterInstantiation',
|
|
3130
|
+
loc: DUMMY_LOC,
|
|
2824
3131
|
params: [transformTypeAnnotationType(node.objectType)]
|
|
2825
3132
|
}
|
|
2826
3133
|
},
|
|
@@ -2832,6 +3139,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2832
3139
|
const qual = node.qualification;
|
|
2833
3140
|
return {
|
|
2834
3141
|
type: 'TSQualifiedName',
|
|
3142
|
+
loc: DUMMY_LOC,
|
|
2835
3143
|
left: qual.type === 'Identifier' ? transform.Identifier(qual, false) : transform.QualifiedTypeIdentifier(qual),
|
|
2836
3144
|
right: transform.Identifier(node.id, false)
|
|
2837
3145
|
};
|
|
@@ -2841,6 +3149,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2841
3149
|
const qual = node.qualification;
|
|
2842
3150
|
return {
|
|
2843
3151
|
type: 'TSQualifiedName',
|
|
3152
|
+
loc: DUMMY_LOC,
|
|
2844
3153
|
left: qual.type === 'Identifier' ? transform.Identifier(qual, false) : transform.QualifiedTypeofIdentifier(qual),
|
|
2845
3154
|
right: transform.Identifier(node.id, false)
|
|
2846
3155
|
};
|
|
@@ -2849,6 +3158,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2849
3158
|
RegExpLiteral(node) {
|
|
2850
3159
|
return {
|
|
2851
3160
|
type: 'Literal',
|
|
3161
|
+
loc: DUMMY_LOC,
|
|
2852
3162
|
raw: node.raw,
|
|
2853
3163
|
regex: {
|
|
2854
3164
|
pattern: node.regex.pattern,
|
|
@@ -2861,6 +3171,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2861
3171
|
StringLiteral(node) {
|
|
2862
3172
|
return {
|
|
2863
3173
|
type: 'Literal',
|
|
3174
|
+
loc: DUMMY_LOC,
|
|
2864
3175
|
raw: node.raw,
|
|
2865
3176
|
value: node.value
|
|
2866
3177
|
};
|
|
@@ -2869,8 +3180,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2869
3180
|
StringLiteralTypeAnnotation(node) {
|
|
2870
3181
|
return {
|
|
2871
3182
|
type: 'TSLiteralType',
|
|
3183
|
+
loc: DUMMY_LOC,
|
|
2872
3184
|
literal: {
|
|
2873
3185
|
type: 'Literal',
|
|
3186
|
+
loc: DUMMY_LOC,
|
|
2874
3187
|
value: node.value,
|
|
2875
3188
|
raw: node.raw
|
|
2876
3189
|
}
|
|
@@ -2879,19 +3192,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2879
3192
|
|
|
2880
3193
|
StringTypeAnnotation(_node) {
|
|
2881
3194
|
return {
|
|
2882
|
-
type: 'TSStringKeyword'
|
|
3195
|
+
type: 'TSStringKeyword',
|
|
3196
|
+
loc: DUMMY_LOC
|
|
2883
3197
|
};
|
|
2884
3198
|
},
|
|
2885
3199
|
|
|
2886
3200
|
SymbolTypeAnnotation(_node) {
|
|
2887
3201
|
return {
|
|
2888
|
-
type: 'TSSymbolKeyword'
|
|
3202
|
+
type: 'TSSymbolKeyword',
|
|
3203
|
+
loc: DUMMY_LOC
|
|
2889
3204
|
};
|
|
2890
3205
|
},
|
|
2891
3206
|
|
|
2892
3207
|
ThisTypeAnnotation(_node) {
|
|
2893
3208
|
return {
|
|
2894
|
-
type: 'TSThisType'
|
|
3209
|
+
type: 'TSThisType',
|
|
3210
|
+
loc: DUMMY_LOC
|
|
2895
3211
|
};
|
|
2896
3212
|
},
|
|
2897
3213
|
|
|
@@ -2899,6 +3215,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2899
3215
|
const allReadOnly = node.types.length > 0 && node.types.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && element.variance.kind === 'plus');
|
|
2900
3216
|
const tupleAnnot = {
|
|
2901
3217
|
type: 'TSTupleType',
|
|
3218
|
+
loc: DUMMY_LOC,
|
|
2902
3219
|
elementTypes: node.types.map(element => {
|
|
2903
3220
|
switch (element.type) {
|
|
2904
3221
|
case 'TupleTypeLabeledElement':
|
|
@@ -2908,6 +3225,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2908
3225
|
|
|
2909
3226
|
return {
|
|
2910
3227
|
type: 'TSNamedTupleMember',
|
|
3228
|
+
loc: DUMMY_LOC,
|
|
2911
3229
|
label: transform.Identifier(element.label),
|
|
2912
3230
|
optional: element.optional,
|
|
2913
3231
|
elementType: transformTypeAnnotationType(element.elementType)
|
|
@@ -2918,8 +3236,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2918
3236
|
const annot = transformTypeAnnotationType(element.typeAnnotation);
|
|
2919
3237
|
return {
|
|
2920
3238
|
type: 'TSRestType',
|
|
3239
|
+
loc: DUMMY_LOC,
|
|
2921
3240
|
typeAnnotation: element.label != null ? {
|
|
2922
3241
|
type: 'TSNamedTupleMember',
|
|
3242
|
+
loc: DUMMY_LOC,
|
|
2923
3243
|
label: transform.Identifier(element.label),
|
|
2924
3244
|
optional: false,
|
|
2925
3245
|
elementType: annot
|
|
@@ -2934,6 +3254,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2934
3254
|
};
|
|
2935
3255
|
return allReadOnly ? {
|
|
2936
3256
|
type: 'TSTypeOperator',
|
|
3257
|
+
loc: DUMMY_LOC,
|
|
2937
3258
|
operator: 'readonly',
|
|
2938
3259
|
typeAnnotation: tupleAnnot
|
|
2939
3260
|
} : tupleAnnot;
|
|
@@ -2946,6 +3267,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2946
3267
|
TypeAnnotation(node) {
|
|
2947
3268
|
return {
|
|
2948
3269
|
type: 'TSTypeAnnotation',
|
|
3270
|
+
loc: DUMMY_LOC,
|
|
2949
3271
|
typeAnnotation: transformTypeAnnotationType(node.typeAnnotation)
|
|
2950
3272
|
};
|
|
2951
3273
|
},
|
|
@@ -2955,6 +3277,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2955
3277
|
case 'Identifier':
|
|
2956
3278
|
return {
|
|
2957
3279
|
type: 'TSTypeQuery',
|
|
3280
|
+
loc: DUMMY_LOC,
|
|
2958
3281
|
exprName: transform.Identifier(node.argument),
|
|
2959
3282
|
typeParameters: undefined
|
|
2960
3283
|
};
|
|
@@ -2962,6 +3285,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2962
3285
|
case 'QualifiedTypeofIdentifier':
|
|
2963
3286
|
return {
|
|
2964
3287
|
type: 'TSTypeQuery',
|
|
3288
|
+
loc: DUMMY_LOC,
|
|
2965
3289
|
exprName: transform.QualifiedTypeofIdentifier(node.argument),
|
|
2966
3290
|
typeParameters: undefined
|
|
2967
3291
|
};
|
|
@@ -2990,8 +3314,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2990
3314
|
*/
|
|
2991
3315
|
return {
|
|
2992
3316
|
type: 'TSTypeParameter',
|
|
3317
|
+
loc: DUMMY_LOC,
|
|
2993
3318
|
name: {
|
|
2994
3319
|
type: 'Identifier',
|
|
3320
|
+
loc: DUMMY_LOC,
|
|
2995
3321
|
name: node.name
|
|
2996
3322
|
},
|
|
2997
3323
|
constraint: node.bound == null ? undefined : transformTypeAnnotationType(node.bound.typeAnnotation),
|
|
@@ -3006,6 +3332,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3006
3332
|
TypeParameterDeclaration(node) {
|
|
3007
3333
|
return {
|
|
3008
3334
|
type: 'TSTypeParameterDeclaration',
|
|
3335
|
+
loc: DUMMY_LOC,
|
|
3009
3336
|
params: node.params.map(transform.TypeParameter)
|
|
3010
3337
|
};
|
|
3011
3338
|
},
|
|
@@ -3013,6 +3340,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3013
3340
|
TypeParameterInstantiation(node) {
|
|
3014
3341
|
return {
|
|
3015
3342
|
type: 'TSTypeParameterInstantiation',
|
|
3343
|
+
loc: DUMMY_LOC,
|
|
3016
3344
|
params: node.params.map(transformTypeAnnotationType)
|
|
3017
3345
|
};
|
|
3018
3346
|
},
|
|
@@ -3020,19 +3348,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3020
3348
|
UnionTypeAnnotation(node) {
|
|
3021
3349
|
return {
|
|
3022
3350
|
type: 'TSUnionType',
|
|
3351
|
+
loc: DUMMY_LOC,
|
|
3023
3352
|
types: node.types.map(transformTypeAnnotationType)
|
|
3024
3353
|
};
|
|
3025
3354
|
},
|
|
3026
3355
|
|
|
3027
3356
|
VoidTypeAnnotation(_node) {
|
|
3028
3357
|
return {
|
|
3029
|
-
type: 'TSVoidKeyword'
|
|
3358
|
+
type: 'TSVoidKeyword',
|
|
3359
|
+
loc: DUMMY_LOC
|
|
3030
3360
|
};
|
|
3031
3361
|
},
|
|
3032
3362
|
|
|
3033
3363
|
ConditionalTypeAnnotation(node) {
|
|
3034
3364
|
return {
|
|
3035
3365
|
type: 'TSConditionalType',
|
|
3366
|
+
loc: DUMMY_LOC,
|
|
3036
3367
|
checkType: transformTypeAnnotationType(node.checkType),
|
|
3037
3368
|
extendsType: transformTypeAnnotationType(node.extendsType),
|
|
3038
3369
|
trueType: transformTypeAnnotationType(node.trueType),
|
|
@@ -3043,10 +3374,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3043
3374
|
TypePredicateAnnotation(node) {
|
|
3044
3375
|
return {
|
|
3045
3376
|
type: 'TSTypePredicate',
|
|
3046
|
-
|
|
3377
|
+
loc: DUMMY_LOC,
|
|
3378
|
+
asserts: node.kind != null && node.kind === 'asserts',
|
|
3047
3379
|
parameterName: transform.Identifier(node.parameterName, false),
|
|
3048
3380
|
typeAnnotation: node.typeAnnotation && {
|
|
3049
3381
|
type: 'TSTypeAnnotation',
|
|
3382
|
+
loc: DUMMY_LOC,
|
|
3050
3383
|
typeAnnotation: transformTypeAnnotationType(node.typeAnnotation)
|
|
3051
3384
|
}
|
|
3052
3385
|
};
|
|
@@ -3055,6 +3388,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3055
3388
|
InferTypeAnnotation(node) {
|
|
3056
3389
|
return {
|
|
3057
3390
|
type: 'TSInferType',
|
|
3391
|
+
loc: DUMMY_LOC,
|
|
3058
3392
|
typeParameter: transform.TypeParameter(node.typeParameter)
|
|
3059
3393
|
};
|
|
3060
3394
|
},
|
|
@@ -3062,6 +3396,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3062
3396
|
KeyofTypeAnnotation(node) {
|
|
3063
3397
|
return {
|
|
3064
3398
|
type: 'TSTypeOperator',
|
|
3399
|
+
loc: DUMMY_LOC,
|
|
3065
3400
|
operator: 'keyof',
|
|
3066
3401
|
typeAnnotation: transformTypeAnnotationType(node.argument)
|
|
3067
3402
|
};
|
|
@@ -3076,11 +3411,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3076
3411
|
const hasReactImport = isReactImport(node, 'React');
|
|
3077
3412
|
return {
|
|
3078
3413
|
type: 'TSTypeReference',
|
|
3414
|
+
loc: DUMMY_LOC,
|
|
3079
3415
|
typeName: {
|
|
3080
3416
|
type: 'TSQualifiedName',
|
|
3417
|
+
loc: DUMMY_LOC,
|
|
3081
3418
|
left: getReactIdentifier(hasReactImport),
|
|
3082
3419
|
right: {
|
|
3083
3420
|
type: 'Identifier',
|
|
3421
|
+
loc: DUMMY_LOC,
|
|
3084
3422
|
name: `ReactNode`
|
|
3085
3423
|
}
|
|
3086
3424
|
},
|
|
@@ -3097,14 +3435,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3097
3435
|
const hasReactImport = isReactImport(node, 'React');
|
|
3098
3436
|
const returnType = {
|
|
3099
3437
|
type: 'TSTypeAnnotation',
|
|
3438
|
+
loc: DUMMY_LOC,
|
|
3100
3439
|
// If no rendersType we assume its ReactNode type.
|
|
3101
3440
|
typeAnnotation: {
|
|
3102
3441
|
type: 'TSTypeReference',
|
|
3442
|
+
loc: DUMMY_LOC,
|
|
3103
3443
|
typeName: {
|
|
3104
3444
|
type: 'TSQualifiedName',
|
|
3445
|
+
loc: DUMMY_LOC,
|
|
3105
3446
|
left: getReactIdentifier(hasReactImport),
|
|
3106
3447
|
right: {
|
|
3107
3448
|
type: 'Identifier',
|
|
3449
|
+
loc: DUMMY_LOC,
|
|
3108
3450
|
name: `ReactNode`
|
|
3109
3451
|
}
|
|
3110
3452
|
},
|
|
@@ -3113,6 +3455,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3113
3455
|
};
|
|
3114
3456
|
return {
|
|
3115
3457
|
type: 'TSFunctionType',
|
|
3458
|
+
loc: DUMMY_LOC,
|
|
3116
3459
|
typeParameters,
|
|
3117
3460
|
params,
|
|
3118
3461
|
returnType
|