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.
- package/dist/TSDefToFlowDef.js +1812 -0
- package/dist/TSDefToFlowDef.js.flow +2030 -0
- package/dist/flowDefToTSDef.js +377 -33
- package/dist/flowDefToTSDef.js.flow +353 -17
- 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
|
};
|
|
@@ -2132,8 +2355,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2132
2355
|
|
|
2133
2356
|
const params = typeParameters.params;
|
|
2134
2357
|
|
|
2135
|
-
if (params.length >
|
|
2136
|
-
throw translationError(node, `Expected at no more than
|
|
2358
|
+
if (params.length > 3) {
|
|
2359
|
+
throw translationError(node, `Expected at no more than 3 type parameters with \`${fullTypeName}\``);
|
|
2137
2360
|
}
|
|
2138
2361
|
|
|
2139
2362
|
const newParams = (() => {
|
|
@@ -2141,24 +2364,31 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2141
2364
|
return assertHasExactlyNTypeParameters(1);
|
|
2142
2365
|
}
|
|
2143
2366
|
|
|
2144
|
-
const
|
|
2367
|
+
const props = transformTypeAnnotationType(params[0]);
|
|
2368
|
+
const ref = transformTypeAnnotationType(params[1]);
|
|
2145
2369
|
return [{
|
|
2146
2370
|
type: 'TSIntersectionType',
|
|
2371
|
+
loc: DUMMY_LOC,
|
|
2147
2372
|
types: [props, {
|
|
2148
2373
|
type: 'TSTypeReference',
|
|
2374
|
+
loc: DUMMY_LOC,
|
|
2149
2375
|
typeName: {
|
|
2150
2376
|
type: 'TSQualifiedName',
|
|
2377
|
+
loc: DUMMY_LOC,
|
|
2151
2378
|
left: {
|
|
2152
2379
|
type: 'Identifier',
|
|
2380
|
+
loc: DUMMY_LOC,
|
|
2153
2381
|
name: 'React'
|
|
2154
2382
|
},
|
|
2155
2383
|
right: {
|
|
2156
2384
|
type: 'Identifier',
|
|
2385
|
+
loc: DUMMY_LOC,
|
|
2157
2386
|
name: 'RefAttributes'
|
|
2158
2387
|
}
|
|
2159
2388
|
},
|
|
2160
2389
|
typeParameters: {
|
|
2161
2390
|
type: 'TSTypeParameterInstantiation',
|
|
2391
|
+
loc: DUMMY_LOC,
|
|
2162
2392
|
params: [ref]
|
|
2163
2393
|
}
|
|
2164
2394
|
}]
|
|
@@ -2167,16 +2397,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2167
2397
|
|
|
2168
2398
|
return {
|
|
2169
2399
|
type: 'TSTypeReference',
|
|
2400
|
+
loc: DUMMY_LOC,
|
|
2170
2401
|
typeName: {
|
|
2171
2402
|
type: 'TSQualifiedName',
|
|
2403
|
+
loc: DUMMY_LOC,
|
|
2172
2404
|
left: getReactIdentifier(hasReactImport),
|
|
2173
2405
|
right: {
|
|
2174
2406
|
type: 'Identifier',
|
|
2407
|
+
loc: DUMMY_LOC,
|
|
2175
2408
|
name: 'ComponentType'
|
|
2176
2409
|
}
|
|
2177
2410
|
},
|
|
2178
2411
|
typeParameters: {
|
|
2179
2412
|
type: 'TSTypeParameterInstantiation',
|
|
2413
|
+
loc: DUMMY_LOC,
|
|
2180
2414
|
params: newParams
|
|
2181
2415
|
}
|
|
2182
2416
|
};
|
|
@@ -2189,16 +2423,20 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2189
2423
|
{
|
|
2190
2424
|
return {
|
|
2191
2425
|
type: 'TSTypeReference',
|
|
2426
|
+
loc: DUMMY_LOC,
|
|
2192
2427
|
typeName: {
|
|
2193
2428
|
type: 'TSQualifiedName',
|
|
2429
|
+
loc: DUMMY_LOC,
|
|
2194
2430
|
left: getReactIdentifier(hasReactImport),
|
|
2195
2431
|
right: {
|
|
2196
2432
|
type: 'Identifier',
|
|
2433
|
+
loc: DUMMY_LOC,
|
|
2197
2434
|
name: 'ComponentProps'
|
|
2198
2435
|
}
|
|
2199
2436
|
},
|
|
2200
2437
|
typeParameters: {
|
|
2201
2438
|
type: 'TSTypeParameterInstantiation',
|
|
2439
|
+
loc: DUMMY_LOC,
|
|
2202
2440
|
params: assertHasExactlyNTypeParameters(1)
|
|
2203
2441
|
}
|
|
2204
2442
|
};
|
|
@@ -2212,31 +2450,40 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2212
2450
|
const [param] = assertHasExactlyNTypeParameters(1);
|
|
2213
2451
|
return {
|
|
2214
2452
|
type: 'TSTypeReference',
|
|
2453
|
+
loc: DUMMY_LOC,
|
|
2215
2454
|
typeName: {
|
|
2216
2455
|
type: 'TSQualifiedName',
|
|
2456
|
+
loc: DUMMY_LOC,
|
|
2217
2457
|
left: {
|
|
2218
2458
|
type: 'Identifier',
|
|
2459
|
+
loc: DUMMY_LOC,
|
|
2219
2460
|
name: 'JSX'
|
|
2220
2461
|
},
|
|
2221
2462
|
right: {
|
|
2222
2463
|
type: 'Identifier',
|
|
2464
|
+
loc: DUMMY_LOC,
|
|
2223
2465
|
name: 'LibraryManagedAttributes'
|
|
2224
2466
|
}
|
|
2225
2467
|
},
|
|
2226
2468
|
typeParameters: {
|
|
2227
2469
|
type: 'TSTypeParameterInstantiation',
|
|
2470
|
+
loc: DUMMY_LOC,
|
|
2228
2471
|
params: [param, {
|
|
2229
2472
|
type: 'TSTypeReference',
|
|
2473
|
+
loc: DUMMY_LOC,
|
|
2230
2474
|
typeName: {
|
|
2231
2475
|
type: 'TSQualifiedName',
|
|
2476
|
+
loc: DUMMY_LOC,
|
|
2232
2477
|
left: getReactIdentifier(hasReactImport),
|
|
2233
2478
|
right: {
|
|
2234
2479
|
type: 'Identifier',
|
|
2480
|
+
loc: DUMMY_LOC,
|
|
2235
2481
|
name: `ComponentProps`
|
|
2236
2482
|
}
|
|
2237
2483
|
},
|
|
2238
2484
|
typeParameters: {
|
|
2239
2485
|
type: 'TSTypeParameterInstantiation',
|
|
2486
|
+
loc: DUMMY_LOC,
|
|
2240
2487
|
params: [param]
|
|
2241
2488
|
}
|
|
2242
2489
|
}]
|
|
@@ -2250,32 +2497,42 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2250
2497
|
case 'React$Ref':
|
|
2251
2498
|
return {
|
|
2252
2499
|
type: 'TSTypeReference',
|
|
2500
|
+
loc: DUMMY_LOC,
|
|
2253
2501
|
typeName: {
|
|
2254
2502
|
type: 'Identifier',
|
|
2503
|
+
loc: DUMMY_LOC,
|
|
2255
2504
|
name: 'NonNullable'
|
|
2256
2505
|
},
|
|
2257
2506
|
typeParameters: {
|
|
2258
2507
|
type: 'TSTypeParameterInstantiation',
|
|
2508
|
+
loc: DUMMY_LOC,
|
|
2259
2509
|
params: [{
|
|
2260
2510
|
type: 'TSUnionType',
|
|
2511
|
+
loc: DUMMY_LOC,
|
|
2261
2512
|
types: [{
|
|
2262
2513
|
type: 'TSTypeReference',
|
|
2514
|
+
loc: DUMMY_LOC,
|
|
2263
2515
|
typeName: {
|
|
2264
2516
|
type: 'TSQualifiedName',
|
|
2517
|
+
loc: DUMMY_LOC,
|
|
2265
2518
|
left: getReactIdentifier(hasReactImport),
|
|
2266
2519
|
right: {
|
|
2267
2520
|
type: 'Identifier',
|
|
2521
|
+
loc: DUMMY_LOC,
|
|
2268
2522
|
name: 'Ref'
|
|
2269
2523
|
}
|
|
2270
2524
|
},
|
|
2271
2525
|
typeParameters: {
|
|
2272
2526
|
type: 'TSTypeParameterInstantiation',
|
|
2527
|
+
loc: DUMMY_LOC,
|
|
2273
2528
|
params: assertHasExactlyNTypeParameters(1)
|
|
2274
2529
|
}
|
|
2275
2530
|
}, {
|
|
2276
|
-
type: 'TSStringKeyword'
|
|
2531
|
+
type: 'TSStringKeyword',
|
|
2532
|
+
loc: DUMMY_LOC
|
|
2277
2533
|
}, {
|
|
2278
|
-
type: 'TSNumberKeyword'
|
|
2534
|
+
type: 'TSNumberKeyword',
|
|
2535
|
+
loc: DUMMY_LOC
|
|
2279
2536
|
}]
|
|
2280
2537
|
}]
|
|
2281
2538
|
}
|
|
@@ -2288,6 +2545,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2288
2545
|
|
|
2289
2546
|
return {
|
|
2290
2547
|
type: 'TSTypeReference',
|
|
2548
|
+
loc: DUMMY_LOC,
|
|
2291
2549
|
typeName: node.id.type === 'Identifier' ? transform.Identifier(node.id, false) : transform.QualifiedTypeIdentifier(node.id),
|
|
2292
2550
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterInstantiation(node.typeParameters)
|
|
2293
2551
|
};
|
|
@@ -2296,6 +2554,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2296
2554
|
Identifier(node, includeTypeAnnotation = true) {
|
|
2297
2555
|
return {
|
|
2298
2556
|
type: 'Identifier',
|
|
2557
|
+
loc: DUMMY_LOC,
|
|
2299
2558
|
name: node.name,
|
|
2300
2559
|
...(includeTypeAnnotation && node.typeAnnotation != null ? {
|
|
2301
2560
|
typeAnnotation: transform.TypeAnnotation(node.typeAnnotation)
|
|
@@ -2306,6 +2565,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2306
2565
|
IndexedAccessType(node) {
|
|
2307
2566
|
return {
|
|
2308
2567
|
type: 'TSIndexedAccessType',
|
|
2568
|
+
loc: DUMMY_LOC,
|
|
2309
2569
|
objectType: transformTypeAnnotationType(node.objectType),
|
|
2310
2570
|
indexType: transformTypeAnnotationType(node.indexType)
|
|
2311
2571
|
};
|
|
@@ -2318,6 +2578,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2318
2578
|
ImportAttribute(node) {
|
|
2319
2579
|
return {
|
|
2320
2580
|
type: 'ImportAttribute',
|
|
2581
|
+
loc: DUMMY_LOC,
|
|
2321
2582
|
key: node.key.type === 'Identifier' ? transform.Identifier(node.key) : transform.Literal(node.key),
|
|
2322
2583
|
value: transform.Literal(node.value)
|
|
2323
2584
|
};
|
|
@@ -2332,13 +2593,16 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2332
2593
|
if (node.importKind === 'typeof' || spec.importKind === 'typeof') {
|
|
2333
2594
|
const id = {
|
|
2334
2595
|
type: 'Identifier',
|
|
2596
|
+
loc: DUMMY_LOC,
|
|
2335
2597
|
name: getPlaceholderNameForTypeofImport()
|
|
2336
2598
|
};
|
|
2337
2599
|
unsupportedSpecifiers.push({
|
|
2338
2600
|
type: 'TSTypeAliasDeclaration',
|
|
2601
|
+
loc: DUMMY_LOC,
|
|
2339
2602
|
id: transform.Identifier(spec.local, false),
|
|
2340
2603
|
typeAnnotation: {
|
|
2341
2604
|
type: 'TSTypeQuery',
|
|
2605
|
+
loc: DUMMY_LOC,
|
|
2342
2606
|
exprName: id
|
|
2343
2607
|
}
|
|
2344
2608
|
});
|
|
@@ -2352,6 +2616,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2352
2616
|
case 'ImportDefaultSpecifier':
|
|
2353
2617
|
specifiers.push({
|
|
2354
2618
|
type: 'ImportDefaultSpecifier',
|
|
2619
|
+
loc: DUMMY_LOC,
|
|
2355
2620
|
local: id
|
|
2356
2621
|
});
|
|
2357
2622
|
return;
|
|
@@ -2359,6 +2624,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2359
2624
|
case 'ImportNamespaceSpecifier':
|
|
2360
2625
|
specifiers.push({
|
|
2361
2626
|
type: 'ImportNamespaceSpecifier',
|
|
2627
|
+
loc: DUMMY_LOC,
|
|
2362
2628
|
local: id
|
|
2363
2629
|
});
|
|
2364
2630
|
return;
|
|
@@ -2366,6 +2632,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2366
2632
|
case 'ImportSpecifier':
|
|
2367
2633
|
specifiers.push({
|
|
2368
2634
|
type: 'ImportSpecifier',
|
|
2635
|
+
loc: DUMMY_LOC,
|
|
2369
2636
|
importKind: spec.importKind === 'typeof' || spec.importKind === 'type' ? 'type' : null,
|
|
2370
2637
|
imported: transform.Identifier(spec.imported, false),
|
|
2371
2638
|
local: id
|
|
@@ -2375,6 +2642,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2375
2642
|
});
|
|
2376
2643
|
const out = specifiers.length ? [{
|
|
2377
2644
|
type: 'ImportDeclaration',
|
|
2645
|
+
loc: DUMMY_LOC,
|
|
2378
2646
|
assertions: node.assertions.map(transform.ImportAttribute),
|
|
2379
2647
|
importKind: importKind === 'typeof' ? 'type' : importKind != null ? importKind : 'value',
|
|
2380
2648
|
source: transform.StringLiteral(node.source),
|
|
@@ -2386,6 +2654,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2386
2654
|
InterfaceExtends(node) {
|
|
2387
2655
|
return {
|
|
2388
2656
|
type: 'TSInterfaceHeritage',
|
|
2657
|
+
loc: DUMMY_LOC,
|
|
2658
|
+
// Bug: node.id can be qualified
|
|
2389
2659
|
expression: transform.Identifier(node.id, false),
|
|
2390
2660
|
typeParameters: node.typeParameters == null ? undefined : transform.TypeParameterInstantiation(node.typeParameters)
|
|
2391
2661
|
};
|
|
@@ -2398,8 +2668,11 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2398
2668
|
// type T = U & V & { ... }
|
|
2399
2669
|
return {
|
|
2400
2670
|
type: 'TSIntersectionType',
|
|
2671
|
+
loc: DUMMY_LOC,
|
|
2401
2672
|
types: [...node.extends.map(ex => ({
|
|
2402
2673
|
type: 'TSTypeReference',
|
|
2674
|
+
loc: DUMMY_LOC,
|
|
2675
|
+
// Bug: ex.id can be qualified
|
|
2403
2676
|
typeName: transform.Identifier(ex.id, false),
|
|
2404
2677
|
typeParameters: ex.typeParameters == null ? undefined : transform.TypeParameterInstantiation(ex.typeParameters)
|
|
2405
2678
|
})), transform.ObjectTypeAnnotation(node.body)]
|
|
@@ -2412,6 +2685,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2412
2685
|
IntersectionTypeAnnotation(node) {
|
|
2413
2686
|
return {
|
|
2414
2687
|
type: 'TSIntersectionType',
|
|
2688
|
+
loc: DUMMY_LOC,
|
|
2415
2689
|
types: node.types.map(transformTypeAnnotationType)
|
|
2416
2690
|
};
|
|
2417
2691
|
},
|
|
@@ -2440,13 +2714,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2440
2714
|
|
|
2441
2715
|
MixedTypeAnnotation(_node) {
|
|
2442
2716
|
return {
|
|
2443
|
-
type: 'TSUnknownKeyword'
|
|
2717
|
+
type: 'TSUnknownKeyword',
|
|
2718
|
+
loc: DUMMY_LOC
|
|
2444
2719
|
};
|
|
2445
2720
|
},
|
|
2446
2721
|
|
|
2447
2722
|
NullLiteral(_node) {
|
|
2448
2723
|
return {
|
|
2449
2724
|
type: 'Literal',
|
|
2725
|
+
loc: DUMMY_LOC,
|
|
2450
2726
|
raw: 'null',
|
|
2451
2727
|
value: null
|
|
2452
2728
|
};
|
|
@@ -2454,7 +2730,8 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2454
2730
|
|
|
2455
2731
|
NullLiteralTypeAnnotation(_node) {
|
|
2456
2732
|
return {
|
|
2457
|
-
type: 'TSNullKeyword'
|
|
2733
|
+
type: 'TSNullKeyword',
|
|
2734
|
+
loc: DUMMY_LOC
|
|
2458
2735
|
};
|
|
2459
2736
|
},
|
|
2460
2737
|
|
|
@@ -2463,10 +2740,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2463
2740
|
// `?T` becomes `null | undefined | T`
|
|
2464
2741
|
return {
|
|
2465
2742
|
type: 'TSUnionType',
|
|
2743
|
+
loc: DUMMY_LOC,
|
|
2466
2744
|
types: [{
|
|
2467
|
-
type: 'TSNullKeyword'
|
|
2745
|
+
type: 'TSNullKeyword',
|
|
2746
|
+
loc: DUMMY_LOC
|
|
2468
2747
|
}, {
|
|
2469
|
-
type: 'TSUndefinedKeyword'
|
|
2748
|
+
type: 'TSUndefinedKeyword',
|
|
2749
|
+
loc: DUMMY_LOC
|
|
2470
2750
|
}, transformTypeAnnotationType(node.typeAnnotation)]
|
|
2471
2751
|
};
|
|
2472
2752
|
},
|
|
@@ -2474,8 +2754,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2474
2754
|
NumberLiteralTypeAnnotation(node) {
|
|
2475
2755
|
return {
|
|
2476
2756
|
type: 'TSLiteralType',
|
|
2757
|
+
loc: DUMMY_LOC,
|
|
2477
2758
|
literal: {
|
|
2478
2759
|
type: 'Literal',
|
|
2760
|
+
loc: DUMMY_LOC,
|
|
2479
2761
|
value: node.value,
|
|
2480
2762
|
raw: node.raw
|
|
2481
2763
|
}
|
|
@@ -2484,13 +2766,15 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2484
2766
|
|
|
2485
2767
|
NumberTypeAnnotation(_node) {
|
|
2486
2768
|
return {
|
|
2487
|
-
type: 'TSNumberKeyword'
|
|
2769
|
+
type: 'TSNumberKeyword',
|
|
2770
|
+
loc: DUMMY_LOC
|
|
2488
2771
|
};
|
|
2489
2772
|
},
|
|
2490
2773
|
|
|
2491
2774
|
NumericLiteral(node) {
|
|
2492
2775
|
return {
|
|
2493
2776
|
type: 'Literal',
|
|
2777
|
+
loc: DUMMY_LOC,
|
|
2494
2778
|
raw: node.raw,
|
|
2495
2779
|
value: node.value
|
|
2496
2780
|
};
|
|
@@ -2504,10 +2788,13 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2504
2788
|
const prop = node.properties[0];
|
|
2505
2789
|
const tsProp = {
|
|
2506
2790
|
type: 'TSMappedType',
|
|
2791
|
+
loc: DUMMY_LOC,
|
|
2507
2792
|
typeParameter: {
|
|
2508
2793
|
type: 'TSTypeParameter',
|
|
2794
|
+
loc: DUMMY_LOC,
|
|
2509
2795
|
name: {
|
|
2510
2796
|
type: 'Identifier',
|
|
2797
|
+
loc: DUMMY_LOC,
|
|
2511
2798
|
name: prop.keyTparam.name
|
|
2512
2799
|
},
|
|
2513
2800
|
constraint: transformTypeAnnotationType(prop.sourceType),
|
|
@@ -2575,6 +2862,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2575
2862
|
}) => node);
|
|
2576
2863
|
return {
|
|
2577
2864
|
type: 'TSTypeLiteral',
|
|
2865
|
+
loc: DUMMY_LOC,
|
|
2578
2866
|
members: tsBody
|
|
2579
2867
|
};
|
|
2580
2868
|
} else {
|
|
@@ -2674,6 +2962,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2674
2962
|
}) => node);
|
|
2675
2963
|
const objectType = {
|
|
2676
2964
|
type: 'TSTypeLiteral',
|
|
2965
|
+
loc: DUMMY_LOC,
|
|
2677
2966
|
members: tsBody
|
|
2678
2967
|
};
|
|
2679
2968
|
const intersectionMembers = [];
|
|
@@ -2683,17 +2972,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2683
2972
|
const remainingTypes = typesToIntersect.slice(i + 1);
|
|
2684
2973
|
intersectionMembers.push({
|
|
2685
2974
|
type: 'TSTypeReference',
|
|
2975
|
+
loc: DUMMY_LOC,
|
|
2686
2976
|
typeName: {
|
|
2687
2977
|
type: 'Identifier',
|
|
2978
|
+
loc: DUMMY_LOC,
|
|
2688
2979
|
name: 'Omit'
|
|
2689
2980
|
},
|
|
2690
2981
|
typeParameters: {
|
|
2691
2982
|
type: 'TSTypeParameterInstantiation',
|
|
2983
|
+
loc: DUMMY_LOC,
|
|
2692
2984
|
params: [currentType, {
|
|
2693
2985
|
type: 'TSTypeOperator',
|
|
2986
|
+
loc: DUMMY_LOC,
|
|
2694
2987
|
operator: 'keyof',
|
|
2695
2988
|
typeAnnotation: {
|
|
2696
2989
|
type: 'TSUnionType',
|
|
2990
|
+
loc: DUMMY_LOC,
|
|
2697
2991
|
types: [...remainingTypes, objectType]
|
|
2698
2992
|
}
|
|
2699
2993
|
}]
|
|
@@ -2704,6 +2998,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2704
2998
|
intersectionMembers.push(objectType);
|
|
2705
2999
|
return {
|
|
2706
3000
|
type: 'TSIntersectionType',
|
|
3001
|
+
loc: DUMMY_LOC,
|
|
2707
3002
|
types: intersectionMembers
|
|
2708
3003
|
};
|
|
2709
3004
|
}
|
|
@@ -2714,6 +3009,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2714
3009
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2715
3010
|
return {
|
|
2716
3011
|
type: 'TSCallSignatureDeclaration',
|
|
3012
|
+
loc: DUMMY_LOC,
|
|
2717
3013
|
params: func.params,
|
|
2718
3014
|
returnType: func.returnType,
|
|
2719
3015
|
typeParameters: func.typeParameters
|
|
@@ -2725,11 +3021,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2725
3021
|
|
|
2726
3022
|
return {
|
|
2727
3023
|
type: 'TSIndexSignature',
|
|
3024
|
+
loc: DUMMY_LOC,
|
|
2728
3025
|
parameters: [{
|
|
2729
3026
|
type: 'Identifier',
|
|
3027
|
+
loc: DUMMY_LOC,
|
|
2730
3028
|
name: node.id == null ? '$$Key$$' : node.id.name,
|
|
2731
3029
|
typeAnnotation: {
|
|
2732
3030
|
type: 'TSTypeAnnotation',
|
|
3031
|
+
loc: DUMMY_LOC,
|
|
2733
3032
|
typeAnnotation: transformTypeAnnotationType(node.key)
|
|
2734
3033
|
}
|
|
2735
3034
|
}],
|
|
@@ -2737,6 +3036,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2737
3036
|
static: node.static,
|
|
2738
3037
|
typeAnnotation: {
|
|
2739
3038
|
type: 'TSTypeAnnotation',
|
|
3039
|
+
loc: DUMMY_LOC,
|
|
2740
3040
|
typeAnnotation: transformTypeAnnotationType(node.value)
|
|
2741
3041
|
}
|
|
2742
3042
|
};
|
|
@@ -2753,6 +3053,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2753
3053
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2754
3054
|
return {
|
|
2755
3055
|
type: 'TSMethodSignature',
|
|
3056
|
+
loc: DUMMY_LOC,
|
|
2756
3057
|
computed: false,
|
|
2757
3058
|
key,
|
|
2758
3059
|
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
@@ -2770,6 +3071,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2770
3071
|
const func = transform.FunctionTypeAnnotation(node.value);
|
|
2771
3072
|
return {
|
|
2772
3073
|
type: 'TSMethodSignature',
|
|
3074
|
+
loc: DUMMY_LOC,
|
|
2773
3075
|
computed: false,
|
|
2774
3076
|
key,
|
|
2775
3077
|
kind: node.kind,
|
|
@@ -2785,6 +3087,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2785
3087
|
|
|
2786
3088
|
return {
|
|
2787
3089
|
type: 'TSPropertySignature',
|
|
3090
|
+
loc: DUMMY_LOC,
|
|
2788
3091
|
computed: false,
|
|
2789
3092
|
key,
|
|
2790
3093
|
optional: node.optional,
|
|
@@ -2792,6 +3095,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2792
3095
|
static: node.static,
|
|
2793
3096
|
typeAnnotation: {
|
|
2794
3097
|
type: 'TSTypeAnnotation',
|
|
3098
|
+
loc: DUMMY_LOC,
|
|
2795
3099
|
typeAnnotation: transformTypeAnnotationType(node.value)
|
|
2796
3100
|
}
|
|
2797
3101
|
};
|
|
@@ -2813,14 +3117,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2813
3117
|
|
|
2814
3118
|
return {
|
|
2815
3119
|
type: 'TSIndexedAccessType',
|
|
3120
|
+
loc: DUMMY_LOC,
|
|
2816
3121
|
objectType: {
|
|
2817
3122
|
type: 'TSTypeReference',
|
|
3123
|
+
loc: DUMMY_LOC,
|
|
2818
3124
|
typeName: {
|
|
2819
3125
|
type: 'Identifier',
|
|
3126
|
+
loc: DUMMY_LOC,
|
|
2820
3127
|
name: 'NonNullable'
|
|
2821
3128
|
},
|
|
2822
3129
|
typeParameters: {
|
|
2823
3130
|
type: 'TSTypeParameterInstantiation',
|
|
3131
|
+
loc: DUMMY_LOC,
|
|
2824
3132
|
params: [transformTypeAnnotationType(node.objectType)]
|
|
2825
3133
|
}
|
|
2826
3134
|
},
|
|
@@ -2832,6 +3140,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2832
3140
|
const qual = node.qualification;
|
|
2833
3141
|
return {
|
|
2834
3142
|
type: 'TSQualifiedName',
|
|
3143
|
+
loc: DUMMY_LOC,
|
|
2835
3144
|
left: qual.type === 'Identifier' ? transform.Identifier(qual, false) : transform.QualifiedTypeIdentifier(qual),
|
|
2836
3145
|
right: transform.Identifier(node.id, false)
|
|
2837
3146
|
};
|
|
@@ -2841,6 +3150,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2841
3150
|
const qual = node.qualification;
|
|
2842
3151
|
return {
|
|
2843
3152
|
type: 'TSQualifiedName',
|
|
3153
|
+
loc: DUMMY_LOC,
|
|
2844
3154
|
left: qual.type === 'Identifier' ? transform.Identifier(qual, false) : transform.QualifiedTypeofIdentifier(qual),
|
|
2845
3155
|
right: transform.Identifier(node.id, false)
|
|
2846
3156
|
};
|
|
@@ -2849,6 +3159,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2849
3159
|
RegExpLiteral(node) {
|
|
2850
3160
|
return {
|
|
2851
3161
|
type: 'Literal',
|
|
3162
|
+
loc: DUMMY_LOC,
|
|
2852
3163
|
raw: node.raw,
|
|
2853
3164
|
regex: {
|
|
2854
3165
|
pattern: node.regex.pattern,
|
|
@@ -2861,6 +3172,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2861
3172
|
StringLiteral(node) {
|
|
2862
3173
|
return {
|
|
2863
3174
|
type: 'Literal',
|
|
3175
|
+
loc: DUMMY_LOC,
|
|
2864
3176
|
raw: node.raw,
|
|
2865
3177
|
value: node.value
|
|
2866
3178
|
};
|
|
@@ -2869,8 +3181,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2869
3181
|
StringLiteralTypeAnnotation(node) {
|
|
2870
3182
|
return {
|
|
2871
3183
|
type: 'TSLiteralType',
|
|
3184
|
+
loc: DUMMY_LOC,
|
|
2872
3185
|
literal: {
|
|
2873
3186
|
type: 'Literal',
|
|
3187
|
+
loc: DUMMY_LOC,
|
|
2874
3188
|
value: node.value,
|
|
2875
3189
|
raw: node.raw
|
|
2876
3190
|
}
|
|
@@ -2879,19 +3193,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2879
3193
|
|
|
2880
3194
|
StringTypeAnnotation(_node) {
|
|
2881
3195
|
return {
|
|
2882
|
-
type: 'TSStringKeyword'
|
|
3196
|
+
type: 'TSStringKeyword',
|
|
3197
|
+
loc: DUMMY_LOC
|
|
2883
3198
|
};
|
|
2884
3199
|
},
|
|
2885
3200
|
|
|
2886
3201
|
SymbolTypeAnnotation(_node) {
|
|
2887
3202
|
return {
|
|
2888
|
-
type: 'TSSymbolKeyword'
|
|
3203
|
+
type: 'TSSymbolKeyword',
|
|
3204
|
+
loc: DUMMY_LOC
|
|
2889
3205
|
};
|
|
2890
3206
|
},
|
|
2891
3207
|
|
|
2892
3208
|
ThisTypeAnnotation(_node) {
|
|
2893
3209
|
return {
|
|
2894
|
-
type: 'TSThisType'
|
|
3210
|
+
type: 'TSThisType',
|
|
3211
|
+
loc: DUMMY_LOC
|
|
2895
3212
|
};
|
|
2896
3213
|
},
|
|
2897
3214
|
|
|
@@ -2899,6 +3216,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2899
3216
|
const allReadOnly = node.types.length > 0 && node.types.every(element => element.type === 'TupleTypeLabeledElement' && element.variance != null && element.variance.kind === 'plus');
|
|
2900
3217
|
const tupleAnnot = {
|
|
2901
3218
|
type: 'TSTupleType',
|
|
3219
|
+
loc: DUMMY_LOC,
|
|
2902
3220
|
elementTypes: node.types.map(element => {
|
|
2903
3221
|
switch (element.type) {
|
|
2904
3222
|
case 'TupleTypeLabeledElement':
|
|
@@ -2908,6 +3226,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2908
3226
|
|
|
2909
3227
|
return {
|
|
2910
3228
|
type: 'TSNamedTupleMember',
|
|
3229
|
+
loc: DUMMY_LOC,
|
|
2911
3230
|
label: transform.Identifier(element.label),
|
|
2912
3231
|
optional: element.optional,
|
|
2913
3232
|
elementType: transformTypeAnnotationType(element.elementType)
|
|
@@ -2918,8 +3237,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2918
3237
|
const annot = transformTypeAnnotationType(element.typeAnnotation);
|
|
2919
3238
|
return {
|
|
2920
3239
|
type: 'TSRestType',
|
|
3240
|
+
loc: DUMMY_LOC,
|
|
2921
3241
|
typeAnnotation: element.label != null ? {
|
|
2922
3242
|
type: 'TSNamedTupleMember',
|
|
3243
|
+
loc: DUMMY_LOC,
|
|
2923
3244
|
label: transform.Identifier(element.label),
|
|
2924
3245
|
optional: false,
|
|
2925
3246
|
elementType: annot
|
|
@@ -2934,6 +3255,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2934
3255
|
};
|
|
2935
3256
|
return allReadOnly ? {
|
|
2936
3257
|
type: 'TSTypeOperator',
|
|
3258
|
+
loc: DUMMY_LOC,
|
|
2937
3259
|
operator: 'readonly',
|
|
2938
3260
|
typeAnnotation: tupleAnnot
|
|
2939
3261
|
} : tupleAnnot;
|
|
@@ -2946,6 +3268,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2946
3268
|
TypeAnnotation(node) {
|
|
2947
3269
|
return {
|
|
2948
3270
|
type: 'TSTypeAnnotation',
|
|
3271
|
+
loc: DUMMY_LOC,
|
|
2949
3272
|
typeAnnotation: transformTypeAnnotationType(node.typeAnnotation)
|
|
2950
3273
|
};
|
|
2951
3274
|
},
|
|
@@ -2955,6 +3278,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2955
3278
|
case 'Identifier':
|
|
2956
3279
|
return {
|
|
2957
3280
|
type: 'TSTypeQuery',
|
|
3281
|
+
loc: DUMMY_LOC,
|
|
2958
3282
|
exprName: transform.Identifier(node.argument),
|
|
2959
3283
|
typeParameters: undefined
|
|
2960
3284
|
};
|
|
@@ -2962,6 +3286,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2962
3286
|
case 'QualifiedTypeofIdentifier':
|
|
2963
3287
|
return {
|
|
2964
3288
|
type: 'TSTypeQuery',
|
|
3289
|
+
loc: DUMMY_LOC,
|
|
2965
3290
|
exprName: transform.QualifiedTypeofIdentifier(node.argument),
|
|
2966
3291
|
typeParameters: undefined
|
|
2967
3292
|
};
|
|
@@ -2990,8 +3315,10 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
2990
3315
|
*/
|
|
2991
3316
|
return {
|
|
2992
3317
|
type: 'TSTypeParameter',
|
|
3318
|
+
loc: DUMMY_LOC,
|
|
2993
3319
|
name: {
|
|
2994
3320
|
type: 'Identifier',
|
|
3321
|
+
loc: DUMMY_LOC,
|
|
2995
3322
|
name: node.name
|
|
2996
3323
|
},
|
|
2997
3324
|
constraint: node.bound == null ? undefined : transformTypeAnnotationType(node.bound.typeAnnotation),
|
|
@@ -3006,6 +3333,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3006
3333
|
TypeParameterDeclaration(node) {
|
|
3007
3334
|
return {
|
|
3008
3335
|
type: 'TSTypeParameterDeclaration',
|
|
3336
|
+
loc: DUMMY_LOC,
|
|
3009
3337
|
params: node.params.map(transform.TypeParameter)
|
|
3010
3338
|
};
|
|
3011
3339
|
},
|
|
@@ -3013,6 +3341,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3013
3341
|
TypeParameterInstantiation(node) {
|
|
3014
3342
|
return {
|
|
3015
3343
|
type: 'TSTypeParameterInstantiation',
|
|
3344
|
+
loc: DUMMY_LOC,
|
|
3016
3345
|
params: node.params.map(transformTypeAnnotationType)
|
|
3017
3346
|
};
|
|
3018
3347
|
},
|
|
@@ -3020,19 +3349,22 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3020
3349
|
UnionTypeAnnotation(node) {
|
|
3021
3350
|
return {
|
|
3022
3351
|
type: 'TSUnionType',
|
|
3352
|
+
loc: DUMMY_LOC,
|
|
3023
3353
|
types: node.types.map(transformTypeAnnotationType)
|
|
3024
3354
|
};
|
|
3025
3355
|
},
|
|
3026
3356
|
|
|
3027
3357
|
VoidTypeAnnotation(_node) {
|
|
3028
3358
|
return {
|
|
3029
|
-
type: 'TSVoidKeyword'
|
|
3359
|
+
type: 'TSVoidKeyword',
|
|
3360
|
+
loc: DUMMY_LOC
|
|
3030
3361
|
};
|
|
3031
3362
|
},
|
|
3032
3363
|
|
|
3033
3364
|
ConditionalTypeAnnotation(node) {
|
|
3034
3365
|
return {
|
|
3035
3366
|
type: 'TSConditionalType',
|
|
3367
|
+
loc: DUMMY_LOC,
|
|
3036
3368
|
checkType: transformTypeAnnotationType(node.checkType),
|
|
3037
3369
|
extendsType: transformTypeAnnotationType(node.extendsType),
|
|
3038
3370
|
trueType: transformTypeAnnotationType(node.trueType),
|
|
@@ -3043,10 +3375,12 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3043
3375
|
TypePredicateAnnotation(node) {
|
|
3044
3376
|
return {
|
|
3045
3377
|
type: 'TSTypePredicate',
|
|
3046
|
-
|
|
3378
|
+
loc: DUMMY_LOC,
|
|
3379
|
+
asserts: node.kind != null && node.kind === 'asserts',
|
|
3047
3380
|
parameterName: transform.Identifier(node.parameterName, false),
|
|
3048
3381
|
typeAnnotation: node.typeAnnotation && {
|
|
3049
3382
|
type: 'TSTypeAnnotation',
|
|
3383
|
+
loc: DUMMY_LOC,
|
|
3050
3384
|
typeAnnotation: transformTypeAnnotationType(node.typeAnnotation)
|
|
3051
3385
|
}
|
|
3052
3386
|
};
|
|
@@ -3055,6 +3389,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3055
3389
|
InferTypeAnnotation(node) {
|
|
3056
3390
|
return {
|
|
3057
3391
|
type: 'TSInferType',
|
|
3392
|
+
loc: DUMMY_LOC,
|
|
3058
3393
|
typeParameter: transform.TypeParameter(node.typeParameter)
|
|
3059
3394
|
};
|
|
3060
3395
|
},
|
|
@@ -3062,6 +3397,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3062
3397
|
KeyofTypeAnnotation(node) {
|
|
3063
3398
|
return {
|
|
3064
3399
|
type: 'TSTypeOperator',
|
|
3400
|
+
loc: DUMMY_LOC,
|
|
3065
3401
|
operator: 'keyof',
|
|
3066
3402
|
typeAnnotation: transformTypeAnnotationType(node.argument)
|
|
3067
3403
|
};
|
|
@@ -3076,11 +3412,14 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3076
3412
|
const hasReactImport = isReactImport(node, 'React');
|
|
3077
3413
|
return {
|
|
3078
3414
|
type: 'TSTypeReference',
|
|
3415
|
+
loc: DUMMY_LOC,
|
|
3079
3416
|
typeName: {
|
|
3080
3417
|
type: 'TSQualifiedName',
|
|
3418
|
+
loc: DUMMY_LOC,
|
|
3081
3419
|
left: getReactIdentifier(hasReactImport),
|
|
3082
3420
|
right: {
|
|
3083
3421
|
type: 'Identifier',
|
|
3422
|
+
loc: DUMMY_LOC,
|
|
3084
3423
|
name: `ReactNode`
|
|
3085
3424
|
}
|
|
3086
3425
|
},
|
|
@@ -3097,14 +3436,18 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3097
3436
|
const hasReactImport = isReactImport(node, 'React');
|
|
3098
3437
|
const returnType = {
|
|
3099
3438
|
type: 'TSTypeAnnotation',
|
|
3439
|
+
loc: DUMMY_LOC,
|
|
3100
3440
|
// If no rendersType we assume its ReactNode type.
|
|
3101
3441
|
typeAnnotation: {
|
|
3102
3442
|
type: 'TSTypeReference',
|
|
3443
|
+
loc: DUMMY_LOC,
|
|
3103
3444
|
typeName: {
|
|
3104
3445
|
type: 'TSQualifiedName',
|
|
3446
|
+
loc: DUMMY_LOC,
|
|
3105
3447
|
left: getReactIdentifier(hasReactImport),
|
|
3106
3448
|
right: {
|
|
3107
3449
|
type: 'Identifier',
|
|
3450
|
+
loc: DUMMY_LOC,
|
|
3108
3451
|
name: `ReactNode`
|
|
3109
3452
|
}
|
|
3110
3453
|
},
|
|
@@ -3113,6 +3456,7 @@ const getTransforms = (originalCode, scopeManager, opts) => {
|
|
|
3113
3456
|
};
|
|
3114
3457
|
return {
|
|
3115
3458
|
type: 'TSFunctionType',
|
|
3459
|
+
loc: DUMMY_LOC,
|
|
3116
3460
|
typeParameters,
|
|
3117
3461
|
params,
|
|
3118
3462
|
returnType
|