@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
|
@@ -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
|
*/
|
|
@@ -51,11 +127,11 @@ export interface Parser {
|
|
|
51
127
|
*/
|
|
52
128
|
language(): ParserType;
|
|
53
129
|
/**
|
|
54
|
-
* Given a type annotation
|
|
130
|
+
* Given a type annotation, it returns the type name.
|
|
55
131
|
* @parameter typeAnnotation: the annotation for a type in the AST.
|
|
56
132
|
* @returns: the name of the type.
|
|
57
133
|
*/
|
|
58
|
-
|
|
134
|
+
getTypeAnnotationName(typeAnnotation: $FlowFixMe): string;
|
|
59
135
|
/**
|
|
60
136
|
* Given a type arguments, it returns a boolean specifying if the Module is Invalid.
|
|
61
137
|
* @parameter typeArguments: the type arguments.
|
|
@@ -255,4 +331,101 @@ export interface Parser {
|
|
|
255
331
|
* @returns: converted TypeAnnotation to Keywords
|
|
256
332
|
*/
|
|
257
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
|
+
/**
|
|
361
|
+
* Given a property return the type annotation.
|
|
362
|
+
* @parameter property
|
|
363
|
+
* @returns: the annotation for a type in the AST.
|
|
364
|
+
*/
|
|
365
|
+
getTypeAnnotationFromProperty(property: PropAST): $FlowFixMe;
|
|
366
|
+
|
|
367
|
+
getResolvedTypeAnnotation(
|
|
368
|
+
typeAnnotation: $FlowFixMe,
|
|
369
|
+
types: TypeDeclarationMap,
|
|
370
|
+
parser: Parser,
|
|
371
|
+
): {
|
|
372
|
+
nullable: boolean,
|
|
373
|
+
typeAnnotation: $FlowFixMe,
|
|
374
|
+
typeResolutionStatus: TypeResolutionStatus,
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
getResolveTypeAnnotationFN(): ResolveTypeAnnotationFN;
|
|
378
|
+
|
|
379
|
+
getProps(
|
|
380
|
+
typeDefinition: $ReadOnlyArray<PropAST>,
|
|
381
|
+
types: TypeDeclarationMap,
|
|
382
|
+
): {
|
|
383
|
+
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
384
|
+
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
getProperties(typeName: string, types: TypeDeclarationMap): $FlowFixMe;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Given a typeAlias, it returns the next node.
|
|
391
|
+
*/
|
|
392
|
+
nextNodeForTypeAlias(typeAnnotation: $FlowFixMe): $FlowFixMe;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Given an enum Declaration, it returns the next node.
|
|
396
|
+
*/
|
|
397
|
+
nextNodeForEnum(typeAnnotation: $FlowFixMe): $FlowFixMe;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Given a unsupported typeAnnotation, returns an error message.
|
|
401
|
+
*/
|
|
402
|
+
genericTypeAnnotationErrorMessage(typeAnnotation: $FlowFixMe): string;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Given a type annotation, it extracts the type.
|
|
406
|
+
* @parameter typeAnnotation: the annotation for a type in the AST.
|
|
407
|
+
* @returns: the extracted type.
|
|
408
|
+
*/
|
|
409
|
+
extractTypeFromTypeAnnotation(typeAnnotation: $FlowFixMe): string;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Given a typeAnnotation return the properties of an object.
|
|
413
|
+
* @parameter property
|
|
414
|
+
* @returns: the properties of an object represented by a type annotation.
|
|
415
|
+
*/
|
|
416
|
+
getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Given a option return the literal value.
|
|
420
|
+
* @parameter option
|
|
421
|
+
* @returns: the literal value of an union represented.
|
|
422
|
+
*/
|
|
423
|
+
getLiteralValue(option: $FlowFixMe): $FlowFixMe;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Given a type annotation, it returns top level name in the AST if it exists else returns null.
|
|
427
|
+
* @parameter typeAnnotation: the annotation for a type in the AST.
|
|
428
|
+
* @returns: the top level name properties in the AST if it exists else null.
|
|
429
|
+
*/
|
|
430
|
+
getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe;
|
|
258
431
|
}
|
|
@@ -38,11 +38,17 @@ function _toPrimitive(input, hint) {
|
|
|
38
38
|
}
|
|
39
39
|
return (hint === 'string' ? String : Number)(input);
|
|
40
40
|
}
|
|
41
|
+
import invariant from 'invariant';
|
|
42
|
+
const _require = require('./typescript/components/componentsUtils'),
|
|
43
|
+
flattenProperties = _require.flattenProperties;
|
|
44
|
+
const _require2 = require('./parsers-commons'),
|
|
45
|
+
buildPropSchema = _require2.buildPropSchema;
|
|
46
|
+
|
|
41
47
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
42
48
|
const flowParser = require('flow-parser');
|
|
43
|
-
const
|
|
49
|
+
const _require3 = require('./errors'),
|
|
44
50
|
UnsupportedObjectPropertyTypeAnnotationParserError =
|
|
45
|
-
|
|
51
|
+
_require3.UnsupportedObjectPropertyTypeAnnotationParserError;
|
|
46
52
|
const schemaMock = {
|
|
47
53
|
modules: {
|
|
48
54
|
StringPropNativeComponentView: {
|
|
@@ -65,6 +71,19 @@ export class MockedParser {
|
|
|
65
71
|
'typeParameterInstantiation',
|
|
66
72
|
'TypeParameterInstantiation',
|
|
67
73
|
);
|
|
74
|
+
_defineProperty(this, 'typeAlias', 'TypeAlias');
|
|
75
|
+
_defineProperty(this, 'enumDeclaration', 'EnumDeclaration');
|
|
76
|
+
_defineProperty(this, 'interfaceDeclaration', 'InterfaceDeclaration');
|
|
77
|
+
_defineProperty(
|
|
78
|
+
this,
|
|
79
|
+
'nullLiteralTypeAnnotation',
|
|
80
|
+
'NullLiteralTypeAnnotation',
|
|
81
|
+
);
|
|
82
|
+
_defineProperty(
|
|
83
|
+
this,
|
|
84
|
+
'undefinedLiteralTypeAnnotation',
|
|
85
|
+
'VoidLiteralTypeAnnotation',
|
|
86
|
+
);
|
|
68
87
|
}
|
|
69
88
|
isProperty(property) {
|
|
70
89
|
return property.type === 'ObjectTypeProperty';
|
|
@@ -83,8 +102,14 @@ export class MockedParser {
|
|
|
83
102
|
language() {
|
|
84
103
|
return 'Flow';
|
|
85
104
|
}
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
getTypeAnnotationName(typeAnnotation) {
|
|
106
|
+
var _typeAnnotation$id;
|
|
107
|
+
return typeAnnotation === null || typeAnnotation === void 0
|
|
108
|
+
? void 0
|
|
109
|
+
: (_typeAnnotation$id = typeAnnotation.id) === null ||
|
|
110
|
+
_typeAnnotation$id === void 0
|
|
111
|
+
? void 0
|
|
112
|
+
: _typeAnnotation$id.name;
|
|
88
113
|
}
|
|
89
114
|
checkIfInvalidModule(typeArguments) {
|
|
90
115
|
return false;
|
|
@@ -217,4 +242,177 @@ export class MockedParser {
|
|
|
217
242
|
convertKeywordToTypeAnnotation(keyword) {
|
|
218
243
|
return keyword;
|
|
219
244
|
}
|
|
245
|
+
argumentForProp(prop) {
|
|
246
|
+
return prop.expression;
|
|
247
|
+
}
|
|
248
|
+
nameForArgument(prop) {
|
|
249
|
+
return prop.expression.name;
|
|
250
|
+
}
|
|
251
|
+
isOptionalProperty(property) {
|
|
252
|
+
return property.optional || false;
|
|
253
|
+
}
|
|
254
|
+
getTypeAnnotationFromProperty(property) {
|
|
255
|
+
return property.typeAnnotation.typeAnnotation;
|
|
256
|
+
}
|
|
257
|
+
getGetTypeAnnotationFN() {
|
|
258
|
+
return () => {
|
|
259
|
+
return {};
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
getGetSchemaInfoFN() {
|
|
263
|
+
return () => {
|
|
264
|
+
return {
|
|
265
|
+
name: 'MockedSchema',
|
|
266
|
+
optional: false,
|
|
267
|
+
typeAnnotation: 'BooleanTypeAnnotation',
|
|
268
|
+
defaultValue: false,
|
|
269
|
+
withNullDefault: false,
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
getResolveTypeAnnotationFN() {
|
|
274
|
+
return () => {
|
|
275
|
+
return {
|
|
276
|
+
nullable: false,
|
|
277
|
+
typeAnnotation: null,
|
|
278
|
+
typeResolutionStatus: {
|
|
279
|
+
successful: false,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
getResolvedTypeAnnotation(typeAnnotation, types) {
|
|
285
|
+
invariant(
|
|
286
|
+
typeAnnotation != null,
|
|
287
|
+
'resolveTypeAnnotation(): typeAnnotation cannot be null',
|
|
288
|
+
);
|
|
289
|
+
let node = typeAnnotation;
|
|
290
|
+
let nullable = false;
|
|
291
|
+
let typeResolutionStatus = {
|
|
292
|
+
successful: false,
|
|
293
|
+
};
|
|
294
|
+
for (;;) {
|
|
295
|
+
if (node.type === 'NullableTypeAnnotation') {
|
|
296
|
+
nullable = true;
|
|
297
|
+
node = node.typeAnnotation;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (node.type !== 'GenericTypeAnnotation') {
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
const resolvedTypeAnnotation = types[node.id.name];
|
|
304
|
+
if (resolvedTypeAnnotation == null) {
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
switch (resolvedTypeAnnotation.type) {
|
|
308
|
+
case 'TypeAlias': {
|
|
309
|
+
typeResolutionStatus = {
|
|
310
|
+
successful: true,
|
|
311
|
+
type: 'alias',
|
|
312
|
+
name: node.id.name,
|
|
313
|
+
};
|
|
314
|
+
node = resolvedTypeAnnotation.right;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case 'EnumDeclaration': {
|
|
318
|
+
typeResolutionStatus = {
|
|
319
|
+
successful: true,
|
|
320
|
+
type: 'enum',
|
|
321
|
+
name: node.id.name,
|
|
322
|
+
};
|
|
323
|
+
node = resolvedTypeAnnotation.body;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
default: {
|
|
327
|
+
throw new TypeError(
|
|
328
|
+
`A non GenericTypeAnnotation must be a type declaration ('TypeAlias') or enum ('EnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
nullable: nullable,
|
|
335
|
+
typeAnnotation: node,
|
|
336
|
+
typeResolutionStatus,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
getExtendsProps(typeDefinition, types) {
|
|
340
|
+
return typeDefinition
|
|
341
|
+
.filter(prop => prop.type === 'ObjectTypeSpreadProperty')
|
|
342
|
+
.map(prop => this.extendsForProp(prop, types, this))
|
|
343
|
+
.filter(Boolean);
|
|
344
|
+
}
|
|
345
|
+
extendsForProp(prop, types, parser) {
|
|
346
|
+
const argument = this.argumentForProp(prop);
|
|
347
|
+
if (!argument) {
|
|
348
|
+
console.log('null', prop);
|
|
349
|
+
}
|
|
350
|
+
const name = parser.nameForArgument(prop);
|
|
351
|
+
if (types[name] != null) {
|
|
352
|
+
// This type is locally defined in the file
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
switch (name) {
|
|
356
|
+
case 'ViewProps':
|
|
357
|
+
return {
|
|
358
|
+
type: 'ReactNativeBuiltInType',
|
|
359
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
360
|
+
};
|
|
361
|
+
default: {
|
|
362
|
+
throw new Error(`Unable to handle prop spread: ${name}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
removeKnownExtends(typeDefinition, types) {
|
|
367
|
+
return typeDefinition.filter(
|
|
368
|
+
prop =>
|
|
369
|
+
prop.type !== 'ObjectTypeSpreadProperty' ||
|
|
370
|
+
this.extendsForProp(prop, types, this) === null,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
getProps(typeDefinition, types) {
|
|
374
|
+
const nonExtendsProps = this.removeKnownExtends(typeDefinition, types);
|
|
375
|
+
const props = flattenProperties(nonExtendsProps, types, this)
|
|
376
|
+
.map(property => buildPropSchema(property, types, this))
|
|
377
|
+
.filter(Boolean);
|
|
378
|
+
return {
|
|
379
|
+
props,
|
|
380
|
+
extendsProps: this.getExtendsProps(typeDefinition, types),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
getProperties(typeName, types) {
|
|
384
|
+
const typeAlias = types[typeName];
|
|
385
|
+
try {
|
|
386
|
+
return typeAlias.right.typeParameters.params[0].properties;
|
|
387
|
+
} catch (e) {
|
|
388
|
+
throw new Error(
|
|
389
|
+
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
nextNodeForTypeAlias(typeAnnotation) {
|
|
394
|
+
return typeAnnotation.right;
|
|
395
|
+
}
|
|
396
|
+
nextNodeForEnum(typeAnnotation) {
|
|
397
|
+
return typeAnnotation.body;
|
|
398
|
+
}
|
|
399
|
+
genericTypeAnnotationErrorMessage(typeAnnotation) {
|
|
400
|
+
return `A non GenericTypeAnnotation must be a type declaration ('${this.typeAlias}') or enum ('${this.enumDeclaration}'). Instead, got the unsupported ${typeAnnotation.type}.`;
|
|
401
|
+
}
|
|
402
|
+
extractTypeFromTypeAnnotation(typeAnnotation) {
|
|
403
|
+
return typeAnnotation.type === 'GenericTypeAnnotation'
|
|
404
|
+
? typeAnnotation.id.name
|
|
405
|
+
: typeAnnotation.type;
|
|
406
|
+
}
|
|
407
|
+
getObjectProperties(typeAnnotation) {
|
|
408
|
+
return typeAnnotation.properties;
|
|
409
|
+
}
|
|
410
|
+
getLiteralValue(option) {
|
|
411
|
+
return option.value;
|
|
412
|
+
}
|
|
413
|
+
getPaperTopLevelNameDeprecated(typeAnnotation) {
|
|
414
|
+
return typeAnnotation.typeParameters.params.length > 1
|
|
415
|
+
? typeAnnotation.typeParameters.params[1].value
|
|
416
|
+
: null;
|
|
417
|
+
}
|
|
220
418
|
}
|