@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
|
@@ -280,6 +280,44 @@ function throwIfMoreThanOneCodegenNativecommands(commandsTypeNames) {
|
|
|
280
280
|
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
+
function throwIfConfigNotfound(foundConfigs) {
|
|
284
|
+
if (foundConfigs.length === 0) {
|
|
285
|
+
throw new Error('Could not find component config for native component');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function throwIfMoreThanOneConfig(foundConfigs) {
|
|
289
|
+
if (foundConfigs.length > 1) {
|
|
290
|
+
throw new Error('Only one component is supported per file');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function throwIfEventHasNoName(typeAnnotation, parser) {
|
|
294
|
+
const name =
|
|
295
|
+
parser.language() === 'Flow' ? typeAnnotation.id : typeAnnotation.typeName;
|
|
296
|
+
if (!name) {
|
|
297
|
+
throw new Error("typeAnnotation of event doesn't have a name");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function throwIfBubblingTypeIsNull(bubblingType, eventName) {
|
|
301
|
+
if (!bubblingType) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
`Unable to determine event bubbling type for "${eventName}"`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
return bubblingType;
|
|
307
|
+
}
|
|
308
|
+
function throwIfArgumentPropsAreNull(argumentProps, eventName) {
|
|
309
|
+
if (!argumentProps) {
|
|
310
|
+
throw new Error(`Unable to determine event arguments for "${eventName}"`);
|
|
311
|
+
}
|
|
312
|
+
return argumentProps;
|
|
313
|
+
}
|
|
314
|
+
function throwIfTypeAliasIsNotInterface(typeAlias, parser) {
|
|
315
|
+
if (typeAlias.type !== parser.interfaceDeclaration) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
283
321
|
module.exports = {
|
|
284
322
|
throwIfModuleInterfaceIsMisnamed,
|
|
285
323
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -298,4 +336,10 @@ module.exports = {
|
|
|
298
336
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
299
337
|
throwIfPartialWithMoreParameter,
|
|
300
338
|
throwIfMoreThanOneCodegenNativecommands,
|
|
339
|
+
throwIfConfigNotfound,
|
|
340
|
+
throwIfMoreThanOneConfig,
|
|
341
|
+
throwIfEventHasNoName,
|
|
342
|
+
throwIfBubblingTypeIsNull,
|
|
343
|
+
throwIfArgumentPropsAreNull,
|
|
344
|
+
throwIfTypeAliasIsNotInterface,
|
|
301
345
|
};
|
|
@@ -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
|
};
|
|
@@ -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,12 @@
|
|
|
12
12
|
|
|
13
13
|
const _require = require('../utils.js'),
|
|
14
14
|
getValueFromTypes = _require.getValueFromTypes;
|
|
15
|
-
function getProperties(typeName, types) {
|
|
16
|
-
const typeAlias = types[typeName];
|
|
17
|
-
try {
|
|
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
|
-
}
|
|
25
15
|
function getTypeAnnotationForArray(
|
|
26
16
|
name,
|
|
27
17
|
typeAnnotation,
|
|
28
18
|
defaultValue,
|
|
29
19
|
types,
|
|
20
|
+
parser,
|
|
30
21
|
buildSchema,
|
|
31
22
|
) {
|
|
32
23
|
const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
|
|
@@ -52,8 +43,9 @@ function getTypeAnnotationForArray(
|
|
|
52
43
|
properties: flattenProperties(
|
|
53
44
|
objectType.typeParameters.params[0].properties,
|
|
54
45
|
types,
|
|
46
|
+
parser,
|
|
55
47
|
)
|
|
56
|
-
.map(prop => buildSchema(prop, types))
|
|
48
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
57
49
|
.filter(Boolean),
|
|
58
50
|
};
|
|
59
51
|
}
|
|
@@ -71,8 +63,9 @@ function getTypeAnnotationForArray(
|
|
|
71
63
|
properties: flattenProperties(
|
|
72
64
|
nestedObjectType.typeParameters.params[0].properties,
|
|
73
65
|
types,
|
|
66
|
+
parser,
|
|
74
67
|
)
|
|
75
|
-
.map(prop => buildSchema(prop, types))
|
|
68
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
76
69
|
.filter(Boolean),
|
|
77
70
|
},
|
|
78
71
|
};
|
|
@@ -169,15 +162,16 @@ function getTypeAnnotationForArray(
|
|
|
169
162
|
throw new Error(`Unknown property type for "${name}": ${type}`);
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
|
-
function flattenProperties(typeDefinition, types) {
|
|
165
|
+
function flattenProperties(typeDefinition, types, parser) {
|
|
173
166
|
return typeDefinition
|
|
174
167
|
.map(property => {
|
|
175
168
|
if (property.type === 'ObjectTypeProperty') {
|
|
176
169
|
return property;
|
|
177
170
|
} else if (property.type === 'ObjectTypeSpreadProperty') {
|
|
178
171
|
return flattenProperties(
|
|
179
|
-
getProperties(property.argument.id.name, types),
|
|
172
|
+
parser.getProperties(property.argument.id.name, types),
|
|
180
173
|
types,
|
|
174
|
+
parser,
|
|
181
175
|
);
|
|
182
176
|
}
|
|
183
177
|
})
|
|
@@ -208,6 +202,7 @@ function getTypeAnnotation(
|
|
|
208
202
|
defaultValue,
|
|
209
203
|
withNullDefault,
|
|
210
204
|
types,
|
|
205
|
+
parser,
|
|
211
206
|
buildSchema,
|
|
212
207
|
) {
|
|
213
208
|
const typeAnnotation = getValueFromTypes(annotation, types);
|
|
@@ -222,6 +217,7 @@ function getTypeAnnotation(
|
|
|
222
217
|
typeAnnotation.typeParameters.params[0],
|
|
223
218
|
defaultValue,
|
|
224
219
|
types,
|
|
220
|
+
parser,
|
|
225
221
|
buildSchema,
|
|
226
222
|
),
|
|
227
223
|
};
|
|
@@ -235,8 +231,9 @@ function getTypeAnnotation(
|
|
|
235
231
|
properties: flattenProperties(
|
|
236
232
|
typeAnnotation.typeParameters.params[0].properties,
|
|
237
233
|
types,
|
|
234
|
+
parser,
|
|
238
235
|
)
|
|
239
|
-
.map(prop => buildSchema(prop, types))
|
|
236
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
240
237
|
.filter(Boolean),
|
|
241
238
|
};
|
|
242
239
|
}
|
|
@@ -449,11 +446,7 @@ function getSchemaInfo(property, types) {
|
|
|
449
446
|
withNullDefault,
|
|
450
447
|
};
|
|
451
448
|
}
|
|
452
|
-
|
|
453
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
454
|
-
|
|
455
449
|
module.exports = {
|
|
456
|
-
getProperties,
|
|
457
450
|
getSchemaInfo,
|
|
458
451
|
getTypeAnnotation,
|
|
459
452
|
flattenProperties,
|
|
@@ -10,31 +10,17 @@
|
|
|
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
|
-
import type {TypeDeclarationMap} from '../../utils';
|
|
17
|
-
|
|
18
|
-
function getProperties(
|
|
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
|
+
import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
|
|
15
|
+
import type {BuildSchemaFN, Parser} from '../../parser';
|
|
31
16
|
|
|
32
17
|
function getTypeAnnotationForArray<+T>(
|
|
33
18
|
name: string,
|
|
34
19
|
typeAnnotation: $FlowFixMe,
|
|
35
20
|
defaultValue: $FlowFixMe | null,
|
|
36
21
|
types: TypeDeclarationMap,
|
|
37
|
-
|
|
22
|
+
parser: Parser,
|
|
23
|
+
buildSchema: BuildSchemaFN<T>,
|
|
38
24
|
): $FlowFixMe {
|
|
39
25
|
const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types);
|
|
40
26
|
if (extractedTypeAnnotation.type === 'NullableTypeAnnotation') {
|
|
@@ -62,8 +48,9 @@ function getTypeAnnotationForArray<+T>(
|
|
|
62
48
|
properties: flattenProperties(
|
|
63
49
|
objectType.typeParameters.params[0].properties,
|
|
64
50
|
types,
|
|
51
|
+
parser,
|
|
65
52
|
)
|
|
66
|
-
.map(prop => buildSchema(prop, types))
|
|
53
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
67
54
|
.filter(Boolean),
|
|
68
55
|
};
|
|
69
56
|
}
|
|
@@ -83,8 +70,9 @@ function getTypeAnnotationForArray<+T>(
|
|
|
83
70
|
properties: flattenProperties(
|
|
84
71
|
nestedObjectType.typeParameters.params[0].properties,
|
|
85
72
|
types,
|
|
73
|
+
parser,
|
|
86
74
|
)
|
|
87
|
-
.map(prop => buildSchema(prop, types))
|
|
75
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
88
76
|
.filter(Boolean),
|
|
89
77
|
},
|
|
90
78
|
};
|
|
@@ -189,6 +177,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
189
177
|
function flattenProperties(
|
|
190
178
|
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
191
179
|
types: TypeDeclarationMap,
|
|
180
|
+
parser: Parser,
|
|
192
181
|
): $ReadOnlyArray<PropAST> {
|
|
193
182
|
return typeDefinition
|
|
194
183
|
.map(property => {
|
|
@@ -196,8 +185,9 @@ function flattenProperties(
|
|
|
196
185
|
return property;
|
|
197
186
|
} else if (property.type === 'ObjectTypeSpreadProperty') {
|
|
198
187
|
return flattenProperties(
|
|
199
|
-
getProperties(property.argument.id.name, types),
|
|
188
|
+
parser.getProperties(property.argument.id.name, types),
|
|
200
189
|
types,
|
|
190
|
+
parser,
|
|
201
191
|
);
|
|
202
192
|
}
|
|
203
193
|
})
|
|
@@ -233,7 +223,8 @@ function getTypeAnnotation<+T>(
|
|
|
233
223
|
defaultValue: $FlowFixMe | null,
|
|
234
224
|
withNullDefault: boolean,
|
|
235
225
|
types: TypeDeclarationMap,
|
|
236
|
-
|
|
226
|
+
parser: Parser,
|
|
227
|
+
buildSchema: BuildSchemaFN<T>,
|
|
237
228
|
): $FlowFixMe {
|
|
238
229
|
const typeAnnotation = getValueFromTypes(annotation, types);
|
|
239
230
|
|
|
@@ -248,6 +239,7 @@ function getTypeAnnotation<+T>(
|
|
|
248
239
|
typeAnnotation.typeParameters.params[0],
|
|
249
240
|
defaultValue,
|
|
250
241
|
types,
|
|
242
|
+
parser,
|
|
251
243
|
buildSchema,
|
|
252
244
|
),
|
|
253
245
|
};
|
|
@@ -262,8 +254,9 @@ function getTypeAnnotation<+T>(
|
|
|
262
254
|
properties: flattenProperties(
|
|
263
255
|
typeAnnotation.typeParameters.params[0].properties,
|
|
264
256
|
types,
|
|
257
|
+
parser,
|
|
265
258
|
)
|
|
266
|
-
.map(prop => buildSchema(prop, types))
|
|
259
|
+
.map(prop => buildSchema(prop, types, parser))
|
|
267
260
|
.filter(Boolean),
|
|
268
261
|
};
|
|
269
262
|
}
|
|
@@ -499,11 +492,7 @@ function getSchemaInfo(
|
|
|
499
492
|
};
|
|
500
493
|
}
|
|
501
494
|
|
|
502
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
503
|
-
type PropAST = Object;
|
|
504
|
-
|
|
505
495
|
module.exports = {
|
|
506
|
-
getProperties,
|
|
507
496
|
getSchemaInfo,
|
|
508
497
|
getTypeAnnotation,
|
|
509
498
|
flattenProperties,
|