@react-native/codegen 0.72.2 → 0.72.4
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/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/parsers/error-utils.js +50 -15
- package/lib/parsers/error-utils.js.flow +57 -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 +27 -126
- package/lib/parsers/flow/components/index.js.flow +22 -52
- 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 +41 -317
- package/lib/parsers/flow/modules/index.js.flow +19 -247
- package/lib/parsers/flow/parser.js +119 -12
- package/lib/parsers/flow/parser.js.flow +124 -3
- package/lib/parsers/flow/utils.js +0 -38
- package/lib/parsers/flow/utils.js.flow +0 -38
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -0
- package/lib/parsers/parserMock.js +58 -0
- package/lib/parsers/parserMock.js.flow +72 -0
- package/lib/parsers/parsers-commons.js +362 -5
- package/lib/parsers/parsers-commons.js.flow +351 -8
- package/lib/parsers/parsers-primitives.js +119 -3
- package/lib/parsers/parsers-primitives.js.flow +128 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/{typescript/components/schema.js.flow → schema.js.flow} +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 +28 -127
- package/lib/parsers/typescript/components/index.js.flow +24 -54
- package/lib/parsers/typescript/modules/index.js +103 -434
- package/lib/parsers/typescript/modules/index.js.flow +85 -299
- package/lib/parsers/typescript/parser.js +113 -12
- package/lib/parsers/typescript/parser.js.flow +115 -3
- package/lib/parsers/typescript/utils.js +0 -31
- package/lib/parsers/typescript/utils.js.flow +0 -31
- 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/flow/components/schema.js +0 -106
- package/lib/parsers/flow/components/schema.js.flow +0 -62
- 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
- /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
|
@@ -16,63 +16,41 @@ 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 {
|
|
28
|
-
const {resolveTypeAnnotation, getTypes} = require('../utils');
|
|
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
34
|
emitBoolean,
|
|
39
|
-
emitDouble,
|
|
40
|
-
emitFloat,
|
|
41
35
|
emitFunction,
|
|
42
36
|
emitNumber,
|
|
43
|
-
emitInt32,
|
|
44
37
|
emitGenericObject,
|
|
45
|
-
emitObject,
|
|
46
38
|
emitPromise,
|
|
47
39
|
emitRootTag,
|
|
48
40
|
emitVoid,
|
|
49
41
|
emitString,
|
|
50
|
-
emitStringish,
|
|
51
42
|
emitMixed,
|
|
52
43
|
emitUnion,
|
|
44
|
+
emitCommonTypes,
|
|
53
45
|
typeAliasResolution,
|
|
54
46
|
typeEnumResolution,
|
|
55
47
|
} = require('../../parsers-primitives');
|
|
56
48
|
|
|
57
49
|
const {
|
|
58
50
|
UnsupportedTypeAnnotationParserError,
|
|
59
|
-
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
60
51
|
UnsupportedGenericParserError,
|
|
61
52
|
} = require('../../errors');
|
|
62
53
|
|
|
63
|
-
const {
|
|
64
|
-
throwIfModuleInterfaceNotFound,
|
|
65
|
-
throwIfModuleInterfaceIsMisnamed,
|
|
66
|
-
throwIfUnusedModuleInterfaceParserError,
|
|
67
|
-
throwIfWrongNumberOfCallExpressionArgs,
|
|
68
|
-
throwIfMoreThanOneModuleRegistryCalls,
|
|
69
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
70
|
-
throwIfUntypedModule,
|
|
71
|
-
throwIfMoreThanOneModuleInterfaceParserError,
|
|
72
|
-
} = require('../../error-utils');
|
|
73
|
-
|
|
74
|
-
const language = 'Flow';
|
|
75
|
-
|
|
76
54
|
function translateTypeAnnotation(
|
|
77
55
|
hasteModuleName: string,
|
|
78
56
|
/**
|
|
@@ -145,63 +123,27 @@ function translateTypeAnnotation(
|
|
|
145
123
|
|
|
146
124
|
return wrapNullable(nullable || isParamNullable, paramType);
|
|
147
125
|
}
|
|
148
|
-
case 'Stringish': {
|
|
149
|
-
return emitStringish(nullable);
|
|
150
|
-
}
|
|
151
|
-
case 'Int32': {
|
|
152
|
-
return emitInt32(nullable);
|
|
153
|
-
}
|
|
154
|
-
case 'Double': {
|
|
155
|
-
return emitDouble(nullable);
|
|
156
|
-
}
|
|
157
|
-
case 'Float': {
|
|
158
|
-
return emitFloat(nullable);
|
|
159
|
-
}
|
|
160
|
-
case 'UnsafeObject':
|
|
161
|
-
case 'Object': {
|
|
162
|
-
return emitGenericObject(nullable);
|
|
163
|
-
}
|
|
164
|
-
case '$Partial': {
|
|
165
|
-
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
'Partials only support annotating exactly one parameter.',
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const annotatedElement =
|
|
172
|
-
types[typeAnnotation.typeParameters.params[0].id.name];
|
|
173
|
-
|
|
174
|
-
if (!annotatedElement) {
|
|
175
|
-
throw new Error(
|
|
176
|
-
'Partials only support annotating a type parameter.',
|
|
177
|
-
);
|
|
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
126
|
default: {
|
|
200
|
-
|
|
127
|
+
const commonType = emitCommonTypes(
|
|
201
128
|
hasteModuleName,
|
|
129
|
+
types,
|
|
202
130
|
typeAnnotation,
|
|
131
|
+
aliasMap,
|
|
132
|
+
enumMap,
|
|
133
|
+
tryParse,
|
|
134
|
+
cxxOnly,
|
|
135
|
+
nullable,
|
|
203
136
|
parser,
|
|
204
137
|
);
|
|
138
|
+
|
|
139
|
+
if (!commonType) {
|
|
140
|
+
throw new UnsupportedGenericParserError(
|
|
141
|
+
hasteModuleName,
|
|
142
|
+
typeAnnotation,
|
|
143
|
+
parser,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return commonType;
|
|
205
147
|
}
|
|
206
148
|
}
|
|
207
149
|
}
|
|
@@ -315,7 +257,6 @@ function translateTypeAnnotation(
|
|
|
315
257
|
typeResolutionStatus,
|
|
316
258
|
nullable,
|
|
317
259
|
hasteModuleName,
|
|
318
|
-
language,
|
|
319
260
|
enumMap,
|
|
320
261
|
parser,
|
|
321
262
|
);
|
|
@@ -324,181 +265,12 @@ function translateTypeAnnotation(
|
|
|
324
265
|
throw new UnsupportedTypeAnnotationParserError(
|
|
325
266
|
hasteModuleName,
|
|
326
267
|
typeAnnotation,
|
|
327
|
-
language,
|
|
268
|
+
parser.language(),
|
|
328
269
|
);
|
|
329
270
|
}
|
|
330
271
|
}
|
|
331
272
|
}
|
|
332
273
|
|
|
333
|
-
function isModuleInterface(node: $FlowFixMe) {
|
|
334
|
-
return (
|
|
335
|
-
node.type === 'InterfaceDeclaration' &&
|
|
336
|
-
node.extends.length === 1 &&
|
|
337
|
-
node.extends[0].type === 'InterfaceExtends' &&
|
|
338
|
-
node.extends[0].id.name === 'TurboModule'
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function buildModuleSchema(
|
|
343
|
-
hasteModuleName: string,
|
|
344
|
-
/**
|
|
345
|
-
* TODO(T71778680): Flow-type this node.
|
|
346
|
-
*/
|
|
347
|
-
ast: $FlowFixMe,
|
|
348
|
-
tryParse: ParserErrorCapturer,
|
|
349
|
-
parser: Parser,
|
|
350
|
-
): NativeModuleSchema {
|
|
351
|
-
const types = getTypes(ast);
|
|
352
|
-
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
353
|
-
isModuleInterface,
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
throwIfModuleInterfaceNotFound(
|
|
357
|
-
moduleSpecs.length,
|
|
358
|
-
hasteModuleName,
|
|
359
|
-
ast,
|
|
360
|
-
language,
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
364
|
-
hasteModuleName,
|
|
365
|
-
moduleSpecs,
|
|
366
|
-
language,
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
const [moduleSpec] = moduleSpecs;
|
|
370
|
-
|
|
371
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
372
|
-
|
|
373
|
-
// Parse Module Name
|
|
374
|
-
const moduleName = ((): string => {
|
|
375
|
-
const callExpressions = [];
|
|
376
|
-
visit(ast, {
|
|
377
|
-
CallExpression(node) {
|
|
378
|
-
if (isModuleRegistryCall(node)) {
|
|
379
|
-
callExpressions.push(node);
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
385
|
-
hasteModuleName,
|
|
386
|
-
moduleSpec,
|
|
387
|
-
callExpressions,
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
391
|
-
hasteModuleName,
|
|
392
|
-
callExpressions,
|
|
393
|
-
callExpressions.length,
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
const [callExpression] = callExpressions;
|
|
397
|
-
const {typeArguments} = callExpression;
|
|
398
|
-
const methodName = callExpression.callee.property.name;
|
|
399
|
-
|
|
400
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
401
|
-
hasteModuleName,
|
|
402
|
-
callExpression,
|
|
403
|
-
methodName,
|
|
404
|
-
callExpression.arguments.length,
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
if (callExpression.arguments[0].type !== 'Literal') {
|
|
408
|
-
const {type} = callExpression.arguments[0];
|
|
409
|
-
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
410
|
-
hasteModuleName,
|
|
411
|
-
callExpression.arguments[0],
|
|
412
|
-
methodName,
|
|
413
|
-
type,
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
418
|
-
|
|
419
|
-
throwIfUntypedModule(
|
|
420
|
-
typeArguments,
|
|
421
|
-
hasteModuleName,
|
|
422
|
-
callExpression,
|
|
423
|
-
methodName,
|
|
424
|
-
$moduleName,
|
|
425
|
-
);
|
|
426
|
-
|
|
427
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
428
|
-
hasteModuleName,
|
|
429
|
-
typeArguments,
|
|
430
|
-
methodName,
|
|
431
|
-
$moduleName,
|
|
432
|
-
parser,
|
|
433
|
-
);
|
|
434
|
-
|
|
435
|
-
return $moduleName;
|
|
436
|
-
})();
|
|
437
|
-
|
|
438
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
439
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
440
|
-
// Also check the hasteModuleName for platform suffix.
|
|
441
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
442
|
-
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
443
|
-
hasteModuleName,
|
|
444
|
-
moduleName,
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
// $FlowFixMe[missing-type-arg]
|
|
448
|
-
return (moduleSpec.body.properties: $ReadOnlyArray<$FlowFixMe>)
|
|
449
|
-
.filter(property => property.type === 'ObjectTypeProperty')
|
|
450
|
-
.map<?{
|
|
451
|
-
aliasMap: NativeModuleAliasMap,
|
|
452
|
-
enumMap: NativeModuleEnumMap,
|
|
453
|
-
propertyShape: NativeModulePropertyShape,
|
|
454
|
-
}>(property => {
|
|
455
|
-
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
456
|
-
const enumMap: {...NativeModuleEnumMap} = {};
|
|
457
|
-
return tryParse(() => ({
|
|
458
|
-
aliasMap: aliasMap,
|
|
459
|
-
enumMap: enumMap,
|
|
460
|
-
propertyShape: buildPropertySchema(
|
|
461
|
-
hasteModuleName,
|
|
462
|
-
property,
|
|
463
|
-
types,
|
|
464
|
-
aliasMap,
|
|
465
|
-
enumMap,
|
|
466
|
-
tryParse,
|
|
467
|
-
cxxOnly,
|
|
468
|
-
resolveTypeAnnotation,
|
|
469
|
-
translateTypeAnnotation,
|
|
470
|
-
parser,
|
|
471
|
-
),
|
|
472
|
-
}));
|
|
473
|
-
})
|
|
474
|
-
.filter(Boolean)
|
|
475
|
-
.reduce(
|
|
476
|
-
(
|
|
477
|
-
moduleSchema: NativeModuleSchema,
|
|
478
|
-
{aliasMap, enumMap, propertyShape},
|
|
479
|
-
) => ({
|
|
480
|
-
type: 'NativeModule',
|
|
481
|
-
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
482
|
-
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
483
|
-
spec: {
|
|
484
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
485
|
-
},
|
|
486
|
-
moduleName: moduleSchema.moduleName,
|
|
487
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
488
|
-
}),
|
|
489
|
-
{
|
|
490
|
-
type: 'NativeModule',
|
|
491
|
-
aliasMap: {},
|
|
492
|
-
enumMap: {},
|
|
493
|
-
spec: {properties: []},
|
|
494
|
-
moduleName,
|
|
495
|
-
excludedPlatforms:
|
|
496
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
497
|
-
},
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
274
|
module.exports = {
|
|
502
|
-
buildModuleSchema,
|
|
503
275
|
flowTranslateTypeAnnotation: translateTypeAnnotation,
|
|
504
276
|
};
|
|
@@ -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(
|
|
@@ -111,6 +116,8 @@ class FlowParser {
|
|
|
111
116
|
buildModuleSchema,
|
|
112
117
|
Visitor,
|
|
113
118
|
this,
|
|
119
|
+
resolveTypeAnnotation,
|
|
120
|
+
flowTranslateTypeAnnotation,
|
|
114
121
|
);
|
|
115
122
|
}
|
|
116
123
|
parseModuleFixture(filename) {
|
|
@@ -193,6 +200,106 @@ class FlowParser {
|
|
|
193
200
|
};
|
|
194
201
|
});
|
|
195
202
|
}
|
|
203
|
+
isModuleInterface(node) {
|
|
204
|
+
return (
|
|
205
|
+
node.type === 'InterfaceDeclaration' &&
|
|
206
|
+
node.extends.length === 1 &&
|
|
207
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
208
|
+
node.extends[0].id.name === 'TurboModule'
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
212
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
217
|
+
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
218
|
+
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
219
|
+
* a way to get these types from our flow parser library.
|
|
220
|
+
*
|
|
221
|
+
* TODO(T71778680): Flow type AST Nodes
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
getTypes(ast) {
|
|
225
|
+
return ast.body.reduce((types, node) => {
|
|
226
|
+
if (
|
|
227
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
228
|
+
node.exportKind === 'type'
|
|
229
|
+
) {
|
|
230
|
+
if (
|
|
231
|
+
node.declaration != null &&
|
|
232
|
+
(node.declaration.type === 'TypeAlias' ||
|
|
233
|
+
node.declaration.type === 'InterfaceDeclaration')
|
|
234
|
+
) {
|
|
235
|
+
types[node.declaration.id.name] = node.declaration;
|
|
236
|
+
}
|
|
237
|
+
} else if (
|
|
238
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
239
|
+
node.exportKind === 'value' &&
|
|
240
|
+
node.declaration &&
|
|
241
|
+
node.declaration.type === 'EnumDeclaration'
|
|
242
|
+
) {
|
|
243
|
+
types[node.declaration.id.name] = node.declaration;
|
|
244
|
+
} else if (
|
|
245
|
+
node.type === 'TypeAlias' ||
|
|
246
|
+
node.type === 'InterfaceDeclaration' ||
|
|
247
|
+
node.type === 'EnumDeclaration'
|
|
248
|
+
) {
|
|
249
|
+
types[node.id.name] = node;
|
|
250
|
+
}
|
|
251
|
+
return types;
|
|
252
|
+
}, {});
|
|
253
|
+
}
|
|
254
|
+
callExpressionTypeParameters(callExpression) {
|
|
255
|
+
return callExpression.typeArguments || null;
|
|
256
|
+
}
|
|
257
|
+
computePartialProperties(
|
|
258
|
+
properties,
|
|
259
|
+
hasteModuleName,
|
|
260
|
+
types,
|
|
261
|
+
aliasMap,
|
|
262
|
+
enumMap,
|
|
263
|
+
tryParse,
|
|
264
|
+
cxxOnly,
|
|
265
|
+
) {
|
|
266
|
+
return properties.map(prop => {
|
|
267
|
+
return {
|
|
268
|
+
name: prop.key.name,
|
|
269
|
+
optional: true,
|
|
270
|
+
typeAnnotation: flowTranslateTypeAnnotation(
|
|
271
|
+
hasteModuleName,
|
|
272
|
+
prop.value,
|
|
273
|
+
types,
|
|
274
|
+
aliasMap,
|
|
275
|
+
enumMap,
|
|
276
|
+
tryParse,
|
|
277
|
+
cxxOnly,
|
|
278
|
+
this,
|
|
279
|
+
),
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
functionTypeAnnotation(propertyValueType) {
|
|
284
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
285
|
+
}
|
|
286
|
+
getTypeArgumentParamsFromDeclaration(declaration) {
|
|
287
|
+
return declaration.typeArguments.params;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* This FlowFixMe is supposed to refer to typeArgumentParams and
|
|
292
|
+
* funcArgumentParams of generated AST.
|
|
293
|
+
*/
|
|
294
|
+
getNativeComponentType(typeArgumentParams, funcArgumentParams) {
|
|
295
|
+
return {
|
|
296
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
297
|
+
componentName: funcArgumentParams[0].value,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
getAnnotatedElementProperties(annotatedElement) {
|
|
301
|
+
return annotatedElement.right.properties;
|
|
302
|
+
}
|
|
196
303
|
}
|
|
197
304
|
module.exports = {
|
|
198
305
|
FlowParser,
|
|
@@ -18,18 +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';
|
|
26
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
|
|
27
|
+
|
|
28
|
+
const {flowTranslateTypeAnnotation} = require('./modules');
|
|
24
29
|
|
|
25
30
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
26
31
|
const flowParser = require('flow-parser');
|
|
27
32
|
|
|
28
33
|
const {buildSchema} = require('../parsers-commons');
|
|
29
|
-
const {Visitor} = require('
|
|
34
|
+
const {Visitor} = require('../parsers-primitives');
|
|
30
35
|
const {buildComponentSchema} = require('./components');
|
|
31
|
-
const {wrapComponentSchema} = require('
|
|
32
|
-
const {buildModuleSchema} = require('
|
|
36
|
+
const {wrapComponentSchema} = require('../schema.js');
|
|
37
|
+
const {buildModuleSchema} = require('../parsers-commons.js');
|
|
38
|
+
const {resolveTypeAnnotation} = require('./utils');
|
|
33
39
|
|
|
34
40
|
const fs = require('fs');
|
|
35
41
|
|
|
@@ -100,6 +106,8 @@ class FlowParser implements Parser {
|
|
|
100
106
|
buildModuleSchema,
|
|
101
107
|
Visitor,
|
|
102
108
|
this,
|
|
109
|
+
resolveTypeAnnotation,
|
|
110
|
+
flowTranslateTypeAnnotation,
|
|
103
111
|
);
|
|
104
112
|
}
|
|
105
113
|
|
|
@@ -196,6 +204,119 @@ class FlowParser implements Parser {
|
|
|
196
204
|
value: member.init?.value ?? member.id.name,
|
|
197
205
|
}));
|
|
198
206
|
}
|
|
207
|
+
|
|
208
|
+
isModuleInterface(node: $FlowFixMe): boolean {
|
|
209
|
+
return (
|
|
210
|
+
node.type === 'InterfaceDeclaration' &&
|
|
211
|
+
node.extends.length === 1 &&
|
|
212
|
+
node.extends[0].type === 'InterfaceExtends' &&
|
|
213
|
+
node.extends[0].id.name === 'TurboModule'
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
extractAnnotatedElement(
|
|
218
|
+
typeAnnotation: $FlowFixMe,
|
|
219
|
+
types: TypeDeclarationMap,
|
|
220
|
+
): $FlowFixMe {
|
|
221
|
+
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
226
|
+
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
227
|
+
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
228
|
+
* a way to get these types from our flow parser library.
|
|
229
|
+
*
|
|
230
|
+
* TODO(T71778680): Flow type AST Nodes
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
234
|
+
return ast.body.reduce((types, node) => {
|
|
235
|
+
if (
|
|
236
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
237
|
+
node.exportKind === 'type'
|
|
238
|
+
) {
|
|
239
|
+
if (
|
|
240
|
+
node.declaration != null &&
|
|
241
|
+
(node.declaration.type === 'TypeAlias' ||
|
|
242
|
+
node.declaration.type === 'InterfaceDeclaration')
|
|
243
|
+
) {
|
|
244
|
+
types[node.declaration.id.name] = node.declaration;
|
|
245
|
+
}
|
|
246
|
+
} else if (
|
|
247
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
248
|
+
node.exportKind === 'value' &&
|
|
249
|
+
node.declaration &&
|
|
250
|
+
node.declaration.type === 'EnumDeclaration'
|
|
251
|
+
) {
|
|
252
|
+
types[node.declaration.id.name] = node.declaration;
|
|
253
|
+
} else if (
|
|
254
|
+
node.type === 'TypeAlias' ||
|
|
255
|
+
node.type === 'InterfaceDeclaration' ||
|
|
256
|
+
node.type === 'EnumDeclaration'
|
|
257
|
+
) {
|
|
258
|
+
types[node.id.name] = node;
|
|
259
|
+
}
|
|
260
|
+
return types;
|
|
261
|
+
}, {});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
|
|
265
|
+
return callExpression.typeArguments || null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
computePartialProperties(
|
|
269
|
+
properties: Array<$FlowFixMe>,
|
|
270
|
+
hasteModuleName: string,
|
|
271
|
+
types: TypeDeclarationMap,
|
|
272
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
273
|
+
enumMap: {...NativeModuleEnumMap},
|
|
274
|
+
tryParse: ParserErrorCapturer,
|
|
275
|
+
cxxOnly: boolean,
|
|
276
|
+
): Array<$FlowFixMe> {
|
|
277
|
+
return properties.map(prop => {
|
|
278
|
+
return {
|
|
279
|
+
name: prop.key.name,
|
|
280
|
+
optional: true,
|
|
281
|
+
typeAnnotation: flowTranslateTypeAnnotation(
|
|
282
|
+
hasteModuleName,
|
|
283
|
+
prop.value,
|
|
284
|
+
types,
|
|
285
|
+
aliasMap,
|
|
286
|
+
enumMap,
|
|
287
|
+
tryParse,
|
|
288
|
+
cxxOnly,
|
|
289
|
+
this,
|
|
290
|
+
),
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
functionTypeAnnotation(propertyValueType: string): boolean {
|
|
296
|
+
return propertyValueType === 'FunctionTypeAnnotation';
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
|
|
300
|
+
return declaration.typeArguments.params;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* This FlowFixMe is supposed to refer to typeArgumentParams and
|
|
305
|
+
* funcArgumentParams of generated AST.
|
|
306
|
+
*/
|
|
307
|
+
getNativeComponentType(
|
|
308
|
+
typeArgumentParams: $FlowFixMe,
|
|
309
|
+
funcArgumentParams: $FlowFixMe,
|
|
310
|
+
): {[string]: string} {
|
|
311
|
+
return {
|
|
312
|
+
propsTypeName: typeArgumentParams[0].id.name,
|
|
313
|
+
componentName: funcArgumentParams[0].value,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
318
|
+
return annotatedElement.right.properties;
|
|
319
|
+
}
|
|
199
320
|
}
|
|
200
321
|
|
|
201
322
|
module.exports = {
|
|
@@ -10,43 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
15
|
-
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
16
|
-
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
17
|
-
* a way to get these types from our flow parser library.
|
|
18
|
-
*
|
|
19
|
-
* TODO(T71778680): Flow type AST Nodes
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function getTypes(ast) {
|
|
23
|
-
return ast.body.reduce((types, node) => {
|
|
24
|
-
if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') {
|
|
25
|
-
if (
|
|
26
|
-
node.declaration != null &&
|
|
27
|
-
(node.declaration.type === 'TypeAlias' ||
|
|
28
|
-
node.declaration.type === 'InterfaceDeclaration')
|
|
29
|
-
) {
|
|
30
|
-
types[node.declaration.id.name] = node.declaration;
|
|
31
|
-
}
|
|
32
|
-
} else if (
|
|
33
|
-
node.type === 'ExportNamedDeclaration' &&
|
|
34
|
-
node.exportKind === 'value' &&
|
|
35
|
-
node.declaration &&
|
|
36
|
-
node.declaration.type === 'EnumDeclaration'
|
|
37
|
-
) {
|
|
38
|
-
types[node.declaration.id.name] = node.declaration;
|
|
39
|
-
} else if (
|
|
40
|
-
node.type === 'TypeAlias' ||
|
|
41
|
-
node.type === 'InterfaceDeclaration' ||
|
|
42
|
-
node.type === 'EnumDeclaration'
|
|
43
|
-
) {
|
|
44
|
-
types[node.id.name] = node;
|
|
45
|
-
}
|
|
46
|
-
return types;
|
|
47
|
-
}, {});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
13
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
51
14
|
|
|
52
15
|
const invariant = require('invariant');
|
|
@@ -118,5 +81,4 @@ function getValueFromTypes(value, types) {
|
|
|
118
81
|
module.exports = {
|
|
119
82
|
getValueFromTypes,
|
|
120
83
|
resolveTypeAnnotation,
|
|
121
|
-
getTypes,
|
|
122
84
|
};
|