@react-native/codegen 0.73.0 → 0.74.0-nightly-20231003-5dedf277c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/CodegenSchema.d.ts +15 -4
- package/lib/CodegenSchema.js.flow +33 -21
- package/lib/cli/combine/combine-js-to-schema-cli.js +7 -1
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +7 -1
- package/lib/generators/components/CppHelpers.js +39 -2
- package/lib/generators/components/CppHelpers.js.flow +54 -5
- package/lib/generators/components/GenerateEventEmitterCpp.js +222 -28
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +221 -34
- package/lib/generators/components/GenerateEventEmitterH.js +77 -26
- package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -30
- package/lib/generators/components/GeneratePropsH.js +2 -3
- package/lib/generators/components/GeneratePropsH.js.flow +2 -3
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
- package/lib/generators/modules/GenerateModuleCpp.js +1 -1
- package/lib/generators/modules/GenerateModuleCpp.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleH.js +44 -39
- package/lib/generators/modules/GenerateModuleH.js.flow +51 -39
- package/lib/generators/modules/GenerateModuleJavaSpec.js +9 -7
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +10 -6
- package/lib/generators/modules/GenerateModuleJniH.js +1 -1
- package/lib/generators/modules/GenerateModuleJniH.js.flow +1 -1
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +11 -3
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +13 -3
- package/lib/parsers/error-utils.js +44 -0
- package/lib/parsers/error-utils.js.flow +59 -0
- package/lib/parsers/errors.js +3 -9
- package/lib/parsers/errors.js.flow +3 -9
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/flow/components/componentsUtils.js +22 -33
- package/lib/parsers/flow/components/componentsUtils.js.flow +24 -45
- package/lib/parsers/flow/components/events.js +151 -128
- package/lib/parsers/flow/components/events.js.flow +161 -136
- package/lib/parsers/flow/components/index.js +13 -94
- package/lib/parsers/flow/components/index.js.flow +5 -102
- package/lib/parsers/flow/modules/index.js +24 -24
- package/lib/parsers/flow/modules/index.js.flow +6 -6
- package/lib/parsers/flow/parser.d.ts +9 -2
- package/lib/parsers/flow/parser.js +179 -18
- package/lib/parsers/flow/parser.js.flow +231 -7
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +176 -3
- package/lib/parsers/parserMock.js +202 -4
- package/lib/parsers/parserMock.js.flow +253 -4
- package/lib/parsers/parsers-commons.js +268 -10
- package/lib/parsers/parsers-commons.js.flow +365 -12
- package/lib/parsers/parsers-primitives.js +95 -1
- package/lib/parsers/parsers-primitives.js.flow +136 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
- package/lib/parsers/typescript/components/componentsUtils.js +49 -57
- package/lib/parsers/typescript/components/componentsUtils.js.flow +48 -66
- package/lib/parsers/typescript/components/events.js +136 -115
- package/lib/parsers/typescript/components/events.js.flow +148 -119
- package/lib/parsers/typescript/components/extends.js +2 -49
- package/lib/parsers/typescript/components/extends.js.flow +1 -55
- package/lib/parsers/typescript/components/index.js +14 -99
- package/lib/parsers/typescript/components/index.js.flow +6 -106
- package/lib/parsers/typescript/modules/index.js +28 -26
- package/lib/parsers/typescript/modules/index.js.flow +9 -8
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +208 -14
- package/lib/parsers/typescript/parser.js.flow +247 -8
- package/lib/parsers/utils.js.flow +6 -0
- package/package.json +27 -16
- package/lib/parsers/flow/components/extends.js +0 -52
- package/lib/parsers/flow/components/extends.js.flow +0 -66
- package/lib/parsers/flow/components/props.js +0 -47
- package/lib/parsers/flow/components/props.js.flow +0 -60
- package/lib/parsers/typescript/components/props.js +0 -39
- package/lib/parsers/typescript/components/props.js.flow +0 -48
- package/lib/parsers/typescript/utils.js +0 -90
- package/lib/parsers/typescript/utils.js.flow +0 -104
|
@@ -23,11 +23,20 @@ import type {
|
|
|
23
23
|
SchemaType,
|
|
24
24
|
NativeModuleEnumMap,
|
|
25
25
|
OptionsShape,
|
|
26
|
+
PropTypeAnnotation,
|
|
27
|
+
EventTypeAnnotation,
|
|
28
|
+
ObjectTypeAnnotation,
|
|
29
|
+
EventTypeShape,
|
|
26
30
|
} from '../CodegenSchema.js';
|
|
27
31
|
|
|
28
32
|
import type {Parser} from './parser';
|
|
29
33
|
import type {ParserType} from './errors';
|
|
30
|
-
import type {
|
|
34
|
+
import type {
|
|
35
|
+
ParserErrorCapturer,
|
|
36
|
+
TypeDeclarationMap,
|
|
37
|
+
PropAST,
|
|
38
|
+
TypeResolutionStatus,
|
|
39
|
+
} from './utils';
|
|
31
40
|
import type {ComponentSchemaBuilderConfig} from './schema.js';
|
|
32
41
|
|
|
33
42
|
const {
|
|
@@ -38,6 +47,7 @@ const {
|
|
|
38
47
|
isModuleRegistryCall,
|
|
39
48
|
verifyPlatforms,
|
|
40
49
|
} = require('./utils');
|
|
50
|
+
|
|
41
51
|
const {
|
|
42
52
|
throwIfPropertyValueTypeIsUnsupported,
|
|
43
53
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
@@ -52,6 +62,10 @@ const {
|
|
|
52
62
|
throwIfModuleInterfaceNotFound,
|
|
53
63
|
throwIfMoreThanOneModuleInterfaceParserError,
|
|
54
64
|
throwIfModuleInterfaceIsMisnamed,
|
|
65
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
66
|
+
throwIfConfigNotfound,
|
|
67
|
+
throwIfMoreThanOneConfig,
|
|
68
|
+
throwIfTypeAliasIsNotInterface,
|
|
55
69
|
} = require('./error-utils');
|
|
56
70
|
|
|
57
71
|
const {
|
|
@@ -69,6 +83,17 @@ export type CommandOptions = $ReadOnly<{
|
|
|
69
83
|
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
70
84
|
type OptionsAST = Object;
|
|
71
85
|
|
|
86
|
+
type ExtendedPropResult = {
|
|
87
|
+
type: 'ReactNativeBuiltInType',
|
|
88
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
89
|
+
} | null;
|
|
90
|
+
|
|
91
|
+
export type EventArgumentReturnType = {
|
|
92
|
+
argumentProps: ?$ReadOnlyArray<$FlowFixMe>,
|
|
93
|
+
paperTopLevelNameDeprecated: ?$FlowFixMe,
|
|
94
|
+
bubblingType: ?'direct' | 'bubble',
|
|
95
|
+
};
|
|
96
|
+
|
|
72
97
|
function wrapModuleSchema(
|
|
73
98
|
nativeModuleSchema: NativeModuleSchema,
|
|
74
99
|
hasteModuleName: string,
|
|
@@ -80,6 +105,7 @@ function wrapModuleSchema(
|
|
|
80
105
|
};
|
|
81
106
|
}
|
|
82
107
|
|
|
108
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
83
109
|
function unwrapNullable<+T: NativeModuleTypeAnnotation>(
|
|
84
110
|
x: Nullable<T>,
|
|
85
111
|
): [T, boolean] {
|
|
@@ -90,6 +116,7 @@ function unwrapNullable<+T: NativeModuleTypeAnnotation>(
|
|
|
90
116
|
return [x, false];
|
|
91
117
|
}
|
|
92
118
|
|
|
119
|
+
// $FlowFixMe[unsupported-variance-annotation]
|
|
93
120
|
function wrapNullable<+T: NativeModuleTypeAnnotation>(
|
|
94
121
|
nullable: boolean,
|
|
95
122
|
typeAnnotation: T,
|
|
@@ -314,7 +341,6 @@ function buildPropertySchema(
|
|
|
314
341
|
enumMap: {...NativeModuleEnumMap},
|
|
315
342
|
tryParse: ParserErrorCapturer,
|
|
316
343
|
cxxOnly: boolean,
|
|
317
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
318
344
|
translateTypeAnnotation: $FlowFixMe,
|
|
319
345
|
parser: Parser,
|
|
320
346
|
): NativeModulePropertyShape {
|
|
@@ -329,7 +355,12 @@ function buildPropertySchema(
|
|
|
329
355
|
: property.typeAnnotation;
|
|
330
356
|
}
|
|
331
357
|
|
|
332
|
-
|
|
358
|
+
const resolveTypeAnnotationFN = parser.getResolveTypeAnnotationFN();
|
|
359
|
+
({nullable, typeAnnotation: value} = resolveTypeAnnotationFN(
|
|
360
|
+
value,
|
|
361
|
+
types,
|
|
362
|
+
parser,
|
|
363
|
+
));
|
|
333
364
|
|
|
334
365
|
throwIfModuleTypeIsUnsupported(
|
|
335
366
|
hasteModuleName,
|
|
@@ -373,11 +404,9 @@ function buildSchemaFromConfigType(
|
|
|
373
404
|
ast: $FlowFixMe,
|
|
374
405
|
tryParse: ParserErrorCapturer,
|
|
375
406
|
parser: Parser,
|
|
376
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
377
407
|
translateTypeAnnotation: $FlowFixMe,
|
|
378
408
|
) => NativeModuleSchema,
|
|
379
409
|
parser: Parser,
|
|
380
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
381
410
|
translateTypeAnnotation: $FlowFixMe,
|
|
382
411
|
): SchemaType {
|
|
383
412
|
switch (configType) {
|
|
@@ -398,7 +427,6 @@ function buildSchemaFromConfigType(
|
|
|
398
427
|
ast,
|
|
399
428
|
tryParse,
|
|
400
429
|
parser,
|
|
401
|
-
resolveTypeAnnotation,
|
|
402
430
|
translateTypeAnnotation,
|
|
403
431
|
),
|
|
404
432
|
);
|
|
@@ -440,14 +468,12 @@ function buildSchema(
|
|
|
440
468
|
ast: $FlowFixMe,
|
|
441
469
|
tryParse: ParserErrorCapturer,
|
|
442
470
|
parser: Parser,
|
|
443
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
444
471
|
translateTypeAnnotation: $FlowFixMe,
|
|
445
472
|
) => NativeModuleSchema,
|
|
446
473
|
Visitor: ({isComponent: boolean, isModule: boolean}) => {
|
|
447
474
|
[type: string]: (node: $FlowFixMe) => void,
|
|
448
475
|
},
|
|
449
476
|
parser: Parser,
|
|
450
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
451
477
|
translateTypeAnnotation: $FlowFixMe,
|
|
452
478
|
): SchemaType {
|
|
453
479
|
// Early return for non-Spec JavaScript files
|
|
@@ -469,7 +495,6 @@ function buildSchema(
|
|
|
469
495
|
buildComponentSchema,
|
|
470
496
|
buildModuleSchema,
|
|
471
497
|
parser,
|
|
472
|
-
resolveTypeAnnotation,
|
|
473
498
|
translateTypeAnnotation,
|
|
474
499
|
);
|
|
475
500
|
}
|
|
@@ -564,7 +589,6 @@ const buildModuleSchema = (
|
|
|
564
589
|
ast: $FlowFixMe,
|
|
565
590
|
tryParse: ParserErrorCapturer,
|
|
566
591
|
parser: Parser,
|
|
567
|
-
resolveTypeAnnotation: $FlowFixMe,
|
|
568
592
|
translateTypeAnnotation: $FlowFixMe,
|
|
569
593
|
): NativeModuleSchema => {
|
|
570
594
|
const language = parser.language();
|
|
@@ -632,7 +656,6 @@ const buildModuleSchema = (
|
|
|
632
656
|
enumMap,
|
|
633
657
|
tryParse,
|
|
634
658
|
cxxOnly,
|
|
635
|
-
resolveTypeAnnotation,
|
|
636
659
|
translateTypeAnnotation,
|
|
637
660
|
parser,
|
|
638
661
|
),
|
|
@@ -804,7 +827,7 @@ function getCommandTypeNameAndOptionsExpression(
|
|
|
804
827
|
}
|
|
805
828
|
|
|
806
829
|
return {
|
|
807
|
-
commandTypeName: parser.
|
|
830
|
+
commandTypeName: parser.getTypeAnnotationName(typeArgumentParam),
|
|
808
831
|
commandOptionsExpression: callExpression.arguments[0],
|
|
809
832
|
};
|
|
810
833
|
}
|
|
@@ -817,6 +840,325 @@ function propertyNames(
|
|
|
817
840
|
.filter(Boolean);
|
|
818
841
|
}
|
|
819
842
|
|
|
843
|
+
function extendsForProp(
|
|
844
|
+
prop: PropAST,
|
|
845
|
+
types: TypeDeclarationMap,
|
|
846
|
+
parser: Parser,
|
|
847
|
+
): ExtendedPropResult {
|
|
848
|
+
const argument = parser.argumentForProp(prop);
|
|
849
|
+
|
|
850
|
+
if (!argument) {
|
|
851
|
+
console.log('null', prop);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const name = parser.nameForArgument(prop);
|
|
855
|
+
|
|
856
|
+
if (types[name] != null) {
|
|
857
|
+
// This type is locally defined in the file
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
switch (name) {
|
|
862
|
+
case 'ViewProps':
|
|
863
|
+
return {
|
|
864
|
+
type: 'ReactNativeBuiltInType',
|
|
865
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
866
|
+
};
|
|
867
|
+
default: {
|
|
868
|
+
throw new Error(`Unable to handle prop spread: ${name}`);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function buildPropSchema(
|
|
874
|
+
property: PropAST,
|
|
875
|
+
types: TypeDeclarationMap,
|
|
876
|
+
parser: Parser,
|
|
877
|
+
): ?NamedShape<PropTypeAnnotation> {
|
|
878
|
+
const getSchemaInfoFN = parser.getGetSchemaInfoFN();
|
|
879
|
+
const info = getSchemaInfoFN(property, types);
|
|
880
|
+
if (info == null) {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
const {name, optional, typeAnnotation, defaultValue, withNullDefault} = info;
|
|
884
|
+
|
|
885
|
+
const getTypeAnnotationFN = parser.getGetTypeAnnotationFN();
|
|
886
|
+
|
|
887
|
+
return {
|
|
888
|
+
name,
|
|
889
|
+
optional,
|
|
890
|
+
typeAnnotation: getTypeAnnotationFN(
|
|
891
|
+
name,
|
|
892
|
+
typeAnnotation,
|
|
893
|
+
defaultValue,
|
|
894
|
+
withNullDefault,
|
|
895
|
+
types,
|
|
896
|
+
parser,
|
|
897
|
+
buildPropSchema,
|
|
898
|
+
),
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
903
|
+
* LTI update could not be added via codemod */
|
|
904
|
+
function getEventArgument(
|
|
905
|
+
argumentProps: PropAST,
|
|
906
|
+
parser: Parser,
|
|
907
|
+
getPropertyType: (
|
|
908
|
+
name: $FlowFixMe,
|
|
909
|
+
optional: boolean,
|
|
910
|
+
typeAnnotation: $FlowFixMe,
|
|
911
|
+
parser: Parser,
|
|
912
|
+
) => NamedShape<EventTypeAnnotation>,
|
|
913
|
+
): ObjectTypeAnnotation<EventTypeAnnotation> {
|
|
914
|
+
return {
|
|
915
|
+
type: 'ObjectTypeAnnotation',
|
|
916
|
+
properties: argumentProps.map(member =>
|
|
917
|
+
buildPropertiesForEvent(member, parser, getPropertyType),
|
|
918
|
+
),
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/* $FlowFixMe[signature-verification-failure] there's no flowtype for AST.
|
|
923
|
+
* TODO(T108222691): Use flow-types for @babel/parser */
|
|
924
|
+
function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
|
|
925
|
+
const foundConfigs: Array<{[string]: string}> = [];
|
|
926
|
+
|
|
927
|
+
const defaultExports = ast.body.filter(
|
|
928
|
+
node => node.type === 'ExportDefaultDeclaration',
|
|
929
|
+
);
|
|
930
|
+
|
|
931
|
+
defaultExports.forEach(statement => {
|
|
932
|
+
findNativeComponentType(statement, foundConfigs, parser);
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
throwIfConfigNotfound(foundConfigs);
|
|
936
|
+
throwIfMoreThanOneConfig(foundConfigs);
|
|
937
|
+
|
|
938
|
+
const foundConfig = foundConfigs[0];
|
|
939
|
+
|
|
940
|
+
const namedExports = ast.body.filter(
|
|
941
|
+
node => node.type === 'ExportNamedDeclaration',
|
|
942
|
+
);
|
|
943
|
+
|
|
944
|
+
const commandsTypeNames = namedExports
|
|
945
|
+
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
946
|
+
.filter(Boolean);
|
|
947
|
+
|
|
948
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
949
|
+
|
|
950
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
|
|
954
|
+
function getCommandProperties(ast: $FlowFixMe, parser: Parser) {
|
|
955
|
+
const {commandTypeName, commandOptionsExpression} = findComponentConfig(
|
|
956
|
+
ast,
|
|
957
|
+
parser,
|
|
958
|
+
);
|
|
959
|
+
|
|
960
|
+
if (commandTypeName == null) {
|
|
961
|
+
return [];
|
|
962
|
+
}
|
|
963
|
+
const types = parser.getTypes(ast);
|
|
964
|
+
|
|
965
|
+
const typeAlias = types[commandTypeName];
|
|
966
|
+
|
|
967
|
+
throwIfTypeAliasIsNotInterface(typeAlias, parser);
|
|
968
|
+
|
|
969
|
+
const properties = parser.bodyProperties(typeAlias);
|
|
970
|
+
if (!properties) {
|
|
971
|
+
throw new Error(
|
|
972
|
+
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen file`,
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const commandPropertyNames = propertyNames(properties);
|
|
977
|
+
|
|
978
|
+
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
979
|
+
|
|
980
|
+
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
981
|
+
throw new Error(
|
|
982
|
+
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
if (
|
|
987
|
+
commandOptions.supportedCommands.length !== commandPropertyNames.length ||
|
|
988
|
+
!commandOptions.supportedCommands.every(supportedCommand =>
|
|
989
|
+
commandPropertyNames.includes(supportedCommand),
|
|
990
|
+
)
|
|
991
|
+
) {
|
|
992
|
+
throw new Error(
|
|
993
|
+
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${commandPropertyNames.join(
|
|
994
|
+
', ',
|
|
995
|
+
)}`,
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
return properties;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function getTypeResolutionStatus(
|
|
1003
|
+
type: 'alias' | 'enum',
|
|
1004
|
+
typeAnnotation: $FlowFixMe,
|
|
1005
|
+
parser: Parser,
|
|
1006
|
+
): TypeResolutionStatus {
|
|
1007
|
+
return {
|
|
1008
|
+
successful: true,
|
|
1009
|
+
type,
|
|
1010
|
+
name: parser.getTypeAnnotationName(typeAnnotation),
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function handleGenericTypeAnnotation(
|
|
1015
|
+
typeAnnotation: $FlowFixMe,
|
|
1016
|
+
resolvedTypeAnnotation: TypeDeclarationMap,
|
|
1017
|
+
parser: Parser,
|
|
1018
|
+
): {
|
|
1019
|
+
typeAnnotation: $FlowFixMe,
|
|
1020
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
1021
|
+
} {
|
|
1022
|
+
let typeResolutionStatus;
|
|
1023
|
+
let node;
|
|
1024
|
+
|
|
1025
|
+
switch (resolvedTypeAnnotation.type) {
|
|
1026
|
+
case parser.typeAlias: {
|
|
1027
|
+
typeResolutionStatus = getTypeResolutionStatus(
|
|
1028
|
+
'alias',
|
|
1029
|
+
typeAnnotation,
|
|
1030
|
+
parser,
|
|
1031
|
+
);
|
|
1032
|
+
node = parser.nextNodeForTypeAlias(resolvedTypeAnnotation);
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
case parser.enumDeclaration: {
|
|
1036
|
+
typeResolutionStatus = getTypeResolutionStatus(
|
|
1037
|
+
'enum',
|
|
1038
|
+
typeAnnotation,
|
|
1039
|
+
parser,
|
|
1040
|
+
);
|
|
1041
|
+
node = parser.nextNodeForEnum(resolvedTypeAnnotation);
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
// parser.interfaceDeclaration is not used here because for flow it should fall through to default case and throw an error
|
|
1045
|
+
case 'TSInterfaceDeclaration': {
|
|
1046
|
+
typeResolutionStatus = getTypeResolutionStatus(
|
|
1047
|
+
'alias',
|
|
1048
|
+
typeAnnotation,
|
|
1049
|
+
parser,
|
|
1050
|
+
);
|
|
1051
|
+
node = resolvedTypeAnnotation;
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
default: {
|
|
1055
|
+
throw new TypeError(
|
|
1056
|
+
parser.genericTypeAnnotationErrorMessage(resolvedTypeAnnotation),
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
return {
|
|
1062
|
+
typeAnnotation: node,
|
|
1063
|
+
typeResolutionStatus,
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function buildPropertiesForEvent(
|
|
1068
|
+
property: $FlowFixMe,
|
|
1069
|
+
parser: Parser,
|
|
1070
|
+
getPropertyType: (
|
|
1071
|
+
name: $FlowFixMe,
|
|
1072
|
+
optional: boolean,
|
|
1073
|
+
typeAnnotation: $FlowFixMe,
|
|
1074
|
+
parser: Parser,
|
|
1075
|
+
) => NamedShape<EventTypeAnnotation>,
|
|
1076
|
+
): NamedShape<EventTypeAnnotation> {
|
|
1077
|
+
const name = property.key.name;
|
|
1078
|
+
const optional = parser.isOptionalProperty(property);
|
|
1079
|
+
const typeAnnotation = parser.getTypeAnnotationFromProperty(property);
|
|
1080
|
+
|
|
1081
|
+
return getPropertyType(name, optional, typeAnnotation, parser);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function verifyPropNotAlreadyDefined(
|
|
1085
|
+
props: $ReadOnlyArray<PropAST>,
|
|
1086
|
+
needleProp: PropAST,
|
|
1087
|
+
) {
|
|
1088
|
+
const propName = needleProp.key.name;
|
|
1089
|
+
const foundProp = props.some(prop => prop.key.name === propName);
|
|
1090
|
+
if (foundProp) {
|
|
1091
|
+
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function handleEventHandler(
|
|
1096
|
+
name: 'BubblingEventHandler' | 'DirectEventHandler',
|
|
1097
|
+
typeAnnotation: $FlowFixMe,
|
|
1098
|
+
parser: Parser,
|
|
1099
|
+
types: TypeDeclarationMap,
|
|
1100
|
+
findEventArgumentsAndType: (
|
|
1101
|
+
parser: Parser,
|
|
1102
|
+
typeAnnotation: $FlowFixMe,
|
|
1103
|
+
types: TypeDeclarationMap,
|
|
1104
|
+
bubblingType: void | 'direct' | 'bubble',
|
|
1105
|
+
paperName: ?$FlowFixMe,
|
|
1106
|
+
) => EventArgumentReturnType,
|
|
1107
|
+
): EventArgumentReturnType {
|
|
1108
|
+
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
|
|
1109
|
+
const paperTopLevelNameDeprecated =
|
|
1110
|
+
parser.getPaperTopLevelNameDeprecated(typeAnnotation);
|
|
1111
|
+
|
|
1112
|
+
switch (typeAnnotation.typeParameters.params[0].type) {
|
|
1113
|
+
case parser.nullLiteralTypeAnnotation:
|
|
1114
|
+
case parser.undefinedLiteralTypeAnnotation:
|
|
1115
|
+
return {
|
|
1116
|
+
argumentProps: [],
|
|
1117
|
+
bubblingType: eventType,
|
|
1118
|
+
paperTopLevelNameDeprecated,
|
|
1119
|
+
};
|
|
1120
|
+
default:
|
|
1121
|
+
return findEventArgumentsAndType(
|
|
1122
|
+
parser,
|
|
1123
|
+
typeAnnotation.typeParameters.params[0],
|
|
1124
|
+
types,
|
|
1125
|
+
eventType,
|
|
1126
|
+
paperTopLevelNameDeprecated,
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function emitBuildEventSchema(
|
|
1132
|
+
paperTopLevelNameDeprecated: $FlowFixMe,
|
|
1133
|
+
name: $FlowFixMe,
|
|
1134
|
+
optional: $FlowFixMe,
|
|
1135
|
+
nonNullableBubblingType: 'direct' | 'bubble',
|
|
1136
|
+
argument: ObjectTypeAnnotation<EventTypeAnnotation>,
|
|
1137
|
+
): ?EventTypeShape {
|
|
1138
|
+
if (paperTopLevelNameDeprecated != null) {
|
|
1139
|
+
return {
|
|
1140
|
+
name,
|
|
1141
|
+
optional,
|
|
1142
|
+
bubblingType: nonNullableBubblingType,
|
|
1143
|
+
paperTopLevelNameDeprecated,
|
|
1144
|
+
typeAnnotation: {
|
|
1145
|
+
type: 'EventTypeAnnotation',
|
|
1146
|
+
argument: argument,
|
|
1147
|
+
},
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
return {
|
|
1152
|
+
name,
|
|
1153
|
+
optional,
|
|
1154
|
+
bubblingType: nonNullableBubblingType,
|
|
1155
|
+
typeAnnotation: {
|
|
1156
|
+
type: 'EventTypeAnnotation',
|
|
1157
|
+
argument: argument,
|
|
1158
|
+
},
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
|
|
820
1162
|
module.exports = {
|
|
821
1163
|
wrapModuleSchema,
|
|
822
1164
|
unwrapNullable,
|
|
@@ -836,4 +1178,15 @@ module.exports = {
|
|
|
836
1178
|
getCommandOptions,
|
|
837
1179
|
getOptions,
|
|
838
1180
|
getCommandTypeNameAndOptionsExpression,
|
|
1181
|
+
extendsForProp,
|
|
1182
|
+
buildPropSchema,
|
|
1183
|
+
getEventArgument,
|
|
1184
|
+
findComponentConfig,
|
|
1185
|
+
getCommandProperties,
|
|
1186
|
+
handleGenericTypeAnnotation,
|
|
1187
|
+
getTypeResolutionStatus,
|
|
1188
|
+
buildPropertiesForEvent,
|
|
1189
|
+
verifyPropNotAlreadyDefined,
|
|
1190
|
+
handleEventHandler,
|
|
1191
|
+
emitBuildEventSchema,
|
|
839
1192
|
};
|
|
@@ -110,6 +110,15 @@ function emitInt32(nullable) {
|
|
|
110
110
|
type: 'Int32TypeAnnotation',
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
+
function emitInt32Prop(name, optional) {
|
|
114
|
+
return {
|
|
115
|
+
name,
|
|
116
|
+
optional,
|
|
117
|
+
typeAnnotation: {
|
|
118
|
+
type: 'Int32TypeAnnotation',
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
113
122
|
function emitNumber(nullable) {
|
|
114
123
|
return wrapNullable(nullable, {
|
|
115
124
|
type: 'NumberTypeAnnotation',
|
|
@@ -126,6 +135,15 @@ function emitDouble(nullable) {
|
|
|
126
135
|
type: 'DoubleTypeAnnotation',
|
|
127
136
|
});
|
|
128
137
|
}
|
|
138
|
+
function emitDoubleProp(name, optional) {
|
|
139
|
+
return {
|
|
140
|
+
name,
|
|
141
|
+
optional,
|
|
142
|
+
typeAnnotation: {
|
|
143
|
+
type: 'DoubleTypeAnnotation',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
129
147
|
function emitVoid(nullable) {
|
|
130
148
|
return wrapNullable(nullable, {
|
|
131
149
|
type: 'VoidTypeAnnotation',
|
|
@@ -171,6 +189,15 @@ function emitString(nullable) {
|
|
|
171
189
|
type: 'StringTypeAnnotation',
|
|
172
190
|
});
|
|
173
191
|
}
|
|
192
|
+
function emitStringProp(name, optional) {
|
|
193
|
+
return {
|
|
194
|
+
name,
|
|
195
|
+
optional,
|
|
196
|
+
typeAnnotation: {
|
|
197
|
+
type: 'StringTypeAnnotation',
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
174
201
|
function typeAliasResolution(
|
|
175
202
|
typeResolution,
|
|
176
203
|
objectTypeAnnotation,
|
|
@@ -315,6 +342,12 @@ function emitGenericObject(nullable) {
|
|
|
315
342
|
type: 'GenericObjectTypeAnnotation',
|
|
316
343
|
});
|
|
317
344
|
}
|
|
345
|
+
function emitDictionary(nullable, valueType) {
|
|
346
|
+
return wrapNullable(nullable, {
|
|
347
|
+
type: 'GenericObjectTypeAnnotation',
|
|
348
|
+
dictionaryValueType: valueType,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
318
351
|
function emitObject(nullable, properties) {
|
|
319
352
|
return wrapNullable(nullable, {
|
|
320
353
|
type: 'ObjectTypeAnnotation',
|
|
@@ -326,6 +359,15 @@ function emitFloat(nullable) {
|
|
|
326
359
|
type: 'FloatTypeAnnotation',
|
|
327
360
|
});
|
|
328
361
|
}
|
|
362
|
+
function emitFloatProp(name, optional) {
|
|
363
|
+
return {
|
|
364
|
+
name,
|
|
365
|
+
optional,
|
|
366
|
+
typeAnnotation: {
|
|
367
|
+
type: 'FloatTypeAnnotation',
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
}
|
|
329
371
|
function emitUnion(nullable, hasteModuleName, typeAnnotation, parser) {
|
|
330
372
|
const unionTypes = parser.remapUnionTypeAnnotationMemberNames(
|
|
331
373
|
typeAnnotation.types,
|
|
@@ -525,7 +567,7 @@ function emitCommonTypes(
|
|
|
525
567
|
return simpleEmitter(nullable);
|
|
526
568
|
}
|
|
527
569
|
const genericTypeAnnotationName =
|
|
528
|
-
parser.
|
|
570
|
+
parser.getTypeAnnotationName(typeAnnotation);
|
|
529
571
|
const emitter = typeMap[genericTypeAnnotationName];
|
|
530
572
|
if (!emitter) {
|
|
531
573
|
return null;
|
|
@@ -542,21 +584,71 @@ function emitCommonTypes(
|
|
|
542
584
|
parser,
|
|
543
585
|
);
|
|
544
586
|
}
|
|
587
|
+
function emitBoolProp(name, optional) {
|
|
588
|
+
return {
|
|
589
|
+
name,
|
|
590
|
+
optional,
|
|
591
|
+
typeAnnotation: {
|
|
592
|
+
type: 'BooleanTypeAnnotation',
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function emitMixedProp(name, optional) {
|
|
597
|
+
return {
|
|
598
|
+
name,
|
|
599
|
+
optional,
|
|
600
|
+
typeAnnotation: {
|
|
601
|
+
type: 'MixedTypeAnnotation',
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function emitObjectProp(
|
|
606
|
+
name,
|
|
607
|
+
optional,
|
|
608
|
+
parser,
|
|
609
|
+
typeAnnotation,
|
|
610
|
+
extractArrayElementType,
|
|
611
|
+
) {
|
|
612
|
+
return {
|
|
613
|
+
name,
|
|
614
|
+
optional,
|
|
615
|
+
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function emitUnionProp(name, optional, parser, typeAnnotation) {
|
|
619
|
+
return {
|
|
620
|
+
name,
|
|
621
|
+
optional,
|
|
622
|
+
typeAnnotation: {
|
|
623
|
+
type: 'StringEnumTypeAnnotation',
|
|
624
|
+
options: typeAnnotation.types.map(option =>
|
|
625
|
+
parser.getLiteralValue(option),
|
|
626
|
+
),
|
|
627
|
+
},
|
|
628
|
+
};
|
|
629
|
+
}
|
|
545
630
|
module.exports = {
|
|
546
631
|
emitArrayType,
|
|
547
632
|
emitBoolean,
|
|
633
|
+
emitBoolProp,
|
|
548
634
|
emitDouble,
|
|
635
|
+
emitDoubleProp,
|
|
549
636
|
emitFloat,
|
|
637
|
+
emitFloatProp,
|
|
550
638
|
emitFunction,
|
|
551
639
|
emitInt32,
|
|
640
|
+
emitInt32Prop,
|
|
641
|
+
emitMixedProp,
|
|
552
642
|
emitNumber,
|
|
553
643
|
emitGenericObject,
|
|
644
|
+
emitDictionary,
|
|
554
645
|
emitObject,
|
|
555
646
|
emitPromise,
|
|
556
647
|
emitRootTag,
|
|
557
648
|
emitVoid,
|
|
558
649
|
emitString,
|
|
559
650
|
emitStringish,
|
|
651
|
+
emitStringProp,
|
|
560
652
|
emitMixed,
|
|
561
653
|
emitUnion,
|
|
562
654
|
emitPartial,
|
|
@@ -565,4 +657,6 @@ module.exports = {
|
|
|
565
657
|
typeEnumResolution,
|
|
566
658
|
translateArrayTypeAnnotation,
|
|
567
659
|
Visitor,
|
|
660
|
+
emitObjectProp,
|
|
661
|
+
emitUnionProp,
|
|
568
662
|
};
|