@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
|
@@ -15,104 +15,175 @@ import type {
|
|
|
15
15
|
NamedShape,
|
|
16
16
|
EventTypeAnnotation,
|
|
17
17
|
} from '../../../CodegenSchema.js';
|
|
18
|
+
import type {Parser} from '../../parser';
|
|
19
|
+
import type {EventArgumentReturnType} from '../../parsers-commons';
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
throwIfEventHasNoName,
|
|
23
|
+
throwIfBubblingTypeIsNull,
|
|
24
|
+
throwIfArgumentPropsAreNull,
|
|
25
|
+
} = require('../../error-utils');
|
|
26
|
+
const {
|
|
27
|
+
getEventArgument,
|
|
28
|
+
buildPropertiesForEvent,
|
|
29
|
+
handleEventHandler,
|
|
30
|
+
emitBuildEventSchema,
|
|
31
|
+
} = require('../../parsers-commons');
|
|
32
|
+
const {
|
|
33
|
+
emitBoolProp,
|
|
34
|
+
emitDoubleProp,
|
|
35
|
+
emitFloatProp,
|
|
36
|
+
emitMixedProp,
|
|
37
|
+
emitStringProp,
|
|
38
|
+
emitInt32Prop,
|
|
39
|
+
emitObjectProp,
|
|
40
|
+
emitUnionProp,
|
|
41
|
+
} = require('../../parsers-primitives');
|
|
18
42
|
|
|
19
43
|
function getPropertyType(
|
|
20
44
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
21
45
|
* LTI update could not be added via codemod */
|
|
22
|
-
name,
|
|
46
|
+
name: string,
|
|
23
47
|
optional: boolean,
|
|
24
48
|
typeAnnotation: $FlowFixMe,
|
|
49
|
+
parser: Parser,
|
|
25
50
|
): NamedShape<EventTypeAnnotation> {
|
|
26
|
-
const type =
|
|
27
|
-
typeAnnotation.type === 'GenericTypeAnnotation'
|
|
28
|
-
? typeAnnotation.id.name
|
|
29
|
-
: typeAnnotation.type;
|
|
51
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
30
52
|
|
|
31
53
|
switch (type) {
|
|
32
54
|
case 'BooleanTypeAnnotation':
|
|
33
|
-
return
|
|
34
|
-
name,
|
|
35
|
-
optional,
|
|
36
|
-
typeAnnotation: {
|
|
37
|
-
type: 'BooleanTypeAnnotation',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
55
|
+
return emitBoolProp(name, optional);
|
|
40
56
|
case 'StringTypeAnnotation':
|
|
41
|
-
return
|
|
42
|
-
name,
|
|
43
|
-
optional,
|
|
44
|
-
typeAnnotation: {
|
|
45
|
-
type: 'StringTypeAnnotation',
|
|
46
|
-
},
|
|
47
|
-
};
|
|
57
|
+
return emitStringProp(name, optional);
|
|
48
58
|
case 'Int32':
|
|
49
|
-
return
|
|
50
|
-
name,
|
|
51
|
-
optional,
|
|
52
|
-
typeAnnotation: {
|
|
53
|
-
type: 'Int32TypeAnnotation',
|
|
54
|
-
},
|
|
55
|
-
};
|
|
59
|
+
return emitInt32Prop(name, optional);
|
|
56
60
|
case 'Double':
|
|
57
|
-
return
|
|
58
|
-
name,
|
|
59
|
-
optional,
|
|
60
|
-
typeAnnotation: {
|
|
61
|
-
type: 'DoubleTypeAnnotation',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
61
|
+
return emitDoubleProp(name, optional);
|
|
64
62
|
case 'Float':
|
|
65
|
-
return
|
|
66
|
-
name,
|
|
67
|
-
optional,
|
|
68
|
-
typeAnnotation: {
|
|
69
|
-
type: 'FloatTypeAnnotation',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
63
|
+
return emitFloatProp(name, optional);
|
|
72
64
|
case '$ReadOnly':
|
|
73
65
|
return getPropertyType(
|
|
74
66
|
name,
|
|
75
67
|
optional,
|
|
76
68
|
typeAnnotation.typeParameters.params[0],
|
|
69
|
+
parser,
|
|
77
70
|
);
|
|
78
71
|
case 'ObjectTypeAnnotation':
|
|
79
|
-
return
|
|
72
|
+
return emitObjectProp(
|
|
80
73
|
name,
|
|
81
74
|
optional,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
75
|
+
parser,
|
|
76
|
+
typeAnnotation,
|
|
77
|
+
extractArrayElementType,
|
|
78
|
+
);
|
|
87
79
|
case 'UnionTypeAnnotation':
|
|
80
|
+
return emitUnionProp(name, optional, parser, typeAnnotation);
|
|
81
|
+
case 'UnsafeMixed':
|
|
82
|
+
return emitMixedProp(name, optional);
|
|
83
|
+
case 'ArrayTypeAnnotation':
|
|
84
|
+
case '$ReadOnlyArray':
|
|
88
85
|
return {
|
|
89
86
|
name,
|
|
90
87
|
optional,
|
|
91
|
-
typeAnnotation:
|
|
92
|
-
type: 'StringEnumTypeAnnotation',
|
|
93
|
-
options: typeAnnotation.types.map(option => option.value),
|
|
94
|
-
},
|
|
88
|
+
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
|
|
95
89
|
};
|
|
96
90
|
default:
|
|
97
|
-
(type: empty);
|
|
98
91
|
throw new Error(`Unable to determine event type for "${name}": ${type}`);
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
|
|
95
|
+
function extractArrayElementType(
|
|
96
|
+
typeAnnotation: $FlowFixMe,
|
|
97
|
+
name: string,
|
|
98
|
+
parser: Parser,
|
|
99
|
+
): EventTypeAnnotation {
|
|
100
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
101
|
+
|
|
102
|
+
switch (type) {
|
|
103
|
+
case 'BooleanTypeAnnotation':
|
|
104
|
+
return {type: 'BooleanTypeAnnotation'};
|
|
105
|
+
case 'StringTypeAnnotation':
|
|
106
|
+
return {type: 'StringTypeAnnotation'};
|
|
107
|
+
case 'Int32':
|
|
108
|
+
return {type: 'Int32TypeAnnotation'};
|
|
109
|
+
case 'Float':
|
|
110
|
+
return {type: 'FloatTypeAnnotation'};
|
|
111
|
+
case 'NumberTypeAnnotation':
|
|
112
|
+
case 'Double':
|
|
113
|
+
return {
|
|
114
|
+
type: 'DoubleTypeAnnotation',
|
|
115
|
+
};
|
|
116
|
+
case 'UnionTypeAnnotation':
|
|
117
|
+
return {
|
|
118
|
+
type: 'StringEnumTypeAnnotation',
|
|
119
|
+
options: typeAnnotation.types.map(option =>
|
|
120
|
+
parser.getLiteralValue(option),
|
|
121
|
+
),
|
|
122
|
+
};
|
|
123
|
+
case 'UnsafeMixed':
|
|
124
|
+
return {type: 'MixedTypeAnnotation'};
|
|
125
|
+
case 'ObjectTypeAnnotation':
|
|
126
|
+
return {
|
|
127
|
+
type: 'ObjectTypeAnnotation',
|
|
128
|
+
properties: parser
|
|
129
|
+
.getObjectProperties(typeAnnotation)
|
|
130
|
+
.map(member =>
|
|
131
|
+
buildPropertiesForEvent(member, parser, getPropertyType),
|
|
132
|
+
),
|
|
133
|
+
};
|
|
134
|
+
case 'ArrayTypeAnnotation':
|
|
135
|
+
return {
|
|
136
|
+
type: 'ArrayTypeAnnotation',
|
|
137
|
+
elementType: extractArrayElementType(
|
|
138
|
+
typeAnnotation.elementType,
|
|
139
|
+
name,
|
|
140
|
+
parser,
|
|
141
|
+
),
|
|
142
|
+
};
|
|
143
|
+
case '$ReadOnlyArray':
|
|
144
|
+
const genericParams = typeAnnotation.typeParameters.params;
|
|
145
|
+
if (genericParams.length !== 1) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Events only supports arrays with 1 Generic type. Found ${
|
|
148
|
+
genericParams.length
|
|
149
|
+
} types:\n${prettify(genericParams)}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
type: 'ArrayTypeAnnotation',
|
|
154
|
+
elementType: extractArrayElementType(genericParams[0], name, parser),
|
|
155
|
+
};
|
|
156
|
+
default:
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Unrecognized ${type} for Array ${name} in events.\n${prettify(
|
|
159
|
+
typeAnnotation,
|
|
160
|
+
)}`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function prettify(jsonObject: $FlowFixMe): string {
|
|
166
|
+
return JSON.stringify(jsonObject, null, 2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function extractTypeFromTypeAnnotation(
|
|
170
|
+
typeAnnotation: $FlowFixMe,
|
|
171
|
+
parser: Parser,
|
|
172
|
+
): string {
|
|
173
|
+
return typeAnnotation.type === 'GenericTypeAnnotation'
|
|
174
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
175
|
+
: typeAnnotation.type;
|
|
176
|
+
}
|
|
177
|
+
|
|
102
178
|
function findEventArgumentsAndType(
|
|
179
|
+
parser: Parser,
|
|
103
180
|
typeAnnotation: $FlowFixMe,
|
|
104
181
|
types: TypeMap,
|
|
105
182
|
bubblingType: void | 'direct' | 'bubble',
|
|
106
183
|
paperName: ?$FlowFixMe,
|
|
107
|
-
): {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
paperTopLevelNameDeprecated: ?$FlowFixMe,
|
|
111
|
-
} {
|
|
112
|
-
if (!typeAnnotation.id) {
|
|
113
|
-
throw new Error("typeAnnotation of event doesn't have a name");
|
|
114
|
-
}
|
|
115
|
-
const name = typeAnnotation.id.name;
|
|
184
|
+
): EventArgumentReturnType {
|
|
185
|
+
throwIfEventHasNoName(typeAnnotation, parser);
|
|
186
|
+
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
116
187
|
if (name === '$ReadOnly') {
|
|
117
188
|
return {
|
|
118
189
|
argumentProps: typeAnnotation.typeParameters.params[0].properties,
|
|
@@ -120,29 +191,16 @@ function findEventArgumentsAndType(
|
|
|
120
191
|
bubblingType,
|
|
121
192
|
};
|
|
122
193
|
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
typeAnnotation
|
|
126
|
-
|
|
127
|
-
: null;
|
|
128
|
-
if (
|
|
129
|
-
typeAnnotation.typeParameters.params[0].type ===
|
|
130
|
-
'NullLiteralTypeAnnotation'
|
|
131
|
-
) {
|
|
132
|
-
return {
|
|
133
|
-
argumentProps: [],
|
|
134
|
-
bubblingType: eventType,
|
|
135
|
-
paperTopLevelNameDeprecated,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return findEventArgumentsAndType(
|
|
139
|
-
typeAnnotation.typeParameters.params[0],
|
|
194
|
+
return handleEventHandler(
|
|
195
|
+
name,
|
|
196
|
+
typeAnnotation,
|
|
197
|
+
parser,
|
|
140
198
|
types,
|
|
141
|
-
|
|
142
|
-
paperTopLevelNameDeprecated,
|
|
199
|
+
findEventArgumentsAndType,
|
|
143
200
|
);
|
|
144
201
|
} else if (types[name]) {
|
|
145
202
|
return findEventArgumentsAndType(
|
|
203
|
+
parser,
|
|
146
204
|
types[name].right,
|
|
147
205
|
types,
|
|
148
206
|
bubblingType,
|
|
@@ -157,32 +215,10 @@ function findEventArgumentsAndType(
|
|
|
157
215
|
}
|
|
158
216
|
}
|
|
159
217
|
|
|
160
|
-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
161
|
-
* LTI update could not be added via codemod */
|
|
162
|
-
function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
|
|
163
|
-
const name = property.key.name;
|
|
164
|
-
const optional =
|
|
165
|
-
property.value.type === 'NullableTypeAnnotation' || property.optional;
|
|
166
|
-
let typeAnnotation =
|
|
167
|
-
property.value.type === 'NullableTypeAnnotation'
|
|
168
|
-
? property.value.typeAnnotation
|
|
169
|
-
: property.value;
|
|
170
|
-
|
|
171
|
-
return getPropertyType(name, optional, typeAnnotation);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
175
|
-
* LTI update could not be added via codemod */
|
|
176
|
-
function getEventArgument(argumentProps, name: $FlowFixMe) {
|
|
177
|
-
return {
|
|
178
|
-
type: 'ObjectTypeAnnotation',
|
|
179
|
-
properties: argumentProps.map(buildPropertiesForEvent),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
218
|
function buildEventSchema(
|
|
184
219
|
types: TypeMap,
|
|
185
220
|
property: EventTypeAST,
|
|
221
|
+
parser: Parser,
|
|
186
222
|
): ?EventTypeShape {
|
|
187
223
|
const name = property.key.name;
|
|
188
224
|
const optional =
|
|
@@ -195,47 +231,34 @@ function buildEventSchema(
|
|
|
195
231
|
|
|
196
232
|
if (
|
|
197
233
|
typeAnnotation.type !== 'GenericTypeAnnotation' ||
|
|
198
|
-
(typeAnnotation
|
|
199
|
-
typeAnnotation
|
|
234
|
+
(parser.getTypeAnnotationName(typeAnnotation) !== 'BubblingEventHandler' &&
|
|
235
|
+
parser.getTypeAnnotationName(typeAnnotation) !== 'DirectEventHandler')
|
|
200
236
|
) {
|
|
201
237
|
return null;
|
|
202
238
|
}
|
|
203
239
|
|
|
204
240
|
const {argumentProps, bubblingType, paperTopLevelNameDeprecated} =
|
|
205
|
-
findEventArgumentsAndType(typeAnnotation, types);
|
|
206
|
-
|
|
207
|
-
if (bubblingType && argumentProps) {
|
|
208
|
-
if (paperTopLevelNameDeprecated != null) {
|
|
209
|
-
return {
|
|
210
|
-
name,
|
|
211
|
-
optional,
|
|
212
|
-
bubblingType,
|
|
213
|
-
paperTopLevelNameDeprecated,
|
|
214
|
-
typeAnnotation: {
|
|
215
|
-
type: 'EventTypeAnnotation',
|
|
216
|
-
argument: getEventArgument(argumentProps, name),
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
}
|
|
241
|
+
findEventArgumentsAndType(parser, typeAnnotation, types);
|
|
220
242
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
type: 'EventTypeAnnotation',
|
|
227
|
-
argument: getEventArgument(argumentProps, name),
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
}
|
|
243
|
+
const nonNullableArgumentProps = throwIfArgumentPropsAreNull(
|
|
244
|
+
argumentProps,
|
|
245
|
+
name,
|
|
246
|
+
);
|
|
247
|
+
const nonNullableBubblingType = throwIfBubblingTypeIsNull(bubblingType, name);
|
|
231
248
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
249
|
+
const argument = getEventArgument(
|
|
250
|
+
nonNullableArgumentProps,
|
|
251
|
+
parser,
|
|
252
|
+
getPropertyType,
|
|
253
|
+
);
|
|
235
254
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
255
|
+
return emitBuildEventSchema(
|
|
256
|
+
paperTopLevelNameDeprecated,
|
|
257
|
+
name,
|
|
258
|
+
optional,
|
|
259
|
+
nonNullableBubblingType,
|
|
260
|
+
argument,
|
|
261
|
+
);
|
|
239
262
|
}
|
|
240
263
|
|
|
241
264
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
@@ -250,13 +273,15 @@ type TypeMap = {
|
|
|
250
273
|
function getEvents(
|
|
251
274
|
eventTypeAST: $ReadOnlyArray<EventTypeAST>,
|
|
252
275
|
types: TypeMap,
|
|
276
|
+
parser: Parser,
|
|
253
277
|
): $ReadOnlyArray<EventTypeShape> {
|
|
254
278
|
return eventTypeAST
|
|
255
279
|
.filter(property => property.type === 'ObjectTypeProperty')
|
|
256
|
-
.map(property => buildEventSchema(types, property))
|
|
280
|
+
.map(property => buildEventSchema(types, property, parser))
|
|
257
281
|
.filter(Boolean);
|
|
258
282
|
}
|
|
259
283
|
|
|
260
284
|
module.exports = {
|
|
261
285
|
getEvents,
|
|
286
|
+
extractArrayElementType,
|
|
262
287
|
};
|
|
@@ -14,106 +14,25 @@ const _require = require('./commands'),
|
|
|
14
14
|
getCommands = _require.getCommands;
|
|
15
15
|
const _require2 = require('./events'),
|
|
16
16
|
getEvents = _require2.getEvents;
|
|
17
|
-
const _require3 = require('
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
getProps = _require4.getProps;
|
|
22
|
-
const _require5 = require('./componentsUtils.js'),
|
|
23
|
-
getProperties = _require5.getProperties;
|
|
24
|
-
const _require6 = require('../../error-utils'),
|
|
25
|
-
throwIfMoreThanOneCodegenNativecommands =
|
|
26
|
-
_require6.throwIfMoreThanOneCodegenNativecommands;
|
|
27
|
-
const _require7 = require('../../parsers-commons'),
|
|
28
|
-
createComponentConfig = _require7.createComponentConfig,
|
|
29
|
-
findNativeComponentType = _require7.findNativeComponentType,
|
|
30
|
-
propertyNames = _require7.propertyNames,
|
|
31
|
-
getCommandOptions = _require7.getCommandOptions,
|
|
32
|
-
getOptions = _require7.getOptions,
|
|
33
|
-
getCommandTypeNameAndOptionsExpression =
|
|
34
|
-
_require7.getCommandTypeNameAndOptionsExpression;
|
|
35
|
-
|
|
36
|
-
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
37
|
-
function findComponentConfig(ast, parser) {
|
|
38
|
-
const foundConfigs = [];
|
|
39
|
-
const defaultExports = ast.body.filter(
|
|
40
|
-
node => node.type === 'ExportDefaultDeclaration',
|
|
41
|
-
);
|
|
42
|
-
defaultExports.forEach(statement => {
|
|
43
|
-
findNativeComponentType(statement, foundConfigs, parser);
|
|
44
|
-
});
|
|
45
|
-
if (foundConfigs.length === 0) {
|
|
46
|
-
throw new Error('Could not find component config for native component');
|
|
47
|
-
}
|
|
48
|
-
if (foundConfigs.length > 1) {
|
|
49
|
-
throw new Error('Only one component is supported per file');
|
|
50
|
-
}
|
|
51
|
-
const foundConfig = foundConfigs[0];
|
|
52
|
-
const namedExports = ast.body.filter(
|
|
53
|
-
node => node.type === 'ExportNamedDeclaration',
|
|
54
|
-
);
|
|
55
|
-
const commandsTypeNames = namedExports
|
|
56
|
-
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
57
|
-
.filter(Boolean);
|
|
58
|
-
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
59
|
-
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
60
|
-
}
|
|
61
|
-
function getCommandProperties(ast, parser) {
|
|
62
|
-
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
63
|
-
commandTypeName = _findComponentConfig.commandTypeName,
|
|
64
|
-
commandOptionsExpression = _findComponentConfig.commandOptionsExpression;
|
|
65
|
-
if (commandTypeName == null) {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
const types = parser.getTypes(ast);
|
|
69
|
-
const typeAlias = types[commandTypeName];
|
|
70
|
-
if (typeAlias.type !== 'InterfaceDeclaration') {
|
|
71
|
-
throw new Error(
|
|
72
|
-
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const properties = parser.bodyProperties(typeAlias);
|
|
76
|
-
if (!properties) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const flowPropertyNames = propertyNames(properties);
|
|
82
|
-
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
83
|
-
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
if (
|
|
89
|
-
commandOptions.supportedCommands.length !== flowPropertyNames.length ||
|
|
90
|
-
!commandOptions.supportedCommands.every(supportedCommand =>
|
|
91
|
-
flowPropertyNames.includes(supportedCommand),
|
|
92
|
-
)
|
|
93
|
-
) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${flowPropertyNames.join(
|
|
96
|
-
', ',
|
|
97
|
-
)}`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return properties;
|
|
101
|
-
}
|
|
17
|
+
const _require3 = require('../../parsers-commons'),
|
|
18
|
+
getOptions = _require3.getOptions,
|
|
19
|
+
findComponentConfig = _require3.findComponentConfig,
|
|
20
|
+
getCommandProperties = _require3.getCommandProperties;
|
|
102
21
|
|
|
103
22
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
104
23
|
function buildComponentSchema(ast, parser) {
|
|
105
|
-
const
|
|
106
|
-
componentName =
|
|
107
|
-
propsTypeName =
|
|
108
|
-
optionsExpression =
|
|
24
|
+
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
25
|
+
componentName = _findComponentConfig.componentName,
|
|
26
|
+
propsTypeName = _findComponentConfig.propsTypeName,
|
|
27
|
+
optionsExpression = _findComponentConfig.optionsExpression;
|
|
109
28
|
const types = parser.getTypes(ast);
|
|
110
|
-
const propProperties = getProperties(propsTypeName, types);
|
|
29
|
+
const propProperties = parser.getProperties(propsTypeName, types);
|
|
111
30
|
const commandProperties = getCommandProperties(ast, parser);
|
|
112
|
-
const
|
|
31
|
+
const _parser$getProps = parser.getProps(propProperties, types),
|
|
32
|
+
extendsProps = _parser$getProps.extendsProps,
|
|
33
|
+
props = _parser$getProps.props;
|
|
113
34
|
const options = getOptions(optionsExpression);
|
|
114
|
-
const
|
|
115
|
-
const props = getProps(nonExtendsProps, types);
|
|
116
|
-
const events = getEvents(propProperties, types);
|
|
35
|
+
const events = getEvents(propProperties, types, parser);
|
|
117
36
|
const commands = getCommands(commandProperties, types);
|
|
118
37
|
return {
|
|
119
38
|
filename: componentName,
|
|
@@ -14,105 +14,12 @@ import type {ComponentSchemaBuilderConfig} from '../../schema.js';
|
|
|
14
14
|
|
|
15
15
|
const {getCommands} = require('./commands');
|
|
16
16
|
const {getEvents} = require('./events');
|
|
17
|
-
const {getExtendsProps, removeKnownExtends} = require('./extends');
|
|
18
|
-
const {getProps} = require('./props');
|
|
19
|
-
const {getProperties} = require('./componentsUtils.js');
|
|
20
|
-
const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
|
|
21
17
|
const {
|
|
22
|
-
createComponentConfig,
|
|
23
|
-
findNativeComponentType,
|
|
24
|
-
propertyNames,
|
|
25
|
-
getCommandOptions,
|
|
26
18
|
getOptions,
|
|
27
|
-
|
|
19
|
+
findComponentConfig,
|
|
20
|
+
getCommandProperties,
|
|
28
21
|
} = require('../../parsers-commons');
|
|
29
22
|
|
|
30
|
-
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
31
|
-
function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
|
|
32
|
-
const foundConfigs: Array<{[string]: string}> = [];
|
|
33
|
-
|
|
34
|
-
const defaultExports = ast.body.filter(
|
|
35
|
-
node => node.type === 'ExportDefaultDeclaration',
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
defaultExports.forEach(statement => {
|
|
39
|
-
findNativeComponentType(statement, foundConfigs, parser);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (foundConfigs.length === 0) {
|
|
43
|
-
throw new Error('Could not find component config for native component');
|
|
44
|
-
}
|
|
45
|
-
if (foundConfigs.length > 1) {
|
|
46
|
-
throw new Error('Only one component is supported per file');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const foundConfig = foundConfigs[0];
|
|
50
|
-
|
|
51
|
-
const namedExports = ast.body.filter(
|
|
52
|
-
node => node.type === 'ExportNamedDeclaration',
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const commandsTypeNames = namedExports
|
|
56
|
-
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
57
|
-
.filter(Boolean);
|
|
58
|
-
|
|
59
|
-
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
60
|
-
|
|
61
|
-
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getCommandProperties(ast: $FlowFixMe, parser: Parser) {
|
|
65
|
-
const {commandTypeName, commandOptionsExpression} = findComponentConfig(
|
|
66
|
-
ast,
|
|
67
|
-
parser,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
if (commandTypeName == null) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
const types = parser.getTypes(ast);
|
|
74
|
-
|
|
75
|
-
const typeAlias = types[commandTypeName];
|
|
76
|
-
|
|
77
|
-
if (typeAlias.type !== 'InterfaceDeclaration') {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const properties = parser.bodyProperties(typeAlias);
|
|
84
|
-
if (!properties) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const flowPropertyNames = propertyNames(properties);
|
|
91
|
-
|
|
92
|
-
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
93
|
-
|
|
94
|
-
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
commandOptions.supportedCommands.length !== flowPropertyNames.length ||
|
|
102
|
-
!commandOptions.supportedCommands.every(supportedCommand =>
|
|
103
|
-
flowPropertyNames.includes(supportedCommand),
|
|
104
|
-
)
|
|
105
|
-
) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${flowPropertyNames.join(
|
|
108
|
-
', ',
|
|
109
|
-
)}`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return properties;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
23
|
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
117
24
|
function buildComponentSchema(
|
|
118
25
|
ast: $FlowFixMe,
|
|
@@ -125,16 +32,12 @@ function buildComponentSchema(
|
|
|
125
32
|
|
|
126
33
|
const types = parser.getTypes(ast);
|
|
127
34
|
|
|
128
|
-
const propProperties = getProperties(propsTypeName, types);
|
|
129
|
-
|
|
35
|
+
const propProperties = parser.getProperties(propsTypeName, types);
|
|
130
36
|
const commandProperties = getCommandProperties(ast, parser);
|
|
37
|
+
const {extendsProps, props} = parser.getProps(propProperties, types);
|
|
131
38
|
|
|
132
|
-
const extendsProps = getExtendsProps(propProperties, types);
|
|
133
39
|
const options = getOptions(optionsExpression);
|
|
134
|
-
|
|
135
|
-
const nonExtendsProps = removeKnownExtends(propProperties, types);
|
|
136
|
-
const props = getProps(nonExtendsProps, types);
|
|
137
|
-
const events = getEvents(propProperties, types);
|
|
40
|
+
const events = getEvents(propProperties, types, parser);
|
|
138
41
|
const commands = getCommands(commandProperties, types);
|
|
139
42
|
|
|
140
43
|
return {
|