@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
|
@@ -298,6 +298,59 @@ function throwIfMoreThanOneCodegenNativecommands(
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
function throwIfConfigNotfound(foundConfigs: Array<{[string]: string}>) {
|
|
302
|
+
if (foundConfigs.length === 0) {
|
|
303
|
+
throw new Error('Could not find component config for native component');
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function throwIfMoreThanOneConfig(foundConfigs: Array<{[string]: string}>) {
|
|
308
|
+
if (foundConfigs.length > 1) {
|
|
309
|
+
throw new Error('Only one component is supported per file');
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function throwIfEventHasNoName(typeAnnotation: $FlowFixMe, parser: Parser) {
|
|
314
|
+
const name =
|
|
315
|
+
parser.language() === 'Flow' ? typeAnnotation.id : typeAnnotation.typeName;
|
|
316
|
+
|
|
317
|
+
if (!name) {
|
|
318
|
+
throw new Error("typeAnnotation of event doesn't have a name");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function throwIfBubblingTypeIsNull(
|
|
323
|
+
bubblingType: ?('direct' | 'bubble'),
|
|
324
|
+
eventName: string,
|
|
325
|
+
): 'direct' | 'bubble' {
|
|
326
|
+
if (!bubblingType) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
`Unable to determine event bubbling type for "${eventName}"`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return bubblingType;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function throwIfArgumentPropsAreNull(
|
|
336
|
+
argumentProps: ?$ReadOnlyArray<$FlowFixMe>,
|
|
337
|
+
eventName: string,
|
|
338
|
+
): $ReadOnlyArray<$FlowFixMe> {
|
|
339
|
+
if (!argumentProps) {
|
|
340
|
+
throw new Error(`Unable to determine event arguments for "${eventName}"`);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return argumentProps;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function throwIfTypeAliasIsNotInterface(typeAlias: $FlowFixMe, parser: Parser) {
|
|
347
|
+
if (typeAlias.type !== parser.interfaceDeclaration) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
301
354
|
module.exports = {
|
|
302
355
|
throwIfModuleInterfaceIsMisnamed,
|
|
303
356
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -316,4 +369,10 @@ module.exports = {
|
|
|
316
369
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
317
370
|
throwIfPartialWithMoreParameter,
|
|
318
371
|
throwIfMoreThanOneCodegenNativecommands,
|
|
372
|
+
throwIfConfigNotfound,
|
|
373
|
+
throwIfMoreThanOneConfig,
|
|
374
|
+
throwIfEventHasNoName,
|
|
375
|
+
throwIfBubblingTypeIsNull,
|
|
376
|
+
throwIfArgumentPropsAreNull,
|
|
377
|
+
throwIfTypeAliasIsNotInterface,
|
|
319
378
|
};
|
package/lib/parsers/errors.js
CHANGED
|
@@ -84,9 +84,7 @@ class UnsupportedTypeAnnotationParserError extends ParserError {
|
|
|
84
84
|
class UnsupportedGenericParserError extends ParserError {
|
|
85
85
|
// +genericName: string;
|
|
86
86
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
87
|
-
const genericName = parser.
|
|
88
|
-
genericTypeAnnotation,
|
|
89
|
-
);
|
|
87
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
90
88
|
super(
|
|
91
89
|
nativeModuleName,
|
|
92
90
|
genericTypeAnnotation,
|
|
@@ -99,9 +97,7 @@ class UnsupportedGenericParserError extends ParserError {
|
|
|
99
97
|
|
|
100
98
|
class MissingTypeParameterGenericParserError extends ParserError {
|
|
101
99
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
102
|
-
const genericName = parser.
|
|
103
|
-
genericTypeAnnotation,
|
|
104
|
-
);
|
|
100
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
105
101
|
super(
|
|
106
102
|
nativeModuleName,
|
|
107
103
|
genericTypeAnnotation,
|
|
@@ -111,9 +107,7 @@ class MissingTypeParameterGenericParserError extends ParserError {
|
|
|
111
107
|
}
|
|
112
108
|
class MoreThanOneTypeParameterGenericParserError extends ParserError {
|
|
113
109
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
114
|
-
const genericName = parser.
|
|
115
|
-
genericTypeAnnotation,
|
|
116
|
-
);
|
|
110
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
117
111
|
super(
|
|
118
112
|
nativeModuleName,
|
|
119
113
|
genericTypeAnnotation,
|
|
@@ -117,9 +117,7 @@ class UnsupportedGenericParserError extends ParserError {
|
|
|
117
117
|
genericTypeAnnotation: $FlowFixMe,
|
|
118
118
|
parser: Parser,
|
|
119
119
|
) {
|
|
120
|
-
const genericName = parser.
|
|
121
|
-
genericTypeAnnotation,
|
|
122
|
-
);
|
|
120
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
123
121
|
super(
|
|
124
122
|
nativeModuleName,
|
|
125
123
|
genericTypeAnnotation,
|
|
@@ -136,9 +134,7 @@ class MissingTypeParameterGenericParserError extends ParserError {
|
|
|
136
134
|
genericTypeAnnotation: $FlowFixMe,
|
|
137
135
|
parser: Parser,
|
|
138
136
|
) {
|
|
139
|
-
const genericName = parser.
|
|
140
|
-
genericTypeAnnotation,
|
|
141
|
-
);
|
|
137
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
142
138
|
|
|
143
139
|
super(
|
|
144
140
|
nativeModuleName,
|
|
@@ -154,9 +150,7 @@ class MoreThanOneTypeParameterGenericParserError extends ParserError {
|
|
|
154
150
|
genericTypeAnnotation: $FlowFixMe,
|
|
155
151
|
parser: Parser,
|
|
156
152
|
) {
|
|
157
|
-
const genericName = parser.
|
|
158
|
-
genericTypeAnnotation,
|
|
159
|
-
);
|
|
153
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
160
154
|
|
|
161
155
|
super(
|
|
162
156
|
nativeModuleName,
|
|
@@ -84,6 +84,57 @@ const EVENT_DEFINITION = `
|
|
|
84
84
|
object_readonly_optional_both?: ?$ReadOnly<{
|
|
85
85
|
int32_optional_both?: ?Int32,
|
|
86
86
|
}>,
|
|
87
|
+
|
|
88
|
+
boolean_array_required: $ReadOnlyArray<boolean>,
|
|
89
|
+
boolean_array_optional_key?: boolean[],
|
|
90
|
+
boolean_array_optional_value: ?$ReadOnlyArray<boolean>,
|
|
91
|
+
boolean_array_optional_both?: ?boolean[],
|
|
92
|
+
|
|
93
|
+
string_array_required: $ReadOnlyArray<string>,
|
|
94
|
+
string_array_optional_key?: string[],
|
|
95
|
+
string_array_optional_value: ?$ReadOnlyArray<string>,
|
|
96
|
+
string_array_optional_both?: ?string[],
|
|
97
|
+
|
|
98
|
+
double_array_required: $ReadOnlyArray<Double>,
|
|
99
|
+
double_array_optional_key?: Double[],
|
|
100
|
+
double_array_optional_value: ?$ReadOnlyArray<Double>,
|
|
101
|
+
double_array_optional_both?: ?Double[],
|
|
102
|
+
|
|
103
|
+
float_array_required: $ReadOnlyArray<Float>,
|
|
104
|
+
float_array_optional_key?: Float[],
|
|
105
|
+
float_array_optional_value: ?$ReadOnlyArray<Float>,
|
|
106
|
+
float_array_optional_both?: ?Float[],
|
|
107
|
+
|
|
108
|
+
int32_array_required: $ReadOnlyArray<Int32>,
|
|
109
|
+
int32_array_optional_key?: Int32[],
|
|
110
|
+
int32_array_optional_value: ?$ReadOnlyArray<Int32>,
|
|
111
|
+
int32_array_optional_both?: ?Int32[],
|
|
112
|
+
|
|
113
|
+
enum_array_required: $ReadOnlyArray<('small' | 'large')>,
|
|
114
|
+
enum_array_optional_key?: ('small' | 'large')[],
|
|
115
|
+
enum_array_optional_value: ?$ReadOnlyArray<('small' | 'large')>,
|
|
116
|
+
enum_array_optional_both?: ?('small' | 'large')[],
|
|
117
|
+
|
|
118
|
+
object_array_required: $ReadOnlyArray<{
|
|
119
|
+
boolean_required: boolean,
|
|
120
|
+
}>,
|
|
121
|
+
|
|
122
|
+
object_array_optional_key?: {
|
|
123
|
+
string_optional_key?: string,
|
|
124
|
+
}[],
|
|
125
|
+
|
|
126
|
+
object_array_optional_value: ?$ReadOnlyArray<{
|
|
127
|
+
float_optional_value: ?Float,
|
|
128
|
+
}>,
|
|
129
|
+
|
|
130
|
+
object_array_optional_both?: ?{
|
|
131
|
+
int32_optional_both?: ?Int32,
|
|
132
|
+
}[],
|
|
133
|
+
|
|
134
|
+
int32_array_array_required: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
|
|
135
|
+
int32_array_array_optional_key?: Int32[][],
|
|
136
|
+
int32_array_array_optional_value: ?$ReadOnlyArray<$ReadOnlyArray<Int32>>,
|
|
137
|
+
int32_array_array_optional_both?: ?Int32[][],
|
|
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,
|
|
86
86
|
}>,
|
|
87
|
+
|
|
88
|
+
boolean_array_required: $ReadOnlyArray<boolean>,
|
|
89
|
+
boolean_array_optional_key?: boolean[],
|
|
90
|
+
boolean_array_optional_value: ?$ReadOnlyArray<boolean>,
|
|
91
|
+
boolean_array_optional_both?: ?boolean[],
|
|
92
|
+
|
|
93
|
+
string_array_required: $ReadOnlyArray<string>,
|
|
94
|
+
string_array_optional_key?: string[],
|
|
95
|
+
string_array_optional_value: ?$ReadOnlyArray<string>,
|
|
96
|
+
string_array_optional_both?: ?string[],
|
|
97
|
+
|
|
98
|
+
double_array_required: $ReadOnlyArray<Double>,
|
|
99
|
+
double_array_optional_key?: Double[],
|
|
100
|
+
double_array_optional_value: ?$ReadOnlyArray<Double>,
|
|
101
|
+
double_array_optional_both?: ?Double[],
|
|
102
|
+
|
|
103
|
+
float_array_required: $ReadOnlyArray<Float>,
|
|
104
|
+
float_array_optional_key?: Float[],
|
|
105
|
+
float_array_optional_value: ?$ReadOnlyArray<Float>,
|
|
106
|
+
float_array_optional_both?: ?Float[],
|
|
107
|
+
|
|
108
|
+
int32_array_required: $ReadOnlyArray<Int32>,
|
|
109
|
+
int32_array_optional_key?: Int32[],
|
|
110
|
+
int32_array_optional_value: ?$ReadOnlyArray<Int32>,
|
|
111
|
+
int32_array_optional_both?: ?Int32[],
|
|
112
|
+
|
|
113
|
+
enum_array_required: $ReadOnlyArray<('small' | 'large')>,
|
|
114
|
+
enum_array_optional_key?: ('small' | 'large')[],
|
|
115
|
+
enum_array_optional_value: ?$ReadOnlyArray<('small' | 'large')>,
|
|
116
|
+
enum_array_optional_both?: ?('small' | 'large')[],
|
|
117
|
+
|
|
118
|
+
object_array_required: $ReadOnlyArray<{
|
|
119
|
+
boolean_required: boolean,
|
|
120
|
+
}>,
|
|
121
|
+
|
|
122
|
+
object_array_optional_key?: {
|
|
123
|
+
string_optional_key?: string,
|
|
124
|
+
}[],
|
|
125
|
+
|
|
126
|
+
object_array_optional_value: ?$ReadOnlyArray<{
|
|
127
|
+
float_optional_value: ?Float,
|
|
128
|
+
}>,
|
|
129
|
+
|
|
130
|
+
object_array_optional_both?: ?{
|
|
131
|
+
int32_optional_both?: ?Int32,
|
|
132
|
+
}[],
|
|
133
|
+
|
|
134
|
+
int32_array_array_required: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
|
|
135
|
+
int32_array_array_optional_key?: Int32[][],
|
|
136
|
+
int32_array_array_optional_value: ?$ReadOnlyArray<$ReadOnlyArray<Int32>>,
|
|
137
|
+
int32_array_array_optional_both?: ?Int32[][],
|
|
87
138
|
`;
|
|
88
139
|
|
|
89
140
|
const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
|
|
@@ -12,21 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
const _require = require('../utils.js'),
|
|
14
14
|
getValueFromTypes = _require.getValueFromTypes;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return typeAlias.right.typeParameters.params[0].properties;
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
15
|
+
const _require2 = require('../../parsers-commons'),
|
|
16
|
+
verifyPropNotAlreadyDefined = _require2.verifyPropNotAlreadyDefined;
|
|
17
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
25
18
|
function getTypeAnnotationForArray(
|
|
26
19
|
name,
|
|
27
20
|
typeAnnotation,
|
|
28
21
|
defaultValue,
|
|
29
22
|
types,
|
|
23
|
+
parser,
|
|
30
24
|
buildSchema,
|
|
31
25
|
) {
|
|
32
26
|
const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
|
|
@@ -37,7 +31,7 @@ function getTypeAnnotationForArray(
|
|
|
37
31
|
}
|
|
38
32
|
if (
|
|
39
33
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
40
|
-
extractedTypeAnnotation
|
|
34
|
+
parser.getTypeAnnotationName(extractedTypeAnnotation) === 'WithDefault'
|
|
41
35
|
) {
|
|
42
36
|
throw new Error(
|
|
43
37
|
'Nested defaults such as "$ReadOnlyArray<WithDefault<boolean, false>>" are not supported, please declare defaults at the top level of value definitions as in "WithDefault<$ReadOnlyArray<boolean>, false>"',
|
|
@@ -52,8 +46,9 @@ function getTypeAnnotationForArray(
|
|
|
52
46
|
properties: flattenProperties(
|
|
53
47
|
objectType.typeParameters.params[0].properties,
|
|
54
48
|
types,
|
|
49
|
+
parser,
|
|
55
50
|
)
|
|
56
|
-
.map(prop => buildSchema(prop, types))
|
|
51
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
57
52
|
.filter(Boolean),
|
|
58
53
|
};
|
|
59
54
|
}
|
|
@@ -71,8 +66,9 @@ function getTypeAnnotationForArray(
|
|
|
71
66
|
properties: flattenProperties(
|
|
72
67
|
nestedObjectType.typeParameters.params[0].properties,
|
|
73
68
|
types,
|
|
69
|
+
parser,
|
|
74
70
|
)
|
|
75
|
-
.map(prop => buildSchema(prop, types))
|
|
71
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
76
72
|
.filter(Boolean),
|
|
77
73
|
},
|
|
78
74
|
};
|
|
@@ -80,7 +76,7 @@ function getTypeAnnotationForArray(
|
|
|
80
76
|
}
|
|
81
77
|
const type =
|
|
82
78
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation'
|
|
83
|
-
? extractedTypeAnnotation
|
|
79
|
+
? parser.getTypeAnnotationName(extractedTypeAnnotation)
|
|
84
80
|
: extractedTypeAnnotation.type;
|
|
85
81
|
switch (type) {
|
|
86
82
|
case 'ImageSource':
|
|
@@ -165,19 +161,19 @@ function getTypeAnnotationForArray(
|
|
|
165
161
|
);
|
|
166
162
|
}
|
|
167
163
|
default:
|
|
168
|
-
type;
|
|
169
164
|
throw new Error(`Unknown property type for "${name}": ${type}`);
|
|
170
165
|
}
|
|
171
166
|
}
|
|
172
|
-
function flattenProperties(typeDefinition, types) {
|
|
167
|
+
function flattenProperties(typeDefinition, types, parser) {
|
|
173
168
|
return typeDefinition
|
|
174
169
|
.map(property => {
|
|
175
170
|
if (property.type === 'ObjectTypeProperty') {
|
|
176
171
|
return property;
|
|
177
172
|
} else if (property.type === 'ObjectTypeSpreadProperty') {
|
|
178
173
|
return flattenProperties(
|
|
179
|
-
getProperties(property.argument.id.name, types),
|
|
174
|
+
parser.getProperties(property.argument.id.name, types),
|
|
180
175
|
types,
|
|
176
|
+
parser,
|
|
181
177
|
);
|
|
182
178
|
}
|
|
183
179
|
})
|
|
@@ -195,25 +191,21 @@ function flattenProperties(typeDefinition, types) {
|
|
|
195
191
|
}, [])
|
|
196
192
|
.filter(Boolean);
|
|
197
193
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const foundProp = props.some(prop => prop.key.name === propName);
|
|
201
|
-
if (foundProp) {
|
|
202
|
-
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
194
|
+
|
|
195
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
205
196
|
function getTypeAnnotation(
|
|
206
197
|
name,
|
|
207
198
|
annotation,
|
|
208
199
|
defaultValue,
|
|
209
200
|
withNullDefault,
|
|
210
201
|
types,
|
|
202
|
+
parser,
|
|
211
203
|
buildSchema,
|
|
212
204
|
) {
|
|
213
205
|
const typeAnnotation = getValueFromTypes(annotation, types);
|
|
214
206
|
if (
|
|
215
207
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
216
|
-
typeAnnotation
|
|
208
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray'
|
|
217
209
|
) {
|
|
218
210
|
return {
|
|
219
211
|
type: 'ArrayTypeAnnotation',
|
|
@@ -222,27 +214,29 @@ function getTypeAnnotation(
|
|
|
222
214
|
typeAnnotation.typeParameters.params[0],
|
|
223
215
|
defaultValue,
|
|
224
216
|
types,
|
|
217
|
+
parser,
|
|
225
218
|
buildSchema,
|
|
226
219
|
),
|
|
227
220
|
};
|
|
228
221
|
}
|
|
229
222
|
if (
|
|
230
223
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
231
|
-
typeAnnotation
|
|
224
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly'
|
|
232
225
|
) {
|
|
233
226
|
return {
|
|
234
227
|
type: 'ObjectTypeAnnotation',
|
|
235
228
|
properties: flattenProperties(
|
|
236
229
|
typeAnnotation.typeParameters.params[0].properties,
|
|
237
230
|
types,
|
|
231
|
+
parser,
|
|
238
232
|
)
|
|
239
|
-
.map(prop => buildSchema(prop, types))
|
|
233
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
240
234
|
.filter(Boolean),
|
|
241
235
|
};
|
|
242
236
|
}
|
|
243
237
|
const type =
|
|
244
238
|
typeAnnotation.type === 'GenericTypeAnnotation'
|
|
245
|
-
? typeAnnotation
|
|
239
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
246
240
|
: typeAnnotation.type;
|
|
247
241
|
switch (type) {
|
|
248
242
|
case 'ImageSource':
|
|
@@ -369,7 +363,6 @@ function getTypeAnnotation(
|
|
|
369
363
|
type: 'MixedTypeAnnotation',
|
|
370
364
|
};
|
|
371
365
|
default:
|
|
372
|
-
type;
|
|
373
366
|
throw new Error(
|
|
374
367
|
`Unknown property type for "${name}": "${type}" in the State`,
|
|
375
368
|
);
|
|
@@ -449,11 +442,7 @@ function getSchemaInfo(property, types) {
|
|
|
449
442
|
withNullDefault,
|
|
450
443
|
};
|
|
451
444
|
}
|
|
452
|
-
|
|
453
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
454
|
-
|
|
455
445
|
module.exports = {
|
|
456
|
-
getProperties,
|
|
457
446
|
getSchemaInfo,
|
|
458
447
|
getTypeAnnotation,
|
|
459
448
|
flattenProperties,
|
|
@@ -10,31 +10,19 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {ASTNode} from '../utils';
|
|
14
|
-
import type {NamedShape} from '../../../CodegenSchema.js';
|
|
15
13
|
const {getValueFromTypes} = require('../utils.js');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
typeName: string,
|
|
20
|
-
types: TypeDeclarationMap,
|
|
21
|
-
): $FlowFixMe {
|
|
22
|
-
const typeAlias = types[typeName];
|
|
23
|
-
try {
|
|
24
|
-
return typeAlias.right.typeParameters.params[0].properties;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
14
|
+
const {verifyPropNotAlreadyDefined} = require('../../parsers-commons');
|
|
15
|
+
import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
|
|
16
|
+
import type {BuildSchemaFN, Parser} from '../../parser';
|
|
31
17
|
|
|
18
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
32
19
|
function getTypeAnnotationForArray<+T>(
|
|
33
20
|
name: string,
|
|
34
21
|
typeAnnotation: $FlowFixMe,
|
|
35
22
|
defaultValue: $FlowFixMe | null,
|
|
36
23
|
types: TypeDeclarationMap,
|
|
37
|
-
|
|
24
|
+
parser: Parser,
|
|
25
|
+
buildSchema: BuildSchemaFN<T>,
|
|
38
26
|
): $FlowFixMe {
|
|
39
27
|
const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
|
|
40
28
|
if (extractedTypeAnnotation.type === 'NullableTypeAnnotation') {
|
|
@@ -45,7 +33,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
45
33
|
|
|
46
34
|
if (
|
|
47
35
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
48
|
-
extractedTypeAnnotation
|
|
36
|
+
parser.getTypeAnnotationName(extractedTypeAnnotation) === 'WithDefault'
|
|
49
37
|
) {
|
|
50
38
|
throw new Error(
|
|
51
39
|
'Nested defaults such as "$ReadOnlyArray<WithDefault<boolean, false>>" are not supported, please declare defaults at the top level of value definitions as in "WithDefault<$ReadOnlyArray<boolean>, false>"',
|
|
@@ -62,8 +50,9 @@ function getTypeAnnotationForArray<+T>(
|
|
|
62
50
|
properties: flattenProperties(
|
|
63
51
|
objectType.typeParameters.params[0].properties,
|
|
64
52
|
types,
|
|
53
|
+
parser,
|
|
65
54
|
)
|
|
66
|
-
.map(prop => buildSchema(prop, types))
|
|
55
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
67
56
|
.filter(Boolean),
|
|
68
57
|
};
|
|
69
58
|
}
|
|
@@ -83,8 +72,9 @@ function getTypeAnnotationForArray<+T>(
|
|
|
83
72
|
properties: flattenProperties(
|
|
84
73
|
nestedObjectType.typeParameters.params[0].properties,
|
|
85
74
|
types,
|
|
75
|
+
parser,
|
|
86
76
|
)
|
|
87
|
-
.map(prop => buildSchema(prop, types))
|
|
77
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
88
78
|
.filter(Boolean),
|
|
89
79
|
},
|
|
90
80
|
};
|
|
@@ -93,7 +83,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
93
83
|
|
|
94
84
|
const type =
|
|
95
85
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation'
|
|
96
|
-
? extractedTypeAnnotation
|
|
86
|
+
? parser.getTypeAnnotationName(extractedTypeAnnotation)
|
|
97
87
|
: extractedTypeAnnotation.type;
|
|
98
88
|
|
|
99
89
|
switch (type) {
|
|
@@ -181,7 +171,6 @@ function getTypeAnnotationForArray<+T>(
|
|
|
181
171
|
);
|
|
182
172
|
}
|
|
183
173
|
default:
|
|
184
|
-
(type: empty);
|
|
185
174
|
throw new Error(`Unknown property type for "${name}": ${type}`);
|
|
186
175
|
}
|
|
187
176
|
}
|
|
@@ -189,6 +178,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
189
178
|
function flattenProperties(
|
|
190
179
|
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
191
180
|
types: TypeDeclarationMap,
|
|
181
|
+
parser: Parser,
|
|
192
182
|
): $ReadOnlyArray<PropAST> {
|
|
193
183
|
return typeDefinition
|
|
194
184
|
.map(property => {
|
|
@@ -196,8 +186,9 @@ function flattenProperties(
|
|
|
196
186
|
return property;
|
|
197
187
|
} else if (property.type === 'ObjectTypeSpreadProperty') {
|
|
198
188
|
return flattenProperties(
|
|
199
|
-
getProperties(property.argument.id.name, types),
|
|
189
|
+
parser.getProperties(property.argument.id.name, types),
|
|
200
190
|
types,
|
|
191
|
+
parser,
|
|
201
192
|
);
|
|
202
193
|
}
|
|
203
194
|
})
|
|
@@ -216,30 +207,21 @@ function flattenProperties(
|
|
|
216
207
|
.filter(Boolean);
|
|
217
208
|
}
|
|
218
209
|
|
|
219
|
-
|
|
220
|
-
props: $ReadOnlyArray<PropAST>,
|
|
221
|
-
needleProp: PropAST,
|
|
222
|
-
) {
|
|
223
|
-
const propName = needleProp.key.name;
|
|
224
|
-
const foundProp = props.some(prop => prop.key.name === propName);
|
|
225
|
-
if (foundProp) {
|
|
226
|
-
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
210
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
230
211
|
function getTypeAnnotation<+T>(
|
|
231
212
|
name: string,
|
|
232
213
|
annotation: $FlowFixMe | ASTNode,
|
|
233
214
|
defaultValue: $FlowFixMe | null,
|
|
234
215
|
withNullDefault: boolean,
|
|
235
216
|
types: TypeDeclarationMap,
|
|
236
|
-
|
|
217
|
+
parser: Parser,
|
|
218
|
+
buildSchema: BuildSchemaFN<T>,
|
|
237
219
|
): $FlowFixMe {
|
|
238
220
|
const typeAnnotation = getValueFromTypes(annotation, types);
|
|
239
221
|
|
|
240
222
|
if (
|
|
241
223
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
242
|
-
typeAnnotation
|
|
224
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray'
|
|
243
225
|
) {
|
|
244
226
|
return {
|
|
245
227
|
type: 'ArrayTypeAnnotation',
|
|
@@ -248,6 +230,7 @@ function getTypeAnnotation<+T>(
|
|
|
248
230
|
typeAnnotation.typeParameters.params[0],
|
|
249
231
|
defaultValue,
|
|
250
232
|
types,
|
|
233
|
+
parser,
|
|
251
234
|
buildSchema,
|
|
252
235
|
),
|
|
253
236
|
};
|
|
@@ -255,22 +238,23 @@ function getTypeAnnotation<+T>(
|
|
|
255
238
|
|
|
256
239
|
if (
|
|
257
240
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
258
|
-
typeAnnotation
|
|
241
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly'
|
|
259
242
|
) {
|
|
260
243
|
return {
|
|
261
244
|
type: 'ObjectTypeAnnotation',
|
|
262
245
|
properties: flattenProperties(
|
|
263
246
|
typeAnnotation.typeParameters.params[0].properties,
|
|
264
247
|
types,
|
|
248
|
+
parser,
|
|
265
249
|
)
|
|
266
|
-
.map(prop => buildSchema(prop, types))
|
|
250
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
267
251
|
.filter(Boolean),
|
|
268
252
|
};
|
|
269
253
|
}
|
|
270
254
|
|
|
271
255
|
const type =
|
|
272
256
|
typeAnnotation.type === 'GenericTypeAnnotation'
|
|
273
|
-
? typeAnnotation
|
|
257
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
274
258
|
: typeAnnotation.type;
|
|
275
259
|
|
|
276
260
|
switch (type) {
|
|
@@ -396,7 +380,6 @@ function getTypeAnnotation<+T>(
|
|
|
396
380
|
type: 'MixedTypeAnnotation',
|
|
397
381
|
};
|
|
398
382
|
default:
|
|
399
|
-
(type: empty);
|
|
400
383
|
throw new Error(
|
|
401
384
|
`Unknown property type for "${name}": "${type}" in the State`,
|
|
402
385
|
);
|
|
@@ -499,11 +482,7 @@ function getSchemaInfo(
|
|
|
499
482
|
};
|
|
500
483
|
}
|
|
501
484
|
|
|
502
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
503
|
-
type PropAST = Object;
|
|
504
|
-
|
|
505
485
|
module.exports = {
|
|
506
|
-
getProperties,
|
|
507
486
|
getSchemaInfo,
|
|
508
487
|
getTypeAnnotation,
|
|
509
488
|
flattenProperties,
|