@react-native/codegen 0.72.5 → 0.73.0-nightly-20230603-fd9e295be
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 +6 -6
- package/lib/parsers/flow/components/componentsUtils.js.flow +10 -10
- package/lib/parsers/flow/components/events.js +157 -78
- package/lib/parsers/flow/components/events.js.flow +158 -77
- package/lib/parsers/flow/components/index.js +28 -105
- package/lib/parsers/flow/components/index.js.flow +21 -110
- 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 +167 -16
- package/lib/parsers/flow/parser.js.flow +209 -6
- package/lib/parsers/flow/utils.js +0 -63
- package/lib/parsers/flow/utils.js.flow +1 -77
- package/lib/parsers/parser.js.flow +141 -1
- package/lib/parsers/parserMock.js +165 -2
- package/lib/parsers/parserMock.js.flow +216 -2
- package/lib/parsers/parsers-commons.js +128 -9
- package/lib/parsers/parsers-commons.js.flow +182 -12
- package/lib/parsers/parsers-primitives.js +84 -35
- package/lib/parsers/parsers-primitives.js.flow +110 -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 +31 -7
- package/lib/parsers/typescript/components/componentsUtils.js.flow +31 -14
- package/lib/parsers/typescript/components/events.js +142 -67
- package/lib/parsers/typescript/components/events.js.flow +149 -68
- 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 +29 -109
- package/lib/parsers/typescript/components/index.js.flow +21 -116
- package/lib/parsers/typescript/modules/index.js +41 -50
- package/lib/parsers/typescript/modules/index.js.flow +23 -31
- package/lib/parsers/typescript/parser.d.ts +9 -2
- package/lib/parsers/typescript/parser.js +193 -7
- package/lib/parsers/typescript/parser.js.flow +235 -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
|
@@ -38,23 +38,27 @@ function _toPrimitive(input, hint) {
|
|
|
38
38
|
}
|
|
39
39
|
return (hint === 'string' ? String : Number)(input);
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
const invariant = require('invariant');
|
|
42
|
+
const _require = require('./components/componentsUtils'),
|
|
43
|
+
getSchemaInfo = _require.getSchemaInfo,
|
|
44
|
+
getTypeAnnotation = _require.getTypeAnnotation,
|
|
45
|
+
flattenProperties = _require.flattenProperties;
|
|
46
|
+
const _require2 = require('./modules'),
|
|
47
|
+
flowTranslateTypeAnnotation = _require2.flowTranslateTypeAnnotation;
|
|
43
48
|
|
|
44
49
|
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
45
50
|
const flowParser = require('flow-parser');
|
|
46
|
-
const
|
|
47
|
-
buildSchema =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
resolveTypeAnnotation = _require7.resolveTypeAnnotation;
|
|
51
|
+
const _require3 = require('../parsers-commons'),
|
|
52
|
+
buildSchema = _require3.buildSchema,
|
|
53
|
+
buildPropSchema = _require3.buildPropSchema;
|
|
54
|
+
const _require4 = require('../parsers-primitives'),
|
|
55
|
+
Visitor = _require4.Visitor;
|
|
56
|
+
const _require5 = require('./components'),
|
|
57
|
+
buildComponentSchema = _require5.buildComponentSchema;
|
|
58
|
+
const _require6 = require('../schema.js'),
|
|
59
|
+
wrapComponentSchema = _require6.wrapComponentSchema;
|
|
60
|
+
const _require7 = require('../parsers-commons.js'),
|
|
61
|
+
buildModuleSchema = _require7.buildModuleSchema;
|
|
58
62
|
const fs = require('fs');
|
|
59
63
|
const _require8 = require('../errors'),
|
|
60
64
|
UnsupportedObjectPropertyTypeAnnotationParserError =
|
|
@@ -66,6 +70,19 @@ class FlowParser {
|
|
|
66
70
|
'typeParameterInstantiation',
|
|
67
71
|
'TypeParameterInstantiation',
|
|
68
72
|
);
|
|
73
|
+
_defineProperty(this, 'typeAlias', 'TypeAlias');
|
|
74
|
+
_defineProperty(this, 'enumDeclaration', 'EnumDeclaration');
|
|
75
|
+
_defineProperty(this, 'interfaceDeclaration', 'InterfaceDeclaration');
|
|
76
|
+
_defineProperty(
|
|
77
|
+
this,
|
|
78
|
+
'nullLiteralTypeAnnotation',
|
|
79
|
+
'NullLiteralTypeAnnotation',
|
|
80
|
+
);
|
|
81
|
+
_defineProperty(
|
|
82
|
+
this,
|
|
83
|
+
'undefinedLiteralTypeAnnotation',
|
|
84
|
+
'VoidLiteralTypeAnnotation',
|
|
85
|
+
);
|
|
69
86
|
}
|
|
70
87
|
isProperty(property) {
|
|
71
88
|
return property.type === 'ObjectTypeProperty';
|
|
@@ -85,7 +102,13 @@ class FlowParser {
|
|
|
85
102
|
return 'Flow';
|
|
86
103
|
}
|
|
87
104
|
nameForGenericTypeAnnotation(typeAnnotation) {
|
|
88
|
-
|
|
105
|
+
var _typeAnnotation$id;
|
|
106
|
+
return typeAnnotation === null || typeAnnotation === void 0
|
|
107
|
+
? void 0
|
|
108
|
+
: (_typeAnnotation$id = typeAnnotation.id) === null ||
|
|
109
|
+
_typeAnnotation$id === void 0
|
|
110
|
+
? void 0
|
|
111
|
+
: _typeAnnotation$id.name;
|
|
89
112
|
}
|
|
90
113
|
checkIfInvalidModule(typeArguments) {
|
|
91
114
|
return (
|
|
@@ -116,7 +139,6 @@ class FlowParser {
|
|
|
116
139
|
buildModuleSchema,
|
|
117
140
|
Visitor,
|
|
118
141
|
this,
|
|
119
|
-
resolveTypeAnnotation,
|
|
120
142
|
flowTranslateTypeAnnotation,
|
|
121
143
|
);
|
|
122
144
|
}
|
|
@@ -208,6 +230,9 @@ class FlowParser {
|
|
|
208
230
|
node.extends[0].id.name === 'TurboModule'
|
|
209
231
|
);
|
|
210
232
|
}
|
|
233
|
+
isGenericTypeAnnotation(type) {
|
|
234
|
+
return type === 'GenericTypeAnnotation';
|
|
235
|
+
}
|
|
211
236
|
extractAnnotatedElement(typeAnnotation, types) {
|
|
212
237
|
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
213
238
|
}
|
|
@@ -300,6 +325,132 @@ class FlowParser {
|
|
|
300
325
|
getAnnotatedElementProperties(annotatedElement) {
|
|
301
326
|
return annotatedElement.right.properties;
|
|
302
327
|
}
|
|
328
|
+
bodyProperties(typeAlias) {
|
|
329
|
+
return typeAlias.body.properties;
|
|
330
|
+
}
|
|
331
|
+
convertKeywordToTypeAnnotation(keyword) {
|
|
332
|
+
return keyword;
|
|
333
|
+
}
|
|
334
|
+
argumentForProp(prop) {
|
|
335
|
+
return prop.argument;
|
|
336
|
+
}
|
|
337
|
+
nameForArgument(prop) {
|
|
338
|
+
return prop.argument.id.name;
|
|
339
|
+
}
|
|
340
|
+
isOptionalProperty(property) {
|
|
341
|
+
return (
|
|
342
|
+
property.value.type === 'NullableTypeAnnotation' || property.optional
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
getGetSchemaInfoFN() {
|
|
346
|
+
return getSchemaInfo;
|
|
347
|
+
}
|
|
348
|
+
getGetTypeAnnotationFN() {
|
|
349
|
+
return getTypeAnnotation;
|
|
350
|
+
}
|
|
351
|
+
getResolvedTypeAnnotation(typeAnnotation, types, parser) {
|
|
352
|
+
invariant(
|
|
353
|
+
typeAnnotation != null,
|
|
354
|
+
'resolveTypeAnnotation(): typeAnnotation cannot be null',
|
|
355
|
+
);
|
|
356
|
+
let node = typeAnnotation;
|
|
357
|
+
let nullable = false;
|
|
358
|
+
let typeResolutionStatus = {
|
|
359
|
+
successful: false,
|
|
360
|
+
};
|
|
361
|
+
for (;;) {
|
|
362
|
+
if (node.type === 'NullableTypeAnnotation') {
|
|
363
|
+
nullable = true;
|
|
364
|
+
node = node.typeAnnotation;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (node.type !== 'GenericTypeAnnotation') {
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
const resolvedTypeAnnotation = types[node.id.name];
|
|
371
|
+
if (resolvedTypeAnnotation == null) {
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
switch (resolvedTypeAnnotation.type) {
|
|
375
|
+
case parser.typeAlias: {
|
|
376
|
+
typeResolutionStatus = {
|
|
377
|
+
successful: true,
|
|
378
|
+
type: 'alias',
|
|
379
|
+
name: node.id.name,
|
|
380
|
+
};
|
|
381
|
+
node = resolvedTypeAnnotation.right;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
case parser.enumDeclaration: {
|
|
385
|
+
typeResolutionStatus = {
|
|
386
|
+
successful: true,
|
|
387
|
+
type: 'enum',
|
|
388
|
+
name: node.id.name,
|
|
389
|
+
};
|
|
390
|
+
node = resolvedTypeAnnotation.body;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
default: {
|
|
394
|
+
throw new TypeError(
|
|
395
|
+
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}') or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
nullable: nullable,
|
|
402
|
+
typeAnnotation: node,
|
|
403
|
+
typeResolutionStatus,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
getResolveTypeAnnotationFN() {
|
|
407
|
+
return (typeAnnotation, types, parser) =>
|
|
408
|
+
this.getResolvedTypeAnnotation(typeAnnotation, types, parser);
|
|
409
|
+
}
|
|
410
|
+
extendsForProp(prop, types, parser) {
|
|
411
|
+
const argument = this.argumentForProp(prop);
|
|
412
|
+
if (!argument) {
|
|
413
|
+
console.log('null', prop);
|
|
414
|
+
}
|
|
415
|
+
const name = parser.nameForArgument(prop);
|
|
416
|
+
if (types[name] != null) {
|
|
417
|
+
// This type is locally defined in the file
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
switch (name) {
|
|
421
|
+
case 'ViewProps':
|
|
422
|
+
return {
|
|
423
|
+
type: 'ReactNativeBuiltInType',
|
|
424
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
425
|
+
};
|
|
426
|
+
default: {
|
|
427
|
+
throw new Error(`Unable to handle prop spread: ${name}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
removeKnownExtends(typeDefinition, types) {
|
|
432
|
+
return typeDefinition.filter(
|
|
433
|
+
prop =>
|
|
434
|
+
prop.type !== 'ObjectTypeSpreadProperty' ||
|
|
435
|
+
this.extendsForProp(prop, types, this) === null,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
getExtendsProps(typeDefinition, types) {
|
|
439
|
+
return typeDefinition
|
|
440
|
+
.filter(prop => prop.type === 'ObjectTypeSpreadProperty')
|
|
441
|
+
.map(prop => this.extendsForProp(prop, types, this))
|
|
442
|
+
.filter(Boolean);
|
|
443
|
+
}
|
|
444
|
+
getProps(typeDefinition, types) {
|
|
445
|
+
const nonExtendsProps = this.removeKnownExtends(typeDefinition, types);
|
|
446
|
+
const props = flattenProperties(nonExtendsProps, types)
|
|
447
|
+
.map(property => buildPropSchema(property, types, this))
|
|
448
|
+
.filter(Boolean);
|
|
449
|
+
return {
|
|
450
|
+
props,
|
|
451
|
+
extendsProps: this.getExtendsProps(typeDefinition, types),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
303
454
|
}
|
|
304
455
|
module.exports = {
|
|
305
456
|
FlowParser,
|
|
@@ -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,177 @@ 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)
|
|
515
|
+
.map(property => buildPropSchema(property, types, this))
|
|
516
|
+
.filter(Boolean);
|
|
517
|
+
|
|
518
|
+
return {
|
|
519
|
+
props,
|
|
520
|
+
extendsProps: this.getExtendsProps(typeDefinition, types),
|
|
521
|
+
};
|
|
522
|
+
}
|
|
320
523
|
}
|
|
321
524
|
|
|
322
525
|
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
|
};
|