@react-native/codegen 0.72.3 → 0.73.0
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/lib/CodegenSchema.d.ts +10 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +33 -44
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +35 -44
- package/lib/generators/components/GenerateEventEmitterH.js +0 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +0 -2
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- 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 +9 -15
- package/lib/parsers/error-utils.js.flow +12 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +35 -168
- package/lib/parsers/flow/components/index.js.flow +33 -107
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +51 -327
- package/lib/parsers/flow/modules/index.js.flow +34 -258
- package/lib/parsers/flow/parser.js +84 -13
- package/lib/parsers/flow/parser.js.flow +80 -4
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -3
- package/lib/parsers/parserMock.js +53 -0
- package/lib/parsers/parserMock.js.flow +64 -1
- package/lib/parsers/parsers-commons.js +397 -4
- package/lib/parsers/parsers-commons.js.flow +391 -4
- package/lib/parsers/parsers-primitives.js +121 -3
- package/lib/parsers/parsers-primitives.js.flow +134 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +37 -170
- package/lib/parsers/typescript/components/index.js.flow +33 -109
- package/lib/parsers/typescript/modules/index.js +113 -441
- package/lib/parsers/typescript/modules/index.js.flow +100 -309
- package/lib/parsers/typescript/parser.js +97 -13
- package/lib/parsers/typescript/parser.js.flow +94 -4
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
|
@@ -16,40 +16,27 @@ import type {
|
|
|
16
16
|
NativeModuleEnumMap,
|
|
17
17
|
NativeModuleBaseTypeAnnotation,
|
|
18
18
|
NativeModuleTypeAnnotation,
|
|
19
|
-
NativeModulePropertyShape,
|
|
20
|
-
NativeModuleSchema,
|
|
21
19
|
Nullable,
|
|
22
20
|
} from '../../../CodegenSchema';
|
|
23
21
|
|
|
24
22
|
import type {Parser} from '../../parser';
|
|
25
23
|
import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
|
|
26
24
|
|
|
27
|
-
const {visit, isModuleRegistryCall, verifyPlatforms} = require('../../utils');
|
|
28
25
|
const {resolveTypeAnnotation} = require('../utils');
|
|
29
26
|
const {
|
|
30
27
|
unwrapNullable,
|
|
31
28
|
wrapNullable,
|
|
32
29
|
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
|
|
33
30
|
parseObjectProperty,
|
|
34
|
-
buildPropertySchema,
|
|
35
31
|
} = require('../../parsers-commons');
|
|
36
32
|
const {
|
|
37
33
|
emitArrayType,
|
|
38
|
-
emitBoolean,
|
|
39
|
-
emitDouble,
|
|
40
|
-
emitFloat,
|
|
41
34
|
emitFunction,
|
|
42
|
-
emitNumber,
|
|
43
|
-
emitInt32,
|
|
44
35
|
emitGenericObject,
|
|
45
|
-
emitObject,
|
|
46
36
|
emitPromise,
|
|
47
37
|
emitRootTag,
|
|
48
|
-
emitVoid,
|
|
49
|
-
emitString,
|
|
50
|
-
emitStringish,
|
|
51
|
-
emitMixed,
|
|
52
38
|
emitUnion,
|
|
39
|
+
emitCommonTypes,
|
|
53
40
|
typeAliasResolution,
|
|
54
41
|
typeEnumResolution,
|
|
55
42
|
} = require('../../parsers-primitives');
|
|
@@ -59,22 +46,6 @@ const {
|
|
|
59
46
|
UnsupportedGenericParserError,
|
|
60
47
|
} = require('../../errors');
|
|
61
48
|
|
|
62
|
-
const {
|
|
63
|
-
throwIfModuleInterfaceNotFound,
|
|
64
|
-
throwIfModuleInterfaceIsMisnamed,
|
|
65
|
-
throwIfUnusedModuleInterfaceParserError,
|
|
66
|
-
throwIfWrongNumberOfCallExpressionArgs,
|
|
67
|
-
throwIfMoreThanOneModuleRegistryCalls,
|
|
68
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
69
|
-
throwIfIncorrectModuleRegistryCallArgument,
|
|
70
|
-
throwIfUntypedModule,
|
|
71
|
-
throwIfMoreThanOneModuleInterfaceParserError,
|
|
72
|
-
throwIfPartialNotAnnotatingTypeParameter,
|
|
73
|
-
throwIfPartialWithMoreParameter,
|
|
74
|
-
} = require('../../error-utils');
|
|
75
|
-
|
|
76
|
-
const language = 'Flow';
|
|
77
|
-
|
|
78
49
|
function translateTypeAnnotation(
|
|
79
50
|
hasteModuleName: string,
|
|
80
51
|
/**
|
|
@@ -147,61 +118,27 @@ function translateTypeAnnotation(
|
|
|
147
118
|
|
|
148
119
|
return wrapNullable(nullable || isParamNullable, paramType);
|
|
149
120
|
}
|
|
150
|
-
case 'Stringish': {
|
|
151
|
-
return emitStringish(nullable);
|
|
152
|
-
}
|
|
153
|
-
case 'Int32': {
|
|
154
|
-
return emitInt32(nullable);
|
|
155
|
-
}
|
|
156
|
-
case 'Double': {
|
|
157
|
-
return emitDouble(nullable);
|
|
158
|
-
}
|
|
159
|
-
case 'Float': {
|
|
160
|
-
return emitFloat(nullable);
|
|
161
|
-
}
|
|
162
|
-
case 'UnsafeObject':
|
|
163
|
-
case 'Object': {
|
|
164
|
-
return emitGenericObject(nullable);
|
|
165
|
-
}
|
|
166
|
-
case '$Partial': {
|
|
167
|
-
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
168
|
-
|
|
169
|
-
const annotatedElement = parser.extractAnnotatedElement(
|
|
170
|
-
typeAnnotation,
|
|
171
|
-
types,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
throwIfPartialNotAnnotatingTypeParameter(
|
|
175
|
-
typeAnnotation,
|
|
176
|
-
types,
|
|
177
|
-
parser,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const properties = annotatedElement.right.properties.map(prop => {
|
|
181
|
-
return {
|
|
182
|
-
name: prop.key.name,
|
|
183
|
-
optional: true,
|
|
184
|
-
typeAnnotation: translateTypeAnnotation(
|
|
185
|
-
hasteModuleName,
|
|
186
|
-
prop.value,
|
|
187
|
-
types,
|
|
188
|
-
aliasMap,
|
|
189
|
-
enumMap,
|
|
190
|
-
tryParse,
|
|
191
|
-
cxxOnly,
|
|
192
|
-
parser,
|
|
193
|
-
),
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return emitObject(nullable, properties);
|
|
198
|
-
}
|
|
199
121
|
default: {
|
|
200
|
-
|
|
122
|
+
const commonType = emitCommonTypes(
|
|
201
123
|
hasteModuleName,
|
|
124
|
+
types,
|
|
202
125
|
typeAnnotation,
|
|
126
|
+
aliasMap,
|
|
127
|
+
enumMap,
|
|
128
|
+
tryParse,
|
|
129
|
+
cxxOnly,
|
|
130
|
+
nullable,
|
|
203
131
|
parser,
|
|
204
132
|
);
|
|
133
|
+
|
|
134
|
+
if (!commonType) {
|
|
135
|
+
throw new UnsupportedGenericParserError(
|
|
136
|
+
hasteModuleName,
|
|
137
|
+
typeAnnotation,
|
|
138
|
+
parser,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return commonType;
|
|
205
142
|
}
|
|
206
143
|
}
|
|
207
144
|
}
|
|
@@ -265,18 +202,6 @@ function translateTypeAnnotation(
|
|
|
265
202
|
nullable,
|
|
266
203
|
);
|
|
267
204
|
}
|
|
268
|
-
case 'BooleanTypeAnnotation': {
|
|
269
|
-
return emitBoolean(nullable);
|
|
270
|
-
}
|
|
271
|
-
case 'NumberTypeAnnotation': {
|
|
272
|
-
return emitNumber(nullable);
|
|
273
|
-
}
|
|
274
|
-
case 'VoidTypeAnnotation': {
|
|
275
|
-
return emitVoid(nullable);
|
|
276
|
-
}
|
|
277
|
-
case 'StringTypeAnnotation': {
|
|
278
|
-
return emitString(nullable);
|
|
279
|
-
}
|
|
280
205
|
case 'FunctionTypeAnnotation': {
|
|
281
206
|
return emitFunction(
|
|
282
207
|
nullable,
|
|
@@ -301,13 +226,6 @@ function translateTypeAnnotation(
|
|
|
301
226
|
memberType: 'StringTypeAnnotation',
|
|
302
227
|
});
|
|
303
228
|
}
|
|
304
|
-
case 'MixedTypeAnnotation': {
|
|
305
|
-
if (cxxOnly) {
|
|
306
|
-
return emitMixed(nullable);
|
|
307
|
-
} else {
|
|
308
|
-
return emitGenericObject(nullable);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
229
|
case 'EnumStringBody':
|
|
312
230
|
case 'EnumNumberBody': {
|
|
313
231
|
return typeEnumResolution(
|
|
@@ -315,177 +233,35 @@ function translateTypeAnnotation(
|
|
|
315
233
|
typeResolutionStatus,
|
|
316
234
|
nullable,
|
|
317
235
|
hasteModuleName,
|
|
318
|
-
language,
|
|
319
236
|
enumMap,
|
|
320
237
|
parser,
|
|
321
238
|
);
|
|
322
239
|
}
|
|
323
240
|
default: {
|
|
324
|
-
|
|
241
|
+
const commonType = emitCommonTypes(
|
|
325
242
|
hasteModuleName,
|
|
243
|
+
types,
|
|
326
244
|
typeAnnotation,
|
|
327
|
-
|
|
245
|
+
aliasMap,
|
|
246
|
+
enumMap,
|
|
247
|
+
tryParse,
|
|
248
|
+
cxxOnly,
|
|
249
|
+
nullable,
|
|
250
|
+
parser,
|
|
328
251
|
);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function buildModuleSchema(
|
|
334
|
-
hasteModuleName: string,
|
|
335
|
-
/**
|
|
336
|
-
* TODO(T71778680): Flow-type this node.
|
|
337
|
-
*/
|
|
338
|
-
ast: $FlowFixMe,
|
|
339
|
-
tryParse: ParserErrorCapturer,
|
|
340
|
-
parser: Parser,
|
|
341
|
-
): NativeModuleSchema {
|
|
342
|
-
const types = parser.getTypes(ast);
|
|
343
|
-
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
344
|
-
t => parser.isModuleInterface(t),
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
throwIfModuleInterfaceNotFound(
|
|
348
|
-
moduleSpecs.length,
|
|
349
|
-
hasteModuleName,
|
|
350
|
-
ast,
|
|
351
|
-
language,
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
355
|
-
hasteModuleName,
|
|
356
|
-
moduleSpecs,
|
|
357
|
-
language,
|
|
358
|
-
);
|
|
359
252
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
363
|
-
|
|
364
|
-
// Parse Module Name
|
|
365
|
-
const moduleName = ((): string => {
|
|
366
|
-
const callExpressions = [];
|
|
367
|
-
visit(ast, {
|
|
368
|
-
CallExpression(node) {
|
|
369
|
-
if (isModuleRegistryCall(node)) {
|
|
370
|
-
callExpressions.push(node);
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
376
|
-
hasteModuleName,
|
|
377
|
-
moduleSpec,
|
|
378
|
-
callExpressions,
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
382
|
-
hasteModuleName,
|
|
383
|
-
callExpressions,
|
|
384
|
-
callExpressions.length,
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
const [callExpression] = callExpressions;
|
|
388
|
-
const {typeArguments} = callExpression;
|
|
389
|
-
const methodName = callExpression.callee.property.name;
|
|
390
|
-
|
|
391
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
392
|
-
hasteModuleName,
|
|
393
|
-
callExpression,
|
|
394
|
-
methodName,
|
|
395
|
-
callExpression.arguments.length,
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
throwIfIncorrectModuleRegistryCallArgument(
|
|
399
|
-
hasteModuleName,
|
|
400
|
-
callExpression.arguments[0],
|
|
401
|
-
methodName,
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
405
|
-
|
|
406
|
-
throwIfUntypedModule(
|
|
407
|
-
typeArguments,
|
|
408
|
-
hasteModuleName,
|
|
409
|
-
callExpression,
|
|
410
|
-
methodName,
|
|
411
|
-
$moduleName,
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
415
|
-
hasteModuleName,
|
|
416
|
-
typeArguments,
|
|
417
|
-
methodName,
|
|
418
|
-
$moduleName,
|
|
419
|
-
parser,
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
return $moduleName;
|
|
423
|
-
})();
|
|
424
|
-
|
|
425
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
426
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
427
|
-
// Also check the hasteModuleName for platform suffix.
|
|
428
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
429
|
-
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
430
|
-
hasteModuleName,
|
|
431
|
-
moduleName,
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
// $FlowFixMe[missing-type-arg]
|
|
435
|
-
return (moduleSpec.body.properties: $ReadOnlyArray<$FlowFixMe>)
|
|
436
|
-
.filter(property => property.type === 'ObjectTypeProperty')
|
|
437
|
-
.map<?{
|
|
438
|
-
aliasMap: NativeModuleAliasMap,
|
|
439
|
-
enumMap: NativeModuleEnumMap,
|
|
440
|
-
propertyShape: NativeModulePropertyShape,
|
|
441
|
-
}>(property => {
|
|
442
|
-
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
443
|
-
const enumMap: {...NativeModuleEnumMap} = {};
|
|
444
|
-
return tryParse(() => ({
|
|
445
|
-
aliasMap: aliasMap,
|
|
446
|
-
enumMap: enumMap,
|
|
447
|
-
propertyShape: buildPropertySchema(
|
|
253
|
+
if (!commonType) {
|
|
254
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
448
255
|
hasteModuleName,
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
translateTypeAnnotation,
|
|
457
|
-
parser,
|
|
458
|
-
),
|
|
459
|
-
}));
|
|
460
|
-
})
|
|
461
|
-
.filter(Boolean)
|
|
462
|
-
.reduce(
|
|
463
|
-
(
|
|
464
|
-
moduleSchema: NativeModuleSchema,
|
|
465
|
-
{aliasMap, enumMap, propertyShape},
|
|
466
|
-
) => ({
|
|
467
|
-
type: 'NativeModule',
|
|
468
|
-
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
469
|
-
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
470
|
-
spec: {
|
|
471
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
472
|
-
},
|
|
473
|
-
moduleName: moduleSchema.moduleName,
|
|
474
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
475
|
-
}),
|
|
476
|
-
{
|
|
477
|
-
type: 'NativeModule',
|
|
478
|
-
aliasMap: {},
|
|
479
|
-
enumMap: {},
|
|
480
|
-
spec: {properties: []},
|
|
481
|
-
moduleName,
|
|
482
|
-
excludedPlatforms:
|
|
483
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
484
|
-
},
|
|
485
|
-
);
|
|
256
|
+
typeAnnotation,
|
|
257
|
+
parser.language(),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return commonType;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
486
263
|
}
|
|
487
264
|
|
|
488
265
|
module.exports = {
|
|
489
|
-
buildModuleSchema,
|
|
490
266
|
flowTranslateTypeAnnotation: translateTypeAnnotation,
|
|
491
267
|
};
|
|
@@ -38,22 +38,27 @@ function _toPrimitive(input, hint) {
|
|
|
38
38
|
}
|
|
39
39
|
return (hint === 'string' ? String : Number)(input);
|
|
40
40
|
}
|
|
41
|
+
const _require = require('./modules'),
|
|
42
|
+
flowTranslateTypeAnnotation = _require.flowTranslateTypeAnnotation;
|
|
43
|
+
|
|
41
44
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
42
45
|
const flowParser = require('flow-parser');
|
|
43
|
-
const
|
|
44
|
-
buildSchema =
|
|
45
|
-
const
|
|
46
|
-
Visitor =
|
|
47
|
-
const
|
|
48
|
-
buildComponentSchema =
|
|
49
|
-
const
|
|
50
|
-
wrapComponentSchema =
|
|
51
|
-
const
|
|
52
|
-
buildModuleSchema =
|
|
46
|
+
const _require2 = require('../parsers-commons'),
|
|
47
|
+
buildSchema = _require2.buildSchema;
|
|
48
|
+
const _require3 = require('../parsers-primitives'),
|
|
49
|
+
Visitor = _require3.Visitor;
|
|
50
|
+
const _require4 = require('./components'),
|
|
51
|
+
buildComponentSchema = _require4.buildComponentSchema;
|
|
52
|
+
const _require5 = require('../schema.js'),
|
|
53
|
+
wrapComponentSchema = _require5.wrapComponentSchema;
|
|
54
|
+
const _require6 = require('../parsers-commons.js'),
|
|
55
|
+
buildModuleSchema = _require6.buildModuleSchema;
|
|
56
|
+
const _require7 = require('./utils'),
|
|
57
|
+
resolveTypeAnnotation = _require7.resolveTypeAnnotation;
|
|
53
58
|
const fs = require('fs');
|
|
54
|
-
const
|
|
59
|
+
const _require8 = require('../errors'),
|
|
55
60
|
UnsupportedObjectPropertyTypeAnnotationParserError =
|
|
56
|
-
|
|
61
|
+
_require8.UnsupportedObjectPropertyTypeAnnotationParserError;
|
|
57
62
|
class FlowParser {
|
|
58
63
|
constructor() {
|
|
59
64
|
_defineProperty(
|
|
@@ -80,7 +85,13 @@ class FlowParser {
|
|
|
80
85
|
return 'Flow';
|
|
81
86
|
}
|
|
82
87
|
nameForGenericTypeAnnotation(typeAnnotation) {
|
|
83
|
-
|
|
88
|
+
var _typeAnnotation$id;
|
|
89
|
+
return typeAnnotation === null || typeAnnotation === void 0
|
|
90
|
+
? void 0
|
|
91
|
+
: (_typeAnnotation$id = typeAnnotation.id) === null ||
|
|
92
|
+
_typeAnnotation$id === void 0
|
|
93
|
+
? void 0
|
|
94
|
+
: _typeAnnotation$id.name;
|
|
84
95
|
}
|
|
85
96
|
checkIfInvalidModule(typeArguments) {
|
|
86
97
|
return (
|
|
@@ -111,6 +122,8 @@ class FlowParser {
|
|
|
111
122
|
buildModuleSchema,
|
|
112
123
|
Visitor,
|
|
113
124
|
this,
|
|
125
|
+
resolveTypeAnnotation,
|
|
126
|
+
flowTranslateTypeAnnotation,
|
|
114
127
|
);
|
|
115
128
|
}
|
|
116
129
|
parseModuleFixture(filename) {
|
|
@@ -201,6 +214,9 @@ class FlowParser {
|
|
|
201
214
|
node.extends[0].id.name === 'TurboModule'
|
|
202
215
|
);
|
|
203
216
|
}
|
|
217
|
+
isGenericTypeAnnotation(type) {
|
|
218
|
+
return type === 'GenericTypeAnnotation';
|
|
219
|
+
}
|
|
204
220
|
extractAnnotatedElement(typeAnnotation, types) {
|
|
205
221
|
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
206
222
|
}
|
|
@@ -244,6 +260,61 @@ class FlowParser {
|
|
|
244
260
|
return types;
|
|
245
261
|
}, {});
|
|
246
262
|
}
|
|
263
|
+
callExpressionTypeParameters(callExpression) {
|
|
264
|
+
return callExpression.typeArguments || null;
|
|
265
|
+
}
|
|
266
|
+
computePartialProperties(
|
|
267
|
+
properties,
|
|
268
|
+
hasteModuleName,
|
|
269
|
+
types,
|
|
270
|
+
aliasMap,
|
|
271
|
+
enumMap,
|
|
272
|
+
tryParse,
|
|
273
|
+
cxxOnly,
|
|
274
|
+
) {
|
|
275
|
+
return properties.map(prop => {
|
|
276
|
+
return {
|
|
277
|
+
name: prop.key.name,
|
|
278
|
+
optional: true,
|
|
279
|
+
typeAnnotation: flowTranslateTypeAnnotation(
|
|
280
|
+
hasteModuleName,
|
|
281
|
+
prop.value,
|
|
282
|
+
types,
|
|
283
|
+
aliasMap,
|
|
284
|
+
enumMap,
|
|
285
|
+
tryParse,
|
|
286
|
+
cxxOnly,
|
|
287
|
+
this,
|
|
288
|
+
),
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
functionTypeAnnotation(propertyValueType) {
|
|
293
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
294
|
+
}
|
|
295
|
+
getTypeArgumentParamsFromDeclaration(declaration) {
|
|
296
|
+
return declaration.typeArguments.params;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* This FlowFixMe is supposed to refer to typeArgumentParams and
|
|
301
|
+
* funcArgumentParams of generated AST.
|
|
302
|
+
*/
|
|
303
|
+
getNativeComponentType(typeArgumentParams, funcArgumentParams) {
|
|
304
|
+
return {
|
|
305
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
306
|
+
componentName: funcArgumentParams[0].value,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
getAnnotatedElementProperties(annotatedElement) {
|
|
310
|
+
return annotatedElement.right.properties;
|
|
311
|
+
}
|
|
312
|
+
bodyProperties(typeAlias) {
|
|
313
|
+
return typeAlias.body.properties;
|
|
314
|
+
}
|
|
315
|
+
convertKeywordToTypeAnnotation(keyword) {
|
|
316
|
+
return keyword;
|
|
317
|
+
}
|
|
247
318
|
}
|
|
248
319
|
module.exports = {
|
|
249
320
|
FlowParser,
|
|
@@ -18,19 +18,24 @@ import type {
|
|
|
18
18
|
NativeModuleParamTypeAnnotation,
|
|
19
19
|
NativeModuleEnumMemberType,
|
|
20
20
|
NativeModuleEnumMembers,
|
|
21
|
+
NativeModuleAliasMap,
|
|
22
|
+
NativeModuleEnumMap,
|
|
21
23
|
} from '../../CodegenSchema';
|
|
22
24
|
import type {ParserType} from '../errors';
|
|
23
25
|
import type {Parser} from '../parser';
|
|
24
|
-
import type {TypeDeclarationMap} from '../utils';
|
|
26
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
|
|
27
|
+
|
|
28
|
+
const {flowTranslateTypeAnnotation} = require('./modules');
|
|
25
29
|
|
|
26
30
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
27
31
|
const flowParser = require('flow-parser');
|
|
28
32
|
|
|
29
33
|
const {buildSchema} = require('../parsers-commons');
|
|
30
|
-
const {Visitor} = require('
|
|
34
|
+
const {Visitor} = require('../parsers-primitives');
|
|
31
35
|
const {buildComponentSchema} = require('./components');
|
|
32
36
|
const {wrapComponentSchema} = require('../schema.js');
|
|
33
|
-
const {buildModuleSchema} = require('
|
|
37
|
+
const {buildModuleSchema} = require('../parsers-commons.js');
|
|
38
|
+
const {resolveTypeAnnotation} = require('./utils');
|
|
34
39
|
|
|
35
40
|
const fs = require('fs');
|
|
36
41
|
|
|
@@ -62,7 +67,7 @@ class FlowParser implements Parser {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string {
|
|
65
|
-
return typeAnnotation
|
|
70
|
+
return typeAnnotation?.id?.name;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
checkIfInvalidModule(typeArguments: $FlowFixMe): boolean {
|
|
@@ -101,6 +106,8 @@ class FlowParser implements Parser {
|
|
|
101
106
|
buildModuleSchema,
|
|
102
107
|
Visitor,
|
|
103
108
|
this,
|
|
109
|
+
resolveTypeAnnotation,
|
|
110
|
+
flowTranslateTypeAnnotation,
|
|
104
111
|
);
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -207,6 +214,10 @@ class FlowParser implements Parser {
|
|
|
207
214
|
);
|
|
208
215
|
}
|
|
209
216
|
|
|
217
|
+
isGenericTypeAnnotation(type: $FlowFixMe): boolean {
|
|
218
|
+
return type === 'GenericTypeAnnotation';
|
|
219
|
+
}
|
|
220
|
+
|
|
210
221
|
extractAnnotatedElement(
|
|
211
222
|
typeAnnotation: $FlowFixMe,
|
|
212
223
|
types: TypeDeclarationMap,
|
|
@@ -253,6 +264,71 @@ class FlowParser implements Parser {
|
|
|
253
264
|
return types;
|
|
254
265
|
}, {});
|
|
255
266
|
}
|
|
267
|
+
|
|
268
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
|
|
269
|
+
return callExpression.typeArguments || null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
computePartialProperties(
|
|
273
|
+
properties: Array<$FlowFixMe>,
|
|
274
|
+
hasteModuleName: string,
|
|
275
|
+
types: TypeDeclarationMap,
|
|
276
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
277
|
+
enumMap: {...NativeModuleEnumMap},
|
|
278
|
+
tryParse: ParserErrorCapturer,
|
|
279
|
+
cxxOnly: boolean,
|
|
280
|
+
): Array<$FlowFixMe> {
|
|
281
|
+
return properties.map(prop => {
|
|
282
|
+
return {
|
|
283
|
+
name: prop.key.name,
|
|
284
|
+
optional: true,
|
|
285
|
+
typeAnnotation: flowTranslateTypeAnnotation(
|
|
286
|
+
hasteModuleName,
|
|
287
|
+
prop.value,
|
|
288
|
+
types,
|
|
289
|
+
aliasMap,
|
|
290
|
+
enumMap,
|
|
291
|
+
tryParse,
|
|
292
|
+
cxxOnly,
|
|
293
|
+
this,
|
|
294
|
+
),
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
functionTypeAnnotation(propertyValueType: string): boolean {
|
|
300
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
|
|
304
|
+
return declaration.typeArguments.params;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* This FlowFixMe is supposed to refer to typeArgumentParams and
|
|
309
|
+
* funcArgumentParams of generated AST.
|
|
310
|
+
*/
|
|
311
|
+
getNativeComponentType(
|
|
312
|
+
typeArgumentParams: $FlowFixMe,
|
|
313
|
+
funcArgumentParams: $FlowFixMe,
|
|
314
|
+
): {[string]: string} {
|
|
315
|
+
return {
|
|
316
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
317
|
+
componentName: funcArgumentParams[0].value,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
322
|
+
return annotatedElement.right.properties;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe> {
|
|
326
|
+
return typeAlias.body.properties;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
convertKeywordToTypeAnnotation(keyword: string): string {
|
|
330
|
+
return keyword;
|
|
331
|
+
}
|
|
256
332
|
}
|
|
257
333
|
|
|
258
334
|
module.exports = {
|
package/lib/parsers/parser.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { SchemaType } from
|
|
9
|
-
import type { ParserType } from
|
|
8
|
+
import type { SchemaType } from '../CodegenSchema';
|
|
9
|
+
import type { ParserType } from './errors';
|
|
10
10
|
|
|
11
11
|
// useful members only for downstream
|
|
12
12
|
export interface Parser {
|