@react-native/codegen 0.73.0 → 0.74.0-nightly-20231003-5dedf277c
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/cli/combine/combine-js-to-schema-cli.js +7 -1
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +7 -1
- package/lib/generators/components/CppHelpers.js +39 -2
- package/lib/generators/components/CppHelpers.js.flow +54 -5
- package/lib/generators/components/GenerateEventEmitterCpp.js +222 -28
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +221 -34
- package/lib/generators/components/GenerateEventEmitterH.js +77 -26
- package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -30
- package/lib/generators/components/GeneratePropsH.js +2 -3
- package/lib/generators/components/GeneratePropsH.js.flow +2 -3
- 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 +1 -1
- package/lib/generators/modules/GenerateModuleCpp.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleH.js +44 -39
- package/lib/generators/modules/GenerateModuleH.js.flow +51 -39
- package/lib/generators/modules/GenerateModuleJavaSpec.js +9 -7
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +10 -6
- package/lib/generators/modules/GenerateModuleJniH.js +1 -1
- package/lib/generators/modules/GenerateModuleJniH.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +11 -3
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +13 -3
- package/lib/parsers/error-utils.js +44 -0
- package/lib/parsers/error-utils.js.flow +59 -0
- package/lib/parsers/errors.js +3 -9
- package/lib/parsers/errors.js.flow +3 -9
- 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 +22 -33
- package/lib/parsers/flow/components/componentsUtils.js.flow +24 -45
- package/lib/parsers/flow/components/events.js +151 -128
- package/lib/parsers/flow/components/events.js.flow +161 -136
- package/lib/parsers/flow/components/index.js +13 -94
- package/lib/parsers/flow/components/index.js.flow +5 -102
- package/lib/parsers/flow/modules/index.js +24 -24
- package/lib/parsers/flow/modules/index.js.flow +6 -6
- package/lib/parsers/flow/parser.d.ts +9 -2
- package/lib/parsers/flow/parser.js +179 -18
- package/lib/parsers/flow/parser.js.flow +231 -7
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +176 -3
- package/lib/parsers/parserMock.js +202 -4
- package/lib/parsers/parserMock.js.flow +253 -4
- package/lib/parsers/parsers-commons.js +268 -10
- package/lib/parsers/parsers-commons.js.flow +365 -12
- package/lib/parsers/parsers-primitives.js +95 -1
- package/lib/parsers/parsers-primitives.js.flow +136 -1
- 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 +49 -57
- package/lib/parsers/typescript/components/componentsUtils.js.flow +48 -66
- package/lib/parsers/typescript/components/events.js +136 -115
- package/lib/parsers/typescript/components/events.js.flow +148 -119
- 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 +14 -99
- package/lib/parsers/typescript/components/index.js.flow +6 -106
- package/lib/parsers/typescript/modules/index.js +28 -26
- package/lib/parsers/typescript/modules/index.js.flow +9 -8
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +208 -14
- package/lib/parsers/typescript/parser.js.flow +247 -8
- package/lib/parsers/utils.js.flow +6 -0
- package/package.json +27 -16
- 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,
|
|
@@ -547,7 +611,7 @@ function emitCommonTypes(
|
|
|
547
611
|
}
|
|
548
612
|
|
|
549
613
|
const genericTypeAnnotationName =
|
|
550
|
-
parser.
|
|
614
|
+
parser.getTypeAnnotationName(typeAnnotation);
|
|
551
615
|
|
|
552
616
|
const emitter = typeMap[genericTypeAnnotationName];
|
|
553
617
|
if (!emitter) {
|
|
@@ -567,21 +631,90 @@ function emitCommonTypes(
|
|
|
567
631
|
);
|
|
568
632
|
}
|
|
569
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
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function emitMixedProp(
|
|
648
|
+
name: string,
|
|
649
|
+
optional: boolean,
|
|
650
|
+
): NamedShape<EventTypeAnnotation> {
|
|
651
|
+
return {
|
|
652
|
+
name,
|
|
653
|
+
optional,
|
|
654
|
+
typeAnnotation: {
|
|
655
|
+
type: 'MixedTypeAnnotation',
|
|
656
|
+
},
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function emitObjectProp(
|
|
661
|
+
name: string,
|
|
662
|
+
optional: boolean,
|
|
663
|
+
parser: Parser,
|
|
664
|
+
typeAnnotation: $FlowFixMe,
|
|
665
|
+
extractArrayElementType: (
|
|
666
|
+
typeAnnotation: $FlowFixMe,
|
|
667
|
+
name: string,
|
|
668
|
+
parser: Parser,
|
|
669
|
+
) => EventTypeAnnotation,
|
|
670
|
+
): NamedShape<EventTypeAnnotation> {
|
|
671
|
+
return {
|
|
672
|
+
name,
|
|
673
|
+
optional,
|
|
674
|
+
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function emitUnionProp(
|
|
679
|
+
name: string,
|
|
680
|
+
optional: boolean,
|
|
681
|
+
parser: Parser,
|
|
682
|
+
typeAnnotation: $FlowFixMe,
|
|
683
|
+
): NamedShape<EventTypeAnnotation> {
|
|
684
|
+
return {
|
|
685
|
+
name,
|
|
686
|
+
optional,
|
|
687
|
+
typeAnnotation: {
|
|
688
|
+
type: 'StringEnumTypeAnnotation',
|
|
689
|
+
options: typeAnnotation.types.map(option =>
|
|
690
|
+
parser.getLiteralValue(option),
|
|
691
|
+
),
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
570
696
|
module.exports = {
|
|
571
697
|
emitArrayType,
|
|
572
698
|
emitBoolean,
|
|
699
|
+
emitBoolProp,
|
|
573
700
|
emitDouble,
|
|
701
|
+
emitDoubleProp,
|
|
574
702
|
emitFloat,
|
|
703
|
+
emitFloatProp,
|
|
575
704
|
emitFunction,
|
|
576
705
|
emitInt32,
|
|
706
|
+
emitInt32Prop,
|
|
707
|
+
emitMixedProp,
|
|
577
708
|
emitNumber,
|
|
578
709
|
emitGenericObject,
|
|
710
|
+
emitDictionary,
|
|
579
711
|
emitObject,
|
|
580
712
|
emitPromise,
|
|
581
713
|
emitRootTag,
|
|
582
714
|
emitVoid,
|
|
583
715
|
emitString,
|
|
584
716
|
emitStringish,
|
|
717
|
+
emitStringProp,
|
|
585
718
|
emitMixed,
|
|
586
719
|
emitUnion,
|
|
587
720
|
emitPartial,
|
|
@@ -590,4 +723,6 @@ module.exports = {
|
|
|
590
723
|
typeEnumResolution,
|
|
591
724
|
translateArrayTypeAnnotation,
|
|
592
725
|
Visitor,
|
|
726
|
+
emitObjectProp,
|
|
727
|
+
emitUnionProp,
|
|
593
728
|
};
|
|
@@ -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,8 @@
|
|
|
13
13
|
const _require = require('../parseTopLevelType'),
|
|
14
14
|
parseTopLevelType = _require.parseTopLevelType,
|
|
15
15
|
flattenIntersectionType = _require.flattenIntersectionType;
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
}
|
|
16
|
+
const _require2 = require('../../parsers-commons'),
|
|
17
|
+
verifyPropNotAlreadyDefined = _require2.verifyPropNotAlreadyDefined;
|
|
47
18
|
function getUnionOfLiterals(name, forArray, elementTypes, defaultValue, types) {
|
|
48
19
|
var _elementTypes$0$liter, _elementTypes$0$liter2;
|
|
49
20
|
elementTypes.reduce((lastType, currType) => {
|
|
@@ -109,6 +80,7 @@ function detectArrayType(
|
|
|
109
80
|
typeAnnotation,
|
|
110
81
|
defaultValue,
|
|
111
82
|
types,
|
|
83
|
+
parser,
|
|
112
84
|
buildSchema,
|
|
113
85
|
) {
|
|
114
86
|
// Covers: readonly T[]
|
|
@@ -124,6 +96,7 @@ function detectArrayType(
|
|
|
124
96
|
typeAnnotation.typeAnnotation.elementType,
|
|
125
97
|
defaultValue,
|
|
126
98
|
types,
|
|
99
|
+
parser,
|
|
127
100
|
buildSchema,
|
|
128
101
|
),
|
|
129
102
|
};
|
|
@@ -138,6 +111,7 @@ function detectArrayType(
|
|
|
138
111
|
typeAnnotation.elementType,
|
|
139
112
|
defaultValue,
|
|
140
113
|
types,
|
|
114
|
+
parser,
|
|
141
115
|
buildSchema,
|
|
142
116
|
),
|
|
143
117
|
};
|
|
@@ -146,8 +120,8 @@ function detectArrayType(
|
|
|
146
120
|
// Covers: Array<T> and ReadonlyArray<T>
|
|
147
121
|
if (
|
|
148
122
|
typeAnnotation.type === 'TSTypeReference' &&
|
|
149
|
-
(typeAnnotation
|
|
150
|
-
typeAnnotation
|
|
123
|
+
(parser.getTypeAnnotationName(typeAnnotation) === 'ReadonlyArray' ||
|
|
124
|
+
parser.getTypeAnnotationName(typeAnnotation) === 'Array')
|
|
151
125
|
) {
|
|
152
126
|
return {
|
|
153
127
|
type: 'ArrayTypeAnnotation',
|
|
@@ -156,16 +130,17 @@ function detectArrayType(
|
|
|
156
130
|
typeAnnotation.typeParameters.params[0],
|
|
157
131
|
defaultValue,
|
|
158
132
|
types,
|
|
133
|
+
parser,
|
|
159
134
|
buildSchema,
|
|
160
135
|
),
|
|
161
136
|
};
|
|
162
137
|
}
|
|
163
138
|
return null;
|
|
164
139
|
}
|
|
165
|
-
function buildObjectType(rawProperties, types, buildSchema) {
|
|
166
|
-
const flattenedProperties = flattenProperties(rawProperties, types);
|
|
140
|
+
function buildObjectType(rawProperties, types, parser, buildSchema) {
|
|
141
|
+
const flattenedProperties = flattenProperties(rawProperties, types, parser);
|
|
167
142
|
const properties = flattenedProperties
|
|
168
|
-
.map(prop => buildSchema(prop, types))
|
|
143
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
169
144
|
.filter(Boolean);
|
|
170
145
|
return {
|
|
171
146
|
type: 'ObjectTypeAnnotation',
|
|
@@ -179,17 +154,24 @@ function getCommonTypeAnnotation(
|
|
|
179
154
|
typeAnnotation,
|
|
180
155
|
defaultValue,
|
|
181
156
|
types,
|
|
157
|
+
parser,
|
|
182
158
|
buildSchema,
|
|
183
159
|
) {
|
|
184
160
|
switch (type) {
|
|
185
161
|
case 'TSTypeLiteral':
|
|
186
|
-
return buildObjectType(
|
|
162
|
+
return buildObjectType(
|
|
163
|
+
typeAnnotation.members,
|
|
164
|
+
types,
|
|
165
|
+
parser,
|
|
166
|
+
buildSchema,
|
|
167
|
+
);
|
|
187
168
|
case 'TSInterfaceDeclaration':
|
|
188
|
-
return buildObjectType([typeAnnotation], types, buildSchema);
|
|
169
|
+
return buildObjectType([typeAnnotation], types, parser, buildSchema);
|
|
189
170
|
case 'TSIntersectionType':
|
|
190
171
|
return buildObjectType(
|
|
191
172
|
flattenIntersectionType(typeAnnotation, types),
|
|
192
173
|
types,
|
|
174
|
+
parser,
|
|
193
175
|
buildSchema,
|
|
194
176
|
);
|
|
195
177
|
case 'ImageSource':
|
|
@@ -265,6 +247,7 @@ function getTypeAnnotationForArray(
|
|
|
265
247
|
typeAnnotation,
|
|
266
248
|
defaultValue,
|
|
267
249
|
types,
|
|
250
|
+
parser,
|
|
268
251
|
buildSchema,
|
|
269
252
|
) {
|
|
270
253
|
var _extractedTypeAnnotat, _extractedTypeAnnotat2;
|
|
@@ -286,6 +269,7 @@ function getTypeAnnotationForArray(
|
|
|
286
269
|
extractedTypeAnnotation,
|
|
287
270
|
defaultValue,
|
|
288
271
|
types,
|
|
272
|
+
parser,
|
|
289
273
|
buildSchema,
|
|
290
274
|
);
|
|
291
275
|
if (arrayType) {
|
|
@@ -315,6 +299,7 @@ function getTypeAnnotationForArray(
|
|
|
315
299
|
extractedTypeAnnotation,
|
|
316
300
|
defaultValue,
|
|
317
301
|
types,
|
|
302
|
+
parser,
|
|
318
303
|
buildSchema,
|
|
319
304
|
);
|
|
320
305
|
if (common) {
|
|
@@ -348,7 +333,16 @@ function setDefaultValue(common, defaultValue) {
|
|
|
348
333
|
break;
|
|
349
334
|
}
|
|
350
335
|
}
|
|
351
|
-
function getTypeAnnotation(
|
|
336
|
+
function getTypeAnnotation(
|
|
337
|
+
name,
|
|
338
|
+
annotation,
|
|
339
|
+
defaultValue,
|
|
340
|
+
withNullDefault,
|
|
341
|
+
// Just to make `getTypeAnnotation` signature match with the one from Flow
|
|
342
|
+
types,
|
|
343
|
+
parser,
|
|
344
|
+
buildSchema,
|
|
345
|
+
) {
|
|
352
346
|
// unpack WithDefault, (T) or T|U
|
|
353
347
|
const topLevelType = parseTopLevelType(annotation, types);
|
|
354
348
|
const typeAnnotation = topLevelType.type;
|
|
@@ -357,6 +351,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
357
351
|
typeAnnotation,
|
|
358
352
|
defaultValue,
|
|
359
353
|
types,
|
|
354
|
+
parser,
|
|
360
355
|
buildSchema,
|
|
361
356
|
);
|
|
362
357
|
if (arrayType) {
|
|
@@ -365,7 +360,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
365
360
|
const type =
|
|
366
361
|
typeAnnotation.type === 'TSTypeReference' ||
|
|
367
362
|
typeAnnotation.type === 'TSTypeAliasDeclaration'
|
|
368
|
-
? typeAnnotation
|
|
363
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
369
364
|
: typeAnnotation.type;
|
|
370
365
|
const common = getCommonTypeAnnotation(
|
|
371
366
|
name,
|
|
@@ -374,6 +369,7 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
374
369
|
typeAnnotation,
|
|
375
370
|
defaultValue,
|
|
376
371
|
types,
|
|
372
|
+
parser,
|
|
377
373
|
buildSchema,
|
|
378
374
|
);
|
|
379
375
|
if (common) {
|
|
@@ -398,7 +394,6 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
398
394
|
`Cannot use "${type}" type annotation for "${name}": must use a specific function type like BubblingEventHandler, or DirectEventHandler`,
|
|
399
395
|
);
|
|
400
396
|
default:
|
|
401
|
-
type;
|
|
402
397
|
throw new Error(`Unknown prop type for "${name}": "${type}"`);
|
|
403
398
|
}
|
|
404
399
|
}
|
|
@@ -419,42 +414,40 @@ function getSchemaInfo(property, types) {
|
|
|
419
414
|
optional: property.optional || topLevelType.optional,
|
|
420
415
|
typeAnnotation: topLevelType.type,
|
|
421
416
|
defaultValue: topLevelType.defaultValue,
|
|
417
|
+
withNullDefault: false, // Just to make `getTypeAnnotation` signature match with the one from Flow
|
|
422
418
|
};
|
|
423
419
|
}
|
|
424
420
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
function verifyPropNotAlreadyDefined(props, needleProp) {
|
|
428
|
-
const propName = needleProp.key.name;
|
|
429
|
-
const foundProp = props.some(prop => prop.key.name === propName);
|
|
430
|
-
if (foundProp) {
|
|
431
|
-
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
function flattenProperties(typeDefinition, types) {
|
|
421
|
+
function flattenProperties(typeDefinition, types, parser) {
|
|
435
422
|
return typeDefinition
|
|
436
423
|
.map(property => {
|
|
437
424
|
if (property.type === 'TSPropertySignature') {
|
|
438
425
|
return property;
|
|
439
426
|
} else if (property.type === 'TSTypeReference') {
|
|
440
427
|
return flattenProperties(
|
|
441
|
-
getProperties(property.typeName.name, types),
|
|
428
|
+
parser.getProperties(property.typeName.name, types),
|
|
442
429
|
types,
|
|
430
|
+
parser,
|
|
443
431
|
);
|
|
444
432
|
} else if (
|
|
445
433
|
property.type === 'TSExpressionWithTypeArguments' ||
|
|
446
434
|
property.type === 'TSInterfaceHeritage'
|
|
447
435
|
) {
|
|
448
436
|
return flattenProperties(
|
|
449
|
-
getProperties(property.expression.name, types),
|
|
437
|
+
parser.getProperties(property.expression.name, types),
|
|
450
438
|
types,
|
|
439
|
+
parser,
|
|
451
440
|
);
|
|
452
441
|
} else if (property.type === 'TSTypeLiteral') {
|
|
453
|
-
return flattenProperties(property.members, types);
|
|
442
|
+
return flattenProperties(property.members, types, parser);
|
|
454
443
|
} else if (property.type === 'TSInterfaceDeclaration') {
|
|
455
|
-
return flattenProperties(
|
|
444
|
+
return flattenProperties(
|
|
445
|
+
parser.getProperties(property.id.name, types),
|
|
446
|
+
types,
|
|
447
|
+
parser,
|
|
448
|
+
);
|
|
456
449
|
} else if (property.type === 'TSIntersectionType') {
|
|
457
|
-
return flattenProperties(property.types, types);
|
|
450
|
+
return flattenProperties(property.types, types, parser);
|
|
458
451
|
} else {
|
|
459
452
|
throw new Error(
|
|
460
453
|
`${property.type} is not a supported object literal type.`,
|
|
@@ -477,7 +470,6 @@ function flattenProperties(typeDefinition, types) {
|
|
|
477
470
|
.filter(Boolean);
|
|
478
471
|
}
|
|
479
472
|
module.exports = {
|
|
480
|
-
getProperties,
|
|
481
473
|
getSchemaInfo,
|
|
482
474
|
getTypeAnnotation,
|
|
483
475
|
flattenProperties,
|