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