@react-native/codegen 0.72.5 → 0.73.0-nightly-20230605-5062553c6
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/README.md +2 -2
- package/lib/CodegenSchema.d.ts +15 -4
- package/lib/CodegenSchema.js.flow +33 -21
- package/lib/generators/components/CppHelpers.js +39 -2
- package/lib/generators/components/CppHelpers.js.flow +54 -5
- package/lib/generators/components/GenerateEventEmitterCpp.js +238 -55
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +233 -55
- package/lib/generators/components/GenerateEventEmitterH.js +77 -28
- package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -32
- package/lib/generators/components/GeneratePropsH.js +1 -2
- package/lib/generators/components/GeneratePropsH.js.flow +1 -2
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
- package/lib/generators/modules/GenerateModuleCpp.js +3 -3
- package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
- package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
- package/lib/parsers/error-utils.js +44 -0
- package/lib/parsers/error-utils.js.flow +59 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/flow/components/componentsUtils.js +12 -19
- package/lib/parsers/flow/components/componentsUtils.js.flow +16 -27
- package/lib/parsers/flow/components/events.js +157 -83
- package/lib/parsers/flow/components/events.js.flow +158 -82
- package/lib/parsers/flow/components/index.js +10 -129
- package/lib/parsers/flow/components/index.js.flow +10 -150
- package/lib/parsers/flow/modules/index.js +39 -49
- package/lib/parsers/flow/modules/index.js.flow +22 -31
- package/lib/parsers/flow/parser.d.ts +9 -2
- package/lib/parsers/flow/parser.js +177 -16
- package/lib/parsers/flow/parser.js.flow +220 -6
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +143 -1
- package/lib/parsers/parserMock.js +175 -2
- package/lib/parsers/parserMock.js.flow +227 -2
- package/lib/parsers/parsers-commons.js +169 -9
- package/lib/parsers/parsers-commons.js.flow +233 -12
- package/lib/parsers/parsers-primitives.js +94 -35
- package/lib/parsers/parsers-primitives.js.flow +124 -35
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/typescript/components/componentsUtils.js +44 -46
- package/lib/parsers/typescript/components/componentsUtils.js.flow +44 -51
- package/lib/parsers/typescript/components/events.js +142 -72
- package/lib/parsers/typescript/components/events.js.flow +149 -73
- package/lib/parsers/typescript/components/extends.js +2 -49
- package/lib/parsers/typescript/components/extends.js.flow +1 -55
- package/lib/parsers/typescript/components/index.js +11 -134
- package/lib/parsers/typescript/components/index.js.flow +11 -156
- package/lib/parsers/typescript/modules/index.js +43 -51
- package/lib/parsers/typescript/modules/index.js.flow +25 -32
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +224 -7
- package/lib/parsers/typescript/parser.js.flow +262 -6
- package/lib/parsers/utils.js.flow +6 -0
- package/package.json +16 -5
- package/lib/parsers/flow/components/extends.js +0 -52
- package/lib/parsers/flow/components/extends.js.flow +0 -66
- package/lib/parsers/flow/components/props.js +0 -47
- package/lib/parsers/flow/components/props.js.flow +0 -60
- package/lib/parsers/typescript/components/props.js +0 -39
- package/lib/parsers/typescript/components/props.js.flow +0 -48
- package/lib/parsers/typescript/utils.js +0 -90
- package/lib/parsers/typescript/utils.js.flow +0 -104
|
@@ -14,7 +14,9 @@ import type {
|
|
|
14
14
|
Nullable,
|
|
15
15
|
BooleanTypeAnnotation,
|
|
16
16
|
DoubleTypeAnnotation,
|
|
17
|
+
EventTypeAnnotation,
|
|
17
18
|
Int32TypeAnnotation,
|
|
19
|
+
NamedShape,
|
|
18
20
|
NativeModuleAliasMap,
|
|
19
21
|
NativeModuleEnumMap,
|
|
20
22
|
NativeModuleBaseTypeAnnotation,
|
|
@@ -74,6 +76,19 @@ function emitInt32(nullable: boolean): Nullable<Int32TypeAnnotation> {
|
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
function emitInt32Prop(
|
|
80
|
+
name: string,
|
|
81
|
+
optional: boolean,
|
|
82
|
+
): NamedShape<Int32TypeAnnotation> {
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
optional,
|
|
86
|
+
typeAnnotation: {
|
|
87
|
+
type: 'Int32TypeAnnotation',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
function emitNumber(
|
|
78
93
|
nullable: boolean,
|
|
79
94
|
): Nullable<NativeModuleNumberTypeAnnotation> {
|
|
@@ -95,6 +110,19 @@ function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
|
|
|
95
110
|
});
|
|
96
111
|
}
|
|
97
112
|
|
|
113
|
+
function emitDoubleProp(
|
|
114
|
+
name: string,
|
|
115
|
+
optional: boolean,
|
|
116
|
+
): NamedShape<DoubleTypeAnnotation> {
|
|
117
|
+
return {
|
|
118
|
+
name,
|
|
119
|
+
optional,
|
|
120
|
+
typeAnnotation: {
|
|
121
|
+
type: 'DoubleTypeAnnotation',
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
98
126
|
function emitVoid(nullable: boolean): Nullable<VoidTypeAnnotation> {
|
|
99
127
|
return wrapNullable(nullable, {
|
|
100
128
|
type: 'VoidTypeAnnotation',
|
|
@@ -148,6 +176,19 @@ function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
|
|
|
148
176
|
});
|
|
149
177
|
}
|
|
150
178
|
|
|
179
|
+
function emitStringProp(
|
|
180
|
+
name: string,
|
|
181
|
+
optional: boolean,
|
|
182
|
+
): NamedShape<StringTypeAnnotation> {
|
|
183
|
+
return {
|
|
184
|
+
name,
|
|
185
|
+
optional,
|
|
186
|
+
typeAnnotation: {
|
|
187
|
+
type: 'StringTypeAnnotation',
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
151
192
|
function typeAliasResolution(
|
|
152
193
|
typeResolution: TypeResolutionStatus,
|
|
153
194
|
objectTypeAnnotation: ObjectTypeAnnotation<
|
|
@@ -309,6 +350,16 @@ function emitGenericObject(
|
|
|
309
350
|
});
|
|
310
351
|
}
|
|
311
352
|
|
|
353
|
+
function emitDictionary(
|
|
354
|
+
nullable: boolean,
|
|
355
|
+
valueType: Nullable<NativeModuleTypeAnnotation>,
|
|
356
|
+
): Nullable<NativeModuleGenericObjectTypeAnnotation> {
|
|
357
|
+
return wrapNullable(nullable, {
|
|
358
|
+
type: 'GenericObjectTypeAnnotation',
|
|
359
|
+
dictionaryValueType: valueType,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
312
363
|
function emitObject(
|
|
313
364
|
nullable: boolean,
|
|
314
365
|
properties: Array<$FlowFixMe>,
|
|
@@ -327,6 +378,19 @@ function emitFloat(
|
|
|
327
378
|
});
|
|
328
379
|
}
|
|
329
380
|
|
|
381
|
+
function emitFloatProp(
|
|
382
|
+
name: string,
|
|
383
|
+
optional: boolean,
|
|
384
|
+
): NamedShape<EventTypeAnnotation> {
|
|
385
|
+
return {
|
|
386
|
+
name,
|
|
387
|
+
optional,
|
|
388
|
+
typeAnnotation: {
|
|
389
|
+
type: 'FloatTypeAnnotation',
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
330
394
|
function emitUnion(
|
|
331
395
|
nullable: boolean,
|
|
332
396
|
hasteModuleName: string,
|
|
@@ -476,6 +540,7 @@ function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
|
|
|
476
540
|
}
|
|
477
541
|
|
|
478
542
|
function emitPartial(
|
|
543
|
+
nullable: boolean,
|
|
479
544
|
hasteModuleName: string,
|
|
480
545
|
typeAnnotation: $FlowFixMe,
|
|
481
546
|
types: TypeDeclarationMap,
|
|
@@ -483,7 +548,6 @@ function emitPartial(
|
|
|
483
548
|
enumMap: {...NativeModuleEnumMap},
|
|
484
549
|
tryParse: ParserErrorCapturer,
|
|
485
550
|
cxxOnly: boolean,
|
|
486
|
-
nullable: boolean,
|
|
487
551
|
parser: Parser,
|
|
488
552
|
): Nullable<NativeModuleTypeAnnotation> {
|
|
489
553
|
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
@@ -521,61 +585,86 @@ function emitCommonTypes(
|
|
|
521
585
|
nullable: boolean,
|
|
522
586
|
parser: Parser,
|
|
523
587
|
): $FlowFixMe {
|
|
588
|
+
const typeMap = {
|
|
589
|
+
Stringish: emitStringish,
|
|
590
|
+
Int32: emitInt32,
|
|
591
|
+
Double: emitDouble,
|
|
592
|
+
Float: emitFloat,
|
|
593
|
+
UnsafeObject: emitGenericObject,
|
|
594
|
+
Object: emitGenericObject,
|
|
595
|
+
$Partial: emitPartial,
|
|
596
|
+
Partial: emitPartial,
|
|
597
|
+
BooleanTypeAnnotation: emitBoolean,
|
|
598
|
+
NumberTypeAnnotation: emitNumber,
|
|
599
|
+
VoidTypeAnnotation: emitVoid,
|
|
600
|
+
StringTypeAnnotation: emitString,
|
|
601
|
+
MixedTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
const typeAnnotationName = parser.convertKeywordToTypeAnnotation(
|
|
605
|
+
typeAnnotation.type,
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
const simpleEmitter = typeMap[typeAnnotationName];
|
|
609
|
+
if (simpleEmitter) {
|
|
610
|
+
return simpleEmitter(nullable);
|
|
611
|
+
}
|
|
612
|
+
|
|
524
613
|
const genericTypeAnnotationName =
|
|
525
614
|
parser.nameForGenericTypeAnnotation(typeAnnotation);
|
|
526
615
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
case 'Int32': {
|
|
532
|
-
return emitInt32(nullable);
|
|
533
|
-
}
|
|
534
|
-
case 'Double': {
|
|
535
|
-
return emitDouble(nullable);
|
|
536
|
-
}
|
|
537
|
-
case 'Float': {
|
|
538
|
-
return emitFloat(nullable);
|
|
539
|
-
}
|
|
540
|
-
case 'UnsafeObject':
|
|
541
|
-
case 'Object': {
|
|
542
|
-
return emitGenericObject(nullable);
|
|
543
|
-
}
|
|
544
|
-
case '$Partial':
|
|
545
|
-
case 'Partial': {
|
|
546
|
-
return emitPartial(
|
|
547
|
-
hasteModuleName,
|
|
548
|
-
typeAnnotation,
|
|
549
|
-
types,
|
|
550
|
-
aliasMap,
|
|
551
|
-
enumMap,
|
|
552
|
-
tryParse,
|
|
553
|
-
cxxOnly,
|
|
554
|
-
nullable,
|
|
555
|
-
parser,
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
default: {
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
616
|
+
const emitter = typeMap[genericTypeAnnotationName];
|
|
617
|
+
if (!emitter) {
|
|
618
|
+
return null;
|
|
561
619
|
}
|
|
620
|
+
|
|
621
|
+
return emitter(
|
|
622
|
+
nullable,
|
|
623
|
+
hasteModuleName,
|
|
624
|
+
typeAnnotation,
|
|
625
|
+
types,
|
|
626
|
+
aliasMap,
|
|
627
|
+
enumMap,
|
|
628
|
+
tryParse,
|
|
629
|
+
cxxOnly,
|
|
630
|
+
parser,
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function emitBoolProp(
|
|
635
|
+
name: string,
|
|
636
|
+
optional: boolean,
|
|
637
|
+
): NamedShape<EventTypeAnnotation> {
|
|
638
|
+
return {
|
|
639
|
+
name,
|
|
640
|
+
optional,
|
|
641
|
+
typeAnnotation: {
|
|
642
|
+
type: 'BooleanTypeAnnotation',
|
|
643
|
+
},
|
|
644
|
+
};
|
|
562
645
|
}
|
|
563
646
|
|
|
564
647
|
module.exports = {
|
|
565
648
|
emitArrayType,
|
|
566
649
|
emitBoolean,
|
|
650
|
+
emitBoolProp,
|
|
567
651
|
emitDouble,
|
|
652
|
+
emitDoubleProp,
|
|
568
653
|
emitFloat,
|
|
654
|
+
emitFloatProp,
|
|
569
655
|
emitFunction,
|
|
570
656
|
emitInt32,
|
|
657
|
+
emitInt32Prop,
|
|
571
658
|
emitNumber,
|
|
572
659
|
emitGenericObject,
|
|
660
|
+
emitDictionary,
|
|
573
661
|
emitObject,
|
|
574
662
|
emitPromise,
|
|
575
663
|
emitRootTag,
|
|
576
664
|
emitVoid,
|
|
577
665
|
emitString,
|
|
578
666
|
emitStringish,
|
|
667
|
+
emitStringProp,
|
|
579
668
|
emitMixed,
|
|
580
669
|
emitUnion,
|
|
581
670
|
emitPartial,
|
|
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
|
|
|
84
84
|
object_readonly_optional_both?: Readonly<{
|
|
85
85
|
int32_optional_both?: Int32 | null | undefined;
|
|
86
86
|
}> | null | undefined;
|
|
87
|
+
|
|
88
|
+
boolean_array_required: boolean[];
|
|
89
|
+
boolean_array_optional_key?: boolean[];
|
|
90
|
+
boolean_array_optional_value: boolean[] | null | undefined;
|
|
91
|
+
boolean_array_optional_both?: boolean[] | null | undefined;
|
|
92
|
+
|
|
93
|
+
string_array_required: string[];
|
|
94
|
+
string_array_optional_key?: (string[]);
|
|
95
|
+
string_array_optional_value: (string[]) | null | undefined;
|
|
96
|
+
string_array_optional_both?: (string[] | null | undefined);
|
|
97
|
+
|
|
98
|
+
double_array_required: Double[];
|
|
99
|
+
double_array_optional_key?: Double[];
|
|
100
|
+
double_array_optional_value: Double[] | null | undefined;
|
|
101
|
+
double_array_optional_both?: Double[] | null | undefined;
|
|
102
|
+
|
|
103
|
+
float_array_required: Float[];
|
|
104
|
+
float_array_optional_key?: Float[];
|
|
105
|
+
float_array_optional_value: Float[] | null | undefined;
|
|
106
|
+
float_array_optional_both?: Float[] | null | undefined;
|
|
107
|
+
|
|
108
|
+
int32_array_required: Int32[];
|
|
109
|
+
int32_array_optional_key?: Int32[];
|
|
110
|
+
int32_array_optional_value: Int32[] | null | undefined;
|
|
111
|
+
int32_array_optional_both?: Int32[] | null | undefined;
|
|
112
|
+
|
|
113
|
+
enum_array_required: ('small' | 'large')[];
|
|
114
|
+
enum_array_optional_key?: ('small' | 'large')[];
|
|
115
|
+
enum_array_optional_value: ('small' | 'large')[] | null | undefined;
|
|
116
|
+
enum_array_optional_both?: ('small' | 'large')[] | null | undefined;
|
|
117
|
+
|
|
118
|
+
object_array_required: {
|
|
119
|
+
boolean_required: boolean;
|
|
120
|
+
}[];
|
|
121
|
+
|
|
122
|
+
object_array_optional_key?: {
|
|
123
|
+
string_optional_key?: string;
|
|
124
|
+
}[];
|
|
125
|
+
|
|
126
|
+
object_array_optional_value: {
|
|
127
|
+
float_optional_value: Float | null | undefined;
|
|
128
|
+
}[] | null | undefined;
|
|
129
|
+
|
|
130
|
+
object_array_optional_both?: {
|
|
131
|
+
int32_optional_both?: Int32 | null | undefined;
|
|
132
|
+
}[] | null | undefined;
|
|
133
|
+
|
|
134
|
+
int32_array_array_required: Int32[][];
|
|
135
|
+
int32_array_array_optional_key?: Int32[][];
|
|
136
|
+
int32_array_array_optional_value: Int32[][] | null | undefined;
|
|
137
|
+
int32_array_array_optional_both?: Int32[][] | null | undefined;
|
|
87
138
|
`;
|
|
88
139
|
const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
|
|
89
140
|
/**
|
|
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
|
|
|
84
84
|
object_readonly_optional_both?: Readonly<{
|
|
85
85
|
int32_optional_both?: Int32 | null | undefined;
|
|
86
86
|
}> | null | undefined;
|
|
87
|
+
|
|
88
|
+
boolean_array_required: boolean[];
|
|
89
|
+
boolean_array_optional_key?: boolean[];
|
|
90
|
+
boolean_array_optional_value: boolean[] | null | undefined;
|
|
91
|
+
boolean_array_optional_both?: boolean[] | null | undefined;
|
|
92
|
+
|
|
93
|
+
string_array_required: string[];
|
|
94
|
+
string_array_optional_key?: (string[]);
|
|
95
|
+
string_array_optional_value: (string[]) | null | undefined;
|
|
96
|
+
string_array_optional_both?: (string[] | null | undefined);
|
|
97
|
+
|
|
98
|
+
double_array_required: Double[];
|
|
99
|
+
double_array_optional_key?: Double[];
|
|
100
|
+
double_array_optional_value: Double[] | null | undefined;
|
|
101
|
+
double_array_optional_both?: Double[] | null | undefined;
|
|
102
|
+
|
|
103
|
+
float_array_required: Float[];
|
|
104
|
+
float_array_optional_key?: Float[];
|
|
105
|
+
float_array_optional_value: Float[] | null | undefined;
|
|
106
|
+
float_array_optional_both?: Float[] | null | undefined;
|
|
107
|
+
|
|
108
|
+
int32_array_required: Int32[];
|
|
109
|
+
int32_array_optional_key?: Int32[];
|
|
110
|
+
int32_array_optional_value: Int32[] | null | undefined;
|
|
111
|
+
int32_array_optional_both?: Int32[] | null | undefined;
|
|
112
|
+
|
|
113
|
+
enum_array_required: ('small' | 'large')[];
|
|
114
|
+
enum_array_optional_key?: ('small' | 'large')[];
|
|
115
|
+
enum_array_optional_value: ('small' | 'large')[] | null | undefined;
|
|
116
|
+
enum_array_optional_both?: ('small' | 'large')[] | null | undefined;
|
|
117
|
+
|
|
118
|
+
object_array_required: {
|
|
119
|
+
boolean_required: boolean;
|
|
120
|
+
}[];
|
|
121
|
+
|
|
122
|
+
object_array_optional_key?: {
|
|
123
|
+
string_optional_key?: string;
|
|
124
|
+
}[];
|
|
125
|
+
|
|
126
|
+
object_array_optional_value: {
|
|
127
|
+
float_optional_value: Float | null | undefined;
|
|
128
|
+
}[] | null | undefined;
|
|
129
|
+
|
|
130
|
+
object_array_optional_both?: {
|
|
131
|
+
int32_optional_both?: Int32 | null | undefined;
|
|
132
|
+
}[] | null | undefined;
|
|
133
|
+
|
|
134
|
+
int32_array_array_required: Int32[][];
|
|
135
|
+
int32_array_array_optional_key?: Int32[][];
|
|
136
|
+
int32_array_array_optional_value: Int32[][] | null | undefined;
|
|
137
|
+
int32_array_array_optional_both?: Int32[][] | null | undefined;
|
|
87
138
|
`;
|
|
88
139
|
|
|
89
140
|
const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
|
|
@@ -13,37 +13,6 @@
|
|
|
13
13
|
const _require = require('../parseTopLevelType'),
|
|
14
14
|
parseTopLevelType = _require.parseTopLevelType,
|
|
15
15
|
flattenIntersectionType = _require.flattenIntersectionType;
|
|
16
|
-
function getProperties(typeName, types) {
|
|
17
|
-
const alias = types[typeName];
|
|
18
|
-
if (!alias) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Failed to find definition for "${typeName}", please check that you have a valid codegen typescript file`,
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
const aliasKind =
|
|
24
|
-
alias.type === 'TSInterfaceDeclaration' ? 'interface' : 'type';
|
|
25
|
-
try {
|
|
26
|
-
if (aliasKind === 'interface') {
|
|
27
|
-
var _alias$extends;
|
|
28
|
-
return [
|
|
29
|
-
...((_alias$extends = alias.extends) !== null &&
|
|
30
|
-
_alias$extends !== void 0
|
|
31
|
-
? _alias$extends
|
|
32
|
-
: []),
|
|
33
|
-
...alias.body.body,
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
return (
|
|
37
|
-
alias.typeAnnotation.members ||
|
|
38
|
-
alias.typeAnnotation.typeParameters.params[0].members ||
|
|
39
|
-
alias.typeAnnotation.typeParameters.params
|
|
40
|
-
);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`Failed to find ${aliasKind} definition for "${typeName}", please check that you have a valid codegen typescript file`,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
16
|
function getUnionOfLiterals(name, forArray, elementTypes, defaultValue, types) {
|
|
48
17
|
var _elementTypes$0$liter, _elementTypes$0$liter2;
|
|
49
18
|
elementTypes.reduce((lastType, currType) => {
|
|
@@ -109,6 +78,7 @@ function detectArrayType(
|
|
|
109
78
|
typeAnnotation,
|
|
110
79
|
defaultValue,
|
|
111
80
|
types,
|
|
81
|
+
parser,
|
|
112
82
|
buildSchema,
|
|
113
83
|
) {
|
|
114
84
|
// Covers: readonly T[]
|
|
@@ -124,6 +94,7 @@ function detectArrayType(
|
|
|
124
94
|
typeAnnotation.typeAnnotation.elementType,
|
|
125
95
|
defaultValue,
|
|
126
96
|
types,
|
|
97
|
+
parser,
|
|
127
98
|
buildSchema,
|
|
128
99
|
),
|
|
129
100
|
};
|
|
@@ -138,6 +109,7 @@ function detectArrayType(
|
|
|
138
109
|
typeAnnotation.elementType,
|
|
139
110
|
defaultValue,
|
|
140
111
|
types,
|
|
112
|
+
parser,
|
|
141
113
|
buildSchema,
|
|
142
114
|
),
|
|
143
115
|
};
|
|
@@ -156,16 +128,17 @@ function detectArrayType(
|
|
|
156
128
|
typeAnnotation.typeParameters.params[0],
|
|
157
129
|
defaultValue,
|
|
158
130
|
types,
|
|
131
|
+
parser,
|
|
159
132
|
buildSchema,
|
|
160
133
|
),
|
|
161
134
|
};
|
|
162
135
|
}
|
|
163
136
|
return null;
|
|
164
137
|
}
|
|
165
|
-
function buildObjectType(rawProperties, types, buildSchema) {
|
|
166
|
-
const flattenedProperties = flattenProperties(rawProperties, types);
|
|
138
|
+
function buildObjectType(rawProperties, types, parser, buildSchema) {
|
|
139
|
+
const flattenedProperties = flattenProperties(rawProperties, types, parser);
|
|
167
140
|
const properties = flattenedProperties
|
|
168
|
-
.map(prop => buildSchema(prop, types))
|
|
141
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
169
142
|
.filter(Boolean);
|
|
170
143
|
return {
|
|
171
144
|
type: 'ObjectTypeAnnotation',
|
|
@@ -179,17 +152,24 @@ function getCommonTypeAnnotation(
|
|
|
179
152
|
typeAnnotation,
|
|
180
153
|
defaultValue,
|
|
181
154
|
types,
|
|
155
|
+
parser,
|
|
182
156
|
buildSchema,
|
|
183
157
|
) {
|
|
184
158
|
switch (type) {
|
|
185
159
|
case 'TSTypeLiteral':
|
|
186
|
-
return buildObjectType(
|
|
160
|
+
return buildObjectType(
|
|
161
|
+
typeAnnotation.members,
|
|
162
|
+
types,
|
|
163
|
+
parser,
|
|
164
|
+
buildSchema,
|
|
165
|
+
);
|
|
187
166
|
case 'TSInterfaceDeclaration':
|
|
188
|
-
return buildObjectType([typeAnnotation], types, buildSchema);
|
|
167
|
+
return buildObjectType([typeAnnotation], types, parser, buildSchema);
|
|
189
168
|
case 'TSIntersectionType':
|
|
190
169
|
return buildObjectType(
|
|
191
170
|
flattenIntersectionType(typeAnnotation, types),
|
|
192
171
|
types,
|
|
172
|
+
parser,
|
|
193
173
|
buildSchema,
|
|
194
174
|
);
|
|
195
175
|
case 'ImageSource':
|
|
@@ -265,6 +245,7 @@ function getTypeAnnotationForArray(
|
|
|
265
245
|
typeAnnotation,
|
|
266
246
|
defaultValue,
|
|
267
247
|
types,
|
|
248
|
+
parser,
|
|
268
249
|
buildSchema,
|
|
269
250
|
) {
|
|
270
251
|
var _extractedTypeAnnotat, _extractedTypeAnnotat2;
|
|
@@ -286,6 +267,7 @@ function getTypeAnnotationForArray(
|
|
|
286
267
|
extractedTypeAnnotation,
|
|
287
268
|
defaultValue,
|
|
288
269
|
types,
|
|
270
|
+
parser,
|
|
289
271
|
buildSchema,
|
|
290
272
|
);
|
|
291
273
|
if (arrayType) {
|
|
@@ -315,6 +297,7 @@ function getTypeAnnotationForArray(
|
|
|
315
297
|
extractedTypeAnnotation,
|
|
316
298
|
defaultValue,
|
|
317
299
|
types,
|
|
300
|
+
parser,
|
|
318
301
|
buildSchema,
|
|
319
302
|
);
|
|
320
303
|
if (common) {
|
|
@@ -348,7 +331,16 @@ function setDefaultValue(common, defaultValue) {
|
|
|
348
331
|
break;
|
|
349
332
|
}
|
|
350
333
|
}
|
|
351
|
-
function getTypeAnnotation(
|
|
334
|
+
function getTypeAnnotation(
|
|
335
|
+
name,
|
|
336
|
+
annotation,
|
|
337
|
+
defaultValue,
|
|
338
|
+
withNullDefault,
|
|
339
|
+
// Just to make `getTypeAnnotation` signature match with the one from Flow
|
|
340
|
+
types,
|
|
341
|
+
parser,
|
|
342
|
+
buildSchema,
|
|
343
|
+
) {
|
|
352
344
|
// unpack WithDefault, (T) or T|U
|
|
353
345
|
const topLevelType = parseTopLevelType(annotation, types);
|
|
354
346
|
const typeAnnotation = topLevelType.type;
|
|
@@ -357,6 +349,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
357
349
|
typeAnnotation,
|
|
358
350
|
defaultValue,
|
|
359
351
|
types,
|
|
352
|
+
parser,
|
|
360
353
|
buildSchema,
|
|
361
354
|
);
|
|
362
355
|
if (arrayType) {
|
|
@@ -374,6 +367,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
374
367
|
typeAnnotation,
|
|
375
368
|
defaultValue,
|
|
376
369
|
types,
|
|
370
|
+
parser,
|
|
377
371
|
buildSchema,
|
|
378
372
|
);
|
|
379
373
|
if (common) {
|
|
@@ -419,11 +413,10 @@ function getSchemaInfo(property, types) {
|
|
|
419
413
|
optional: property.optional || topLevelType.optional,
|
|
420
414
|
typeAnnotation: topLevelType.type,
|
|
421
415
|
defaultValue: topLevelType.defaultValue,
|
|
416
|
+
withNullDefault: false, // Just to make `getTypeAnnotation` signature match with the one from Flow
|
|
422
417
|
};
|
|
423
418
|
}
|
|
424
419
|
|
|
425
|
-
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
426
|
-
|
|
427
420
|
function verifyPropNotAlreadyDefined(props, needleProp) {
|
|
428
421
|
const propName = needleProp.key.name;
|
|
429
422
|
const foundProp = props.some(prop => prop.key.name === propName);
|
|
@@ -431,30 +424,36 @@ function verifyPropNotAlreadyDefined(props, needleProp) {
|
|
|
431
424
|
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
432
425
|
}
|
|
433
426
|
}
|
|
434
|
-
function flattenProperties(typeDefinition, types) {
|
|
427
|
+
function flattenProperties(typeDefinition, types, parser) {
|
|
435
428
|
return typeDefinition
|
|
436
429
|
.map(property => {
|
|
437
430
|
if (property.type === 'TSPropertySignature') {
|
|
438
431
|
return property;
|
|
439
432
|
} else if (property.type === 'TSTypeReference') {
|
|
440
433
|
return flattenProperties(
|
|
441
|
-
getProperties(property.typeName.name, types),
|
|
434
|
+
parser.getProperties(property.typeName.name, types),
|
|
442
435
|
types,
|
|
436
|
+
parser,
|
|
443
437
|
);
|
|
444
438
|
} else if (
|
|
445
439
|
property.type === 'TSExpressionWithTypeArguments' ||
|
|
446
440
|
property.type === 'TSInterfaceHeritage'
|
|
447
441
|
) {
|
|
448
442
|
return flattenProperties(
|
|
449
|
-
getProperties(property.expression.name, types),
|
|
443
|
+
parser.getProperties(property.expression.name, types),
|
|
450
444
|
types,
|
|
445
|
+
parser,
|
|
451
446
|
);
|
|
452
447
|
} else if (property.type === 'TSTypeLiteral') {
|
|
453
|
-
return flattenProperties(property.members, types);
|
|
448
|
+
return flattenProperties(property.members, types, parser);
|
|
454
449
|
} else if (property.type === 'TSInterfaceDeclaration') {
|
|
455
|
-
return flattenProperties(
|
|
450
|
+
return flattenProperties(
|
|
451
|
+
parser.getProperties(property.id.name, types),
|
|
452
|
+
types,
|
|
453
|
+
parser,
|
|
454
|
+
);
|
|
456
455
|
} else if (property.type === 'TSIntersectionType') {
|
|
457
|
-
return flattenProperties(property.types, types);
|
|
456
|
+
return flattenProperties(property.types, types, parser);
|
|
458
457
|
} else {
|
|
459
458
|
throw new Error(
|
|
460
459
|
`${property.type} is not a supported object literal type.`,
|
|
@@ -477,7 +476,6 @@ function flattenProperties(typeDefinition, types) {
|
|
|
477
476
|
.filter(Boolean);
|
|
478
477
|
}
|
|
479
478
|
module.exports = {
|
|
480
|
-
getProperties,
|
|
481
479
|
getSchemaInfo,
|
|
482
480
|
getTypeAnnotation,
|
|
483
481
|
flattenProperties,
|