@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
|
@@ -20,22 +20,46 @@ import type {
|
|
|
20
20
|
NativeModuleEnumMembers,
|
|
21
21
|
NativeModuleAliasMap,
|
|
22
22
|
NativeModuleEnumMap,
|
|
23
|
+
PropTypeAnnotation,
|
|
24
|
+
ExtendsPropsShape,
|
|
23
25
|
} from '../../CodegenSchema';
|
|
24
26
|
import type {ParserType} from '../errors';
|
|
25
|
-
import type {
|
|
26
|
-
|
|
27
|
+
import type {
|
|
28
|
+
GetSchemaInfoFN,
|
|
29
|
+
GetTypeAnnotationFN,
|
|
30
|
+
Parser,
|
|
31
|
+
ResolveTypeAnnotationFN,
|
|
32
|
+
} from '../parser';
|
|
33
|
+
import type {
|
|
34
|
+
ParserErrorCapturer,
|
|
35
|
+
TypeDeclarationMap,
|
|
36
|
+
PropAST,
|
|
37
|
+
TypeResolutionStatus,
|
|
38
|
+
} from '../utils';
|
|
39
|
+
|
|
40
|
+
type ExtendsForProp = null | {
|
|
41
|
+
type: 'ReactNativeBuiltInType',
|
|
42
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const invariant = require('invariant');
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
getSchemaInfo,
|
|
49
|
+
getTypeAnnotation,
|
|
50
|
+
flattenProperties,
|
|
51
|
+
} = require('./components/componentsUtils');
|
|
27
52
|
|
|
28
53
|
const {flowTranslateTypeAnnotation} = require('./modules');
|
|
29
54
|
|
|
30
55
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
31
56
|
const flowParser = require('flow-parser');
|
|
32
57
|
|
|
33
|
-
const {buildSchema} = require('../parsers-commons');
|
|
58
|
+
const {buildSchema, buildPropSchema} = require('../parsers-commons');
|
|
34
59
|
const {Visitor} = require('../parsers-primitives');
|
|
35
60
|
const {buildComponentSchema} = require('./components');
|
|
36
61
|
const {wrapComponentSchema} = require('../schema.js');
|
|
37
62
|
const {buildModuleSchema} = require('../parsers-commons.js');
|
|
38
|
-
const {resolveTypeAnnotation} = require('./utils');
|
|
39
63
|
|
|
40
64
|
const fs = require('fs');
|
|
41
65
|
|
|
@@ -45,6 +69,11 @@ const {
|
|
|
45
69
|
|
|
46
70
|
class FlowParser implements Parser {
|
|
47
71
|
typeParameterInstantiation: string = 'TypeParameterInstantiation';
|
|
72
|
+
typeAlias: string = 'TypeAlias';
|
|
73
|
+
enumDeclaration: string = 'EnumDeclaration';
|
|
74
|
+
interfaceDeclaration: string = 'InterfaceDeclaration';
|
|
75
|
+
nullLiteralTypeAnnotation: string = 'NullLiteralTypeAnnotation';
|
|
76
|
+
undefinedLiteralTypeAnnotation: string = 'VoidLiteralTypeAnnotation';
|
|
48
77
|
|
|
49
78
|
isProperty(property: $FlowFixMe): boolean {
|
|
50
79
|
return property.type === 'ObjectTypeProperty';
|
|
@@ -67,7 +96,7 @@ class FlowParser implements Parser {
|
|
|
67
96
|
}
|
|
68
97
|
|
|
69
98
|
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string {
|
|
70
|
-
return typeAnnotation
|
|
99
|
+
return typeAnnotation?.id?.name;
|
|
71
100
|
}
|
|
72
101
|
|
|
73
102
|
checkIfInvalidModule(typeArguments: $FlowFixMe): boolean {
|
|
@@ -106,7 +135,6 @@ class FlowParser implements Parser {
|
|
|
106
135
|
buildModuleSchema,
|
|
107
136
|
Visitor,
|
|
108
137
|
this,
|
|
109
|
-
resolveTypeAnnotation,
|
|
110
138
|
flowTranslateTypeAnnotation,
|
|
111
139
|
);
|
|
112
140
|
}
|
|
@@ -214,6 +242,10 @@ class FlowParser implements Parser {
|
|
|
214
242
|
);
|
|
215
243
|
}
|
|
216
244
|
|
|
245
|
+
isGenericTypeAnnotation(type: $FlowFixMe): boolean {
|
|
246
|
+
return type === 'GenericTypeAnnotation';
|
|
247
|
+
}
|
|
248
|
+
|
|
217
249
|
extractAnnotatedElement(
|
|
218
250
|
typeAnnotation: $FlowFixMe,
|
|
219
251
|
types: TypeDeclarationMap,
|
|
@@ -317,6 +349,188 @@ class FlowParser implements Parser {
|
|
|
317
349
|
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
318
350
|
return annotatedElement.right.properties;
|
|
319
351
|
}
|
|
352
|
+
|
|
353
|
+
bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe> {
|
|
354
|
+
return typeAlias.body.properties;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
convertKeywordToTypeAnnotation(keyword: string): string {
|
|
358
|
+
return keyword;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
argumentForProp(prop: PropAST): $FlowFixMe {
|
|
362
|
+
return prop.argument;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
nameForArgument(prop: PropAST): $FlowFixMe {
|
|
366
|
+
return prop.argument.id.name;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
isOptionalProperty(property: $FlowFixMe): boolean {
|
|
370
|
+
return (
|
|
371
|
+
property.value.type === 'NullableTypeAnnotation' || property.optional
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
getGetSchemaInfoFN(): GetSchemaInfoFN {
|
|
376
|
+
return getSchemaInfo;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
getGetTypeAnnotationFN(): GetTypeAnnotationFN {
|
|
380
|
+
return getTypeAnnotation;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
getResolvedTypeAnnotation(
|
|
384
|
+
typeAnnotation: $FlowFixMe,
|
|
385
|
+
types: TypeDeclarationMap,
|
|
386
|
+
parser: Parser,
|
|
387
|
+
): {
|
|
388
|
+
nullable: boolean,
|
|
389
|
+
typeAnnotation: $FlowFixMe,
|
|
390
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
391
|
+
} {
|
|
392
|
+
invariant(
|
|
393
|
+
typeAnnotation != null,
|
|
394
|
+
'resolveTypeAnnotation(): typeAnnotation cannot be null',
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
let node = typeAnnotation;
|
|
398
|
+
let nullable = false;
|
|
399
|
+
let typeResolutionStatus: TypeResolutionStatus = {
|
|
400
|
+
successful: false,
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
for (;;) {
|
|
404
|
+
if (node.type === 'NullableTypeAnnotation') {
|
|
405
|
+
nullable = true;
|
|
406
|
+
node = node.typeAnnotation;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (node.type !== 'GenericTypeAnnotation') {
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const resolvedTypeAnnotation = types[node.id.name];
|
|
415
|
+
if (resolvedTypeAnnotation == null) {
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
switch (resolvedTypeAnnotation.type) {
|
|
420
|
+
case parser.typeAlias: {
|
|
421
|
+
typeResolutionStatus = {
|
|
422
|
+
successful: true,
|
|
423
|
+
type: 'alias',
|
|
424
|
+
name: node.id.name,
|
|
425
|
+
};
|
|
426
|
+
node = resolvedTypeAnnotation.right;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
case parser.enumDeclaration: {
|
|
430
|
+
typeResolutionStatus = {
|
|
431
|
+
successful: true,
|
|
432
|
+
type: 'enum',
|
|
433
|
+
name: node.id.name,
|
|
434
|
+
};
|
|
435
|
+
node = resolvedTypeAnnotation.body;
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
default: {
|
|
439
|
+
throw new TypeError(
|
|
440
|
+
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}') or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
nullable: nullable,
|
|
448
|
+
typeAnnotation: node,
|
|
449
|
+
typeResolutionStatus,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
getResolveTypeAnnotationFN(): ResolveTypeAnnotationFN {
|
|
454
|
+
return (typeAnnotation, types, parser) =>
|
|
455
|
+
this.getResolvedTypeAnnotation(typeAnnotation, types, parser);
|
|
456
|
+
}
|
|
457
|
+
extendsForProp(
|
|
458
|
+
prop: PropAST,
|
|
459
|
+
types: TypeDeclarationMap,
|
|
460
|
+
parser: Parser,
|
|
461
|
+
): ExtendsForProp {
|
|
462
|
+
const argument = this.argumentForProp(prop);
|
|
463
|
+
if (!argument) {
|
|
464
|
+
console.log('null', prop);
|
|
465
|
+
}
|
|
466
|
+
const name = parser.nameForArgument(prop);
|
|
467
|
+
|
|
468
|
+
if (types[name] != null) {
|
|
469
|
+
// This type is locally defined in the file
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
switch (name) {
|
|
474
|
+
case 'ViewProps':
|
|
475
|
+
return {
|
|
476
|
+
type: 'ReactNativeBuiltInType',
|
|
477
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
478
|
+
};
|
|
479
|
+
default: {
|
|
480
|
+
throw new Error(`Unable to handle prop spread: ${name}`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
removeKnownExtends(
|
|
486
|
+
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
487
|
+
types: TypeDeclarationMap,
|
|
488
|
+
): $ReadOnlyArray<PropAST> {
|
|
489
|
+
return typeDefinition.filter(
|
|
490
|
+
prop =>
|
|
491
|
+
prop.type !== 'ObjectTypeSpreadProperty' ||
|
|
492
|
+
this.extendsForProp(prop, types, this) === null,
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
getExtendsProps(
|
|
497
|
+
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
498
|
+
types: TypeDeclarationMap,
|
|
499
|
+
): $ReadOnlyArray<ExtendsPropsShape> {
|
|
500
|
+
return typeDefinition
|
|
501
|
+
.filter(prop => prop.type === 'ObjectTypeSpreadProperty')
|
|
502
|
+
.map(prop => this.extendsForProp(prop, types, this))
|
|
503
|
+
.filter(Boolean);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
getProps(
|
|
507
|
+
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
508
|
+
types: TypeDeclarationMap,
|
|
509
|
+
): {
|
|
510
|
+
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
511
|
+
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
512
|
+
} {
|
|
513
|
+
const nonExtendsProps = this.removeKnownExtends(typeDefinition, types);
|
|
514
|
+
const props = flattenProperties(nonExtendsProps, types, this)
|
|
515
|
+
.map(property => buildPropSchema(property, types, this))
|
|
516
|
+
.filter(Boolean);
|
|
517
|
+
|
|
518
|
+
return {
|
|
519
|
+
props,
|
|
520
|
+
extendsProps: this.getExtendsProps(typeDefinition, types),
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
getProperties(typeName: string, types: TypeDeclarationMap): $FlowFixMe {
|
|
525
|
+
const typeAlias = types[typeName];
|
|
526
|
+
try {
|
|
527
|
+
return typeAlias.right.typeParameters.params[0].properties;
|
|
528
|
+
} catch (e) {
|
|
529
|
+
throw new Error(
|
|
530
|
+
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
320
534
|
}
|
|
321
535
|
|
|
322
536
|
module.exports = {
|
|
@@ -10,68 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
14
|
-
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
function resolveTypeAnnotation(
|
|
17
|
-
// TODO(T71778680): This is an Flow TypeAnnotation. Flow-type this
|
|
18
|
-
typeAnnotation,
|
|
19
|
-
types,
|
|
20
|
-
) {
|
|
21
|
-
invariant(
|
|
22
|
-
typeAnnotation != null,
|
|
23
|
-
'resolveTypeAnnotation(): typeAnnotation cannot be null',
|
|
24
|
-
);
|
|
25
|
-
let node = typeAnnotation;
|
|
26
|
-
let nullable = false;
|
|
27
|
-
let typeResolutionStatus = {
|
|
28
|
-
successful: false,
|
|
29
|
-
};
|
|
30
|
-
for (;;) {
|
|
31
|
-
if (node.type === 'NullableTypeAnnotation') {
|
|
32
|
-
nullable = true;
|
|
33
|
-
node = node.typeAnnotation;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (node.type !== 'GenericTypeAnnotation') {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
const resolvedTypeAnnotation = types[node.id.name];
|
|
40
|
-
if (resolvedTypeAnnotation == null) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
switch (resolvedTypeAnnotation.type) {
|
|
44
|
-
case 'TypeAlias': {
|
|
45
|
-
typeResolutionStatus = {
|
|
46
|
-
successful: true,
|
|
47
|
-
type: 'alias',
|
|
48
|
-
name: node.id.name,
|
|
49
|
-
};
|
|
50
|
-
node = resolvedTypeAnnotation.right;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case 'EnumDeclaration': {
|
|
54
|
-
typeResolutionStatus = {
|
|
55
|
-
successful: true,
|
|
56
|
-
type: 'enum',
|
|
57
|
-
name: node.id.name,
|
|
58
|
-
};
|
|
59
|
-
node = resolvedTypeAnnotation.body;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
default: {
|
|
63
|
-
throw new TypeError(
|
|
64
|
-
`A non GenericTypeAnnotation must be a type declaration ('TypeAlias') or enum ('EnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
nullable: nullable,
|
|
71
|
-
typeAnnotation: node,
|
|
72
|
-
typeResolutionStatus,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
13
|
function getValueFromTypes(value, types) {
|
|
76
14
|
if (value.type === 'GenericTypeAnnotation' && types[value.id.name]) {
|
|
77
15
|
return getValueFromTypes(types[value.id.name].right, types);
|
|
@@ -80,5 +18,4 @@ function getValueFromTypes(value, types) {
|
|
|
80
18
|
}
|
|
81
19
|
module.exports = {
|
|
82
20
|
getValueFromTypes,
|
|
83
|
-
resolveTypeAnnotation,
|
|
84
21
|
};
|
|
@@ -10,82 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
16
|
-
export type ASTNode = Object;
|
|
17
|
-
|
|
18
|
-
const invariant = require('invariant');
|
|
19
|
-
|
|
20
|
-
function resolveTypeAnnotation(
|
|
21
|
-
// TODO(T71778680): This is an Flow TypeAnnotation. Flow-type this
|
|
22
|
-
typeAnnotation: $FlowFixMe,
|
|
23
|
-
types: TypeDeclarationMap,
|
|
24
|
-
): {
|
|
25
|
-
nullable: boolean,
|
|
26
|
-
typeAnnotation: $FlowFixMe,
|
|
27
|
-
typeResolutionStatus: TypeResolutionStatus,
|
|
28
|
-
} {
|
|
29
|
-
invariant(
|
|
30
|
-
typeAnnotation != null,
|
|
31
|
-
'resolveTypeAnnotation(): typeAnnotation cannot be null',
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
let node = typeAnnotation;
|
|
35
|
-
let nullable = false;
|
|
36
|
-
let typeResolutionStatus: TypeResolutionStatus = {
|
|
37
|
-
successful: false,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
for (;;) {
|
|
41
|
-
if (node.type === 'NullableTypeAnnotation') {
|
|
42
|
-
nullable = true;
|
|
43
|
-
node = node.typeAnnotation;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (node.type !== 'GenericTypeAnnotation') {
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const resolvedTypeAnnotation = types[node.id.name];
|
|
52
|
-
if (resolvedTypeAnnotation == null) {
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
switch (resolvedTypeAnnotation.type) {
|
|
57
|
-
case 'TypeAlias': {
|
|
58
|
-
typeResolutionStatus = {
|
|
59
|
-
successful: true,
|
|
60
|
-
type: 'alias',
|
|
61
|
-
name: node.id.name,
|
|
62
|
-
};
|
|
63
|
-
node = resolvedTypeAnnotation.right;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'EnumDeclaration': {
|
|
67
|
-
typeResolutionStatus = {
|
|
68
|
-
successful: true,
|
|
69
|
-
type: 'enum',
|
|
70
|
-
name: node.id.name,
|
|
71
|
-
};
|
|
72
|
-
node = resolvedTypeAnnotation.body;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
default: {
|
|
76
|
-
throw new TypeError(
|
|
77
|
-
`A non GenericTypeAnnotation must be a type declaration ('TypeAlias') or enum ('EnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
nullable: nullable,
|
|
85
|
-
typeAnnotation: node,
|
|
86
|
-
typeResolutionStatus,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
13
|
+
import type {TypeDeclarationMap, ASTNode} from '../utils';
|
|
89
14
|
|
|
90
15
|
function getValueFromTypes(value: ASTNode, types: TypeDeclarationMap): ASTNode {
|
|
91
16
|
if (value.type === 'GenericTypeAnnotation' && types[value.id.name]) {
|
|
@@ -96,5 +21,4 @@ function getValueFromTypes(value: ASTNode, types: TypeDeclarationMap): ASTNode {
|
|
|
96
21
|
|
|
97
22
|
module.exports = {
|
|
98
23
|
getValueFromTypes,
|
|
99
|
-
resolveTypeAnnotation,
|
|
100
24
|
};
|
|
@@ -20,9 +20,60 @@ import type {
|
|
|
20
20
|
NativeModuleEnumMembers,
|
|
21
21
|
NativeModuleAliasMap,
|
|
22
22
|
NativeModuleEnumMap,
|
|
23
|
+
PropTypeAnnotation,
|
|
24
|
+
ExtendsPropsShape,
|
|
23
25
|
} from '../CodegenSchema';
|
|
24
26
|
import type {ParserType} from './errors';
|
|
25
|
-
import type {
|
|
27
|
+
import type {
|
|
28
|
+
ParserErrorCapturer,
|
|
29
|
+
TypeDeclarationMap,
|
|
30
|
+
PropAST,
|
|
31
|
+
ASTNode,
|
|
32
|
+
TypeResolutionStatus,
|
|
33
|
+
} from './utils';
|
|
34
|
+
|
|
35
|
+
export type GetTypeAnnotationFN = (
|
|
36
|
+
name: string,
|
|
37
|
+
annotation: $FlowFixMe | ASTNode,
|
|
38
|
+
defaultValue: $FlowFixMe | void,
|
|
39
|
+
withNullDefault: boolean,
|
|
40
|
+
types: TypeDeclarationMap,
|
|
41
|
+
parser: Parser,
|
|
42
|
+
buildSchema: (
|
|
43
|
+
property: PropAST,
|
|
44
|
+
types: TypeDeclarationMap,
|
|
45
|
+
parser: Parser,
|
|
46
|
+
) => $FlowFixMe,
|
|
47
|
+
) => $FlowFixMe;
|
|
48
|
+
|
|
49
|
+
export type SchemaInfo = {
|
|
50
|
+
name: string,
|
|
51
|
+
optional: boolean,
|
|
52
|
+
typeAnnotation: $FlowFixMe,
|
|
53
|
+
defaultValue: $FlowFixMe,
|
|
54
|
+
withNullDefault: boolean,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type GetSchemaInfoFN = (
|
|
58
|
+
property: PropAST,
|
|
59
|
+
types: TypeDeclarationMap,
|
|
60
|
+
) => ?SchemaInfo;
|
|
61
|
+
|
|
62
|
+
export type BuildSchemaFN<T> = (
|
|
63
|
+
property: PropAST,
|
|
64
|
+
types: TypeDeclarationMap,
|
|
65
|
+
parser: Parser,
|
|
66
|
+
) => ?NamedShape<T>;
|
|
67
|
+
|
|
68
|
+
export type ResolveTypeAnnotationFN = (
|
|
69
|
+
typeAnnotation: $FlowFixMe,
|
|
70
|
+
types: TypeDeclarationMap,
|
|
71
|
+
parser: Parser,
|
|
72
|
+
) => {
|
|
73
|
+
nullable: boolean,
|
|
74
|
+
typeAnnotation: $FlowFixMe,
|
|
75
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
76
|
+
};
|
|
26
77
|
|
|
27
78
|
/**
|
|
28
79
|
* This is the main interface for Parsers of various languages.
|
|
@@ -34,6 +85,31 @@ export interface Parser {
|
|
|
34
85
|
*/
|
|
35
86
|
typeParameterInstantiation: string;
|
|
36
87
|
|
|
88
|
+
/**
|
|
89
|
+
* TypeAlias property of the Parser
|
|
90
|
+
*/
|
|
91
|
+
typeAlias: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* enumDeclaration Property of the Parser
|
|
95
|
+
*/
|
|
96
|
+
enumDeclaration: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* InterfaceDeclaration property of the Parser
|
|
100
|
+
*/
|
|
101
|
+
interfaceDeclaration: string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* This is the NullLiteralTypeAnnotation value
|
|
105
|
+
*/
|
|
106
|
+
nullLiteralTypeAnnotation: string;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* UndefinedLiteralTypeAnnotation property of the Parser
|
|
110
|
+
*/
|
|
111
|
+
undefinedLiteralTypeAnnotation: string;
|
|
112
|
+
|
|
37
113
|
/**
|
|
38
114
|
* Given a declaration, it returns true if it is a property
|
|
39
115
|
*/
|
|
@@ -161,6 +237,11 @@ export interface Parser {
|
|
|
161
237
|
*/
|
|
162
238
|
isModuleInterface(node: $FlowFixMe): boolean;
|
|
163
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Given a type name, it returns true if it is a generic type annotation
|
|
242
|
+
*/
|
|
243
|
+
isGenericTypeAnnotation(type: $FlowFixMe): boolean;
|
|
244
|
+
|
|
164
245
|
/**
|
|
165
246
|
* Given a typeAnnotation, it returns the annotated element.
|
|
166
247
|
* @parameter typeAnnotation: the annotation for a type.
|
|
@@ -236,4 +317,65 @@ export interface Parser {
|
|
|
236
317
|
* @returns: the properties of annotated element.
|
|
237
318
|
*/
|
|
238
319
|
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Given a typeAlias, it returns an array of properties.
|
|
323
|
+
* @parameter typeAlias: the type alias.
|
|
324
|
+
* @returns: an array of properties.
|
|
325
|
+
*/
|
|
326
|
+
bodyProperties(typeAlias: $FlowFixMe): $ReadOnlyArray<$FlowFixMe>;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Given a keyword convert it to TypeAnnotation.
|
|
330
|
+
* @parameter keyword
|
|
331
|
+
* @returns: converted TypeAnnotation to Keywords
|
|
332
|
+
*/
|
|
333
|
+
convertKeywordToTypeAnnotation(keyword: string): string;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Given a prop return its arguments.
|
|
337
|
+
* @parameter prop
|
|
338
|
+
* @returns: Arguments of the prop
|
|
339
|
+
*/
|
|
340
|
+
argumentForProp(prop: PropAST): $FlowFixMe;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Given a prop return its name.
|
|
344
|
+
* @parameter prop
|
|
345
|
+
* @returns: name property
|
|
346
|
+
*/
|
|
347
|
+
nameForArgument(prop: PropAST): $FlowFixMe;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Given a property return if it is optional.
|
|
351
|
+
* @parameter property
|
|
352
|
+
* @returns: a boolean specifying if the Property is optional
|
|
353
|
+
*/
|
|
354
|
+
isOptionalProperty(property: $FlowFixMe): boolean;
|
|
355
|
+
|
|
356
|
+
getGetTypeAnnotationFN(): GetTypeAnnotationFN;
|
|
357
|
+
|
|
358
|
+
getGetSchemaInfoFN(): GetSchemaInfoFN;
|
|
359
|
+
|
|
360
|
+
getResolvedTypeAnnotation(
|
|
361
|
+
typeAnnotation: $FlowFixMe,
|
|
362
|
+
types: TypeDeclarationMap,
|
|
363
|
+
parser: Parser,
|
|
364
|
+
): {
|
|
365
|
+
nullable: boolean,
|
|
366
|
+
typeAnnotation: $FlowFixMe,
|
|
367
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
getResolveTypeAnnotationFN(): ResolveTypeAnnotationFN;
|
|
371
|
+
|
|
372
|
+
getProps(
|
|
373
|
+
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
374
|
+
types: TypeDeclarationMap,
|
|
375
|
+
): {
|
|
376
|
+
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
377
|
+
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
getProperties(typeName: string, types: TypeDeclarationMap): $FlowFixMe;
|
|
239
381
|
}
|