@react-native/codegen 0.72.3 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CodegenSchema.d.ts +10 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +33 -44
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +35 -44
- package/lib/generators/components/GenerateEventEmitterH.js +0 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +0 -2
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- package/lib/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 +9 -15
- package/lib/parsers/error-utils.js.flow +12 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +35 -168
- package/lib/parsers/flow/components/index.js.flow +33 -107
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +51 -327
- package/lib/parsers/flow/modules/index.js.flow +34 -258
- package/lib/parsers/flow/parser.js +84 -13
- package/lib/parsers/flow/parser.js.flow +80 -4
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -3
- package/lib/parsers/parserMock.js +53 -0
- package/lib/parsers/parserMock.js.flow +64 -1
- package/lib/parsers/parsers-commons.js +397 -4
- package/lib/parsers/parsers-commons.js.flow +391 -4
- package/lib/parsers/parsers-primitives.js +121 -3
- package/lib/parsers/parsers-primitives.js.flow +134 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +37 -170
- package/lib/parsers/typescript/components/index.js.flow +33 -109
- package/lib/parsers/typescript/modules/index.js +113 -441
- package/lib/parsers/typescript/modules/index.js.flow +100 -309
- package/lib/parsers/typescript/parser.js +97 -13
- package/lib/parsers/typescript/parser.js.flow +94 -4
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
|
@@ -15,9 +15,7 @@ import type {
|
|
|
15
15
|
NativeModuleAliasMap,
|
|
16
16
|
NativeModuleEnumMap,
|
|
17
17
|
NativeModuleBaseTypeAnnotation,
|
|
18
|
-
NativeModulePropertyShape,
|
|
19
18
|
NativeModuleTypeAnnotation,
|
|
20
|
-
NativeModuleSchema,
|
|
21
19
|
Nullable,
|
|
22
20
|
} from '../../../CodegenSchema';
|
|
23
21
|
|
|
@@ -30,33 +28,20 @@ import type {
|
|
|
30
28
|
const {flattenIntersectionType} = require('../parseTopLevelType');
|
|
31
29
|
const {flattenProperties} = require('../components/componentsUtils');
|
|
32
30
|
|
|
33
|
-
const {visit, isModuleRegistryCall, verifyPlatforms} = require('../../utils');
|
|
34
31
|
const {resolveTypeAnnotation} = require('../utils');
|
|
35
32
|
|
|
36
|
-
const {
|
|
37
|
-
parseObjectProperty,
|
|
38
|
-
buildPropertySchema,
|
|
39
|
-
} = require('../../parsers-commons');
|
|
40
|
-
const {typeEnumResolution} = require('../../parsers-primitives');
|
|
33
|
+
const {parseObjectProperty} = require('../../parsers-commons');
|
|
41
34
|
|
|
42
35
|
const {
|
|
43
36
|
emitArrayType,
|
|
44
|
-
emitBoolean,
|
|
45
|
-
emitDouble,
|
|
46
|
-
emitFloat,
|
|
47
37
|
emitFunction,
|
|
48
|
-
emitNumber,
|
|
49
|
-
emitInt32,
|
|
50
38
|
emitGenericObject,
|
|
51
|
-
emitObject,
|
|
52
39
|
emitPromise,
|
|
53
40
|
emitRootTag,
|
|
54
|
-
emitVoid,
|
|
55
|
-
emitString,
|
|
56
|
-
emitStringish,
|
|
57
|
-
emitMixed,
|
|
58
41
|
emitUnion,
|
|
42
|
+
emitCommonTypes,
|
|
59
43
|
typeAliasResolution,
|
|
44
|
+
typeEnumResolution,
|
|
60
45
|
translateArrayTypeAnnotation,
|
|
61
46
|
} = require('../../parsers-primitives');
|
|
62
47
|
|
|
@@ -65,22 +50,6 @@ const {
|
|
|
65
50
|
UnsupportedTypeAnnotationParserError,
|
|
66
51
|
} = require('../../errors');
|
|
67
52
|
|
|
68
|
-
const {
|
|
69
|
-
throwIfUntypedModule,
|
|
70
|
-
throwIfUnusedModuleInterfaceParserError,
|
|
71
|
-
throwIfModuleInterfaceNotFound,
|
|
72
|
-
throwIfModuleInterfaceIsMisnamed,
|
|
73
|
-
throwIfWrongNumberOfCallExpressionArgs,
|
|
74
|
-
throwIfMoreThanOneModuleRegistryCalls,
|
|
75
|
-
throwIfMoreThanOneModuleInterfaceParserError,
|
|
76
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
77
|
-
throwIfIncorrectModuleRegistryCallArgument,
|
|
78
|
-
throwIfPartialNotAnnotatingTypeParameter,
|
|
79
|
-
throwIfPartialWithMoreParameter,
|
|
80
|
-
} = require('../../error-utils');
|
|
81
|
-
|
|
82
|
-
const language = 'TypeScript';
|
|
83
|
-
|
|
84
53
|
function translateObjectTypeAnnotation(
|
|
85
54
|
hasteModuleName: string,
|
|
86
55
|
/**
|
|
@@ -139,6 +108,74 @@ function translateObjectTypeAnnotation(
|
|
|
139
108
|
);
|
|
140
109
|
}
|
|
141
110
|
|
|
111
|
+
function translateTypeReferenceAnnotation(
|
|
112
|
+
typeName: string,
|
|
113
|
+
nullable: boolean,
|
|
114
|
+
typeAnnotation: $FlowFixMe,
|
|
115
|
+
hasteModuleName: string,
|
|
116
|
+
types: TypeDeclarationMap,
|
|
117
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
118
|
+
enumMap: {...NativeModuleEnumMap},
|
|
119
|
+
tryParse: ParserErrorCapturer,
|
|
120
|
+
cxxOnly: boolean,
|
|
121
|
+
parser: Parser,
|
|
122
|
+
): Nullable<NativeModuleTypeAnnotation> {
|
|
123
|
+
switch (typeName) {
|
|
124
|
+
case 'RootTag': {
|
|
125
|
+
return emitRootTag(nullable);
|
|
126
|
+
}
|
|
127
|
+
case 'Promise': {
|
|
128
|
+
return emitPromise(
|
|
129
|
+
hasteModuleName,
|
|
130
|
+
typeAnnotation,
|
|
131
|
+
parser,
|
|
132
|
+
nullable,
|
|
133
|
+
types,
|
|
134
|
+
aliasMap,
|
|
135
|
+
enumMap,
|
|
136
|
+
tryParse,
|
|
137
|
+
cxxOnly,
|
|
138
|
+
translateTypeAnnotation,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
case 'Array':
|
|
142
|
+
case 'ReadonlyArray': {
|
|
143
|
+
return emitArrayType(
|
|
144
|
+
hasteModuleName,
|
|
145
|
+
typeAnnotation,
|
|
146
|
+
parser,
|
|
147
|
+
types,
|
|
148
|
+
aliasMap,
|
|
149
|
+
enumMap,
|
|
150
|
+
cxxOnly,
|
|
151
|
+
nullable,
|
|
152
|
+
translateTypeAnnotation,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
default: {
|
|
156
|
+
const commonType = emitCommonTypes(
|
|
157
|
+
hasteModuleName,
|
|
158
|
+
types,
|
|
159
|
+
typeAnnotation,
|
|
160
|
+
aliasMap,
|
|
161
|
+
enumMap,
|
|
162
|
+
tryParse,
|
|
163
|
+
cxxOnly,
|
|
164
|
+
nullable,
|
|
165
|
+
parser,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (!commonType) {
|
|
169
|
+
throw new UnsupportedGenericParserError(
|
|
170
|
+
hasteModuleName,
|
|
171
|
+
typeAnnotation,
|
|
172
|
+
parser,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return commonType;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
142
179
|
function translateTypeAnnotation(
|
|
143
180
|
hasteModuleName: string,
|
|
144
181
|
/**
|
|
@@ -196,97 +233,18 @@ function translateTypeAnnotation(
|
|
|
196
233
|
}
|
|
197
234
|
}
|
|
198
235
|
case 'TSTypeReference': {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
enumMap,
|
|
212
|
-
tryParse,
|
|
213
|
-
cxxOnly,
|
|
214
|
-
translateTypeAnnotation,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
case 'Array':
|
|
218
|
-
case 'ReadonlyArray': {
|
|
219
|
-
return emitArrayType(
|
|
220
|
-
hasteModuleName,
|
|
221
|
-
typeAnnotation,
|
|
222
|
-
parser,
|
|
223
|
-
types,
|
|
224
|
-
aliasMap,
|
|
225
|
-
enumMap,
|
|
226
|
-
cxxOnly,
|
|
227
|
-
nullable,
|
|
228
|
-
translateTypeAnnotation,
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
case 'Stringish': {
|
|
232
|
-
return emitStringish(nullable);
|
|
233
|
-
}
|
|
234
|
-
case 'Int32': {
|
|
235
|
-
return emitInt32(nullable);
|
|
236
|
-
}
|
|
237
|
-
case 'Double': {
|
|
238
|
-
return emitDouble(nullable);
|
|
239
|
-
}
|
|
240
|
-
case 'Float': {
|
|
241
|
-
return emitFloat(nullable);
|
|
242
|
-
}
|
|
243
|
-
case 'UnsafeObject':
|
|
244
|
-
case 'Object': {
|
|
245
|
-
return emitGenericObject(nullable);
|
|
246
|
-
}
|
|
247
|
-
case 'Partial': {
|
|
248
|
-
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
249
|
-
|
|
250
|
-
const annotatedElement = parser.extractAnnotatedElement(
|
|
251
|
-
typeAnnotation,
|
|
252
|
-
types,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
throwIfPartialNotAnnotatingTypeParameter(
|
|
256
|
-
typeAnnotation,
|
|
257
|
-
types,
|
|
258
|
-
parser,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const properties = annotatedElement.typeAnnotation.members.map(
|
|
262
|
-
member => {
|
|
263
|
-
return {
|
|
264
|
-
name: member.key.name,
|
|
265
|
-
optional: true,
|
|
266
|
-
typeAnnotation: translateTypeAnnotation(
|
|
267
|
-
hasteModuleName,
|
|
268
|
-
member.typeAnnotation.typeAnnotation,
|
|
269
|
-
types,
|
|
270
|
-
aliasMap,
|
|
271
|
-
enumMap,
|
|
272
|
-
tryParse,
|
|
273
|
-
cxxOnly,
|
|
274
|
-
parser,
|
|
275
|
-
),
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
return emitObject(nullable, properties);
|
|
281
|
-
}
|
|
282
|
-
default: {
|
|
283
|
-
throw new UnsupportedGenericParserError(
|
|
284
|
-
hasteModuleName,
|
|
285
|
-
typeAnnotation,
|
|
286
|
-
parser,
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
236
|
+
return translateTypeReferenceAnnotation(
|
|
237
|
+
typeAnnotation.typeName.name,
|
|
238
|
+
nullable,
|
|
239
|
+
typeAnnotation,
|
|
240
|
+
hasteModuleName,
|
|
241
|
+
types,
|
|
242
|
+
aliasMap,
|
|
243
|
+
enumMap,
|
|
244
|
+
tryParse,
|
|
245
|
+
cxxOnly,
|
|
246
|
+
parser,
|
|
247
|
+
);
|
|
290
248
|
}
|
|
291
249
|
case 'TSInterfaceDeclaration': {
|
|
292
250
|
const baseTypes = (typeAnnotation.extends ?? []).map(
|
|
@@ -386,23 +344,10 @@ function translateTypeAnnotation(
|
|
|
386
344
|
typeResolutionStatus,
|
|
387
345
|
nullable,
|
|
388
346
|
hasteModuleName,
|
|
389
|
-
language,
|
|
390
347
|
enumMap,
|
|
391
348
|
parser,
|
|
392
349
|
);
|
|
393
350
|
}
|
|
394
|
-
case 'TSBooleanKeyword': {
|
|
395
|
-
return emitBoolean(nullable);
|
|
396
|
-
}
|
|
397
|
-
case 'TSNumberKeyword': {
|
|
398
|
-
return emitNumber(nullable);
|
|
399
|
-
}
|
|
400
|
-
case 'TSVoidKeyword': {
|
|
401
|
-
return emitVoid(nullable);
|
|
402
|
-
}
|
|
403
|
-
case 'TSStringKeyword': {
|
|
404
|
-
return emitString(nullable);
|
|
405
|
-
}
|
|
406
351
|
case 'TSFunctionType': {
|
|
407
352
|
return emitFunction(
|
|
408
353
|
nullable,
|
|
@@ -420,185 +365,31 @@ function translateTypeAnnotation(
|
|
|
420
365
|
case 'TSUnionType': {
|
|
421
366
|
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
|
|
422
367
|
}
|
|
423
|
-
case 'TSUnknownKeyword': {
|
|
424
|
-
if (cxxOnly) {
|
|
425
|
-
return emitMixed(nullable);
|
|
426
|
-
}
|
|
427
|
-
// Fallthrough
|
|
428
|
-
}
|
|
429
368
|
default: {
|
|
430
|
-
|
|
369
|
+
const commonType = emitCommonTypes(
|
|
431
370
|
hasteModuleName,
|
|
371
|
+
types,
|
|
432
372
|
typeAnnotation,
|
|
433
|
-
|
|
373
|
+
aliasMap,
|
|
374
|
+
enumMap,
|
|
375
|
+
tryParse,
|
|
376
|
+
cxxOnly,
|
|
377
|
+
nullable,
|
|
378
|
+
parser,
|
|
434
379
|
);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function buildModuleSchema(
|
|
440
|
-
hasteModuleName: string,
|
|
441
|
-
/**
|
|
442
|
-
* TODO(T108222691): Use flow-types for @babel/parser
|
|
443
|
-
*/
|
|
444
|
-
ast: $FlowFixMe,
|
|
445
|
-
tryParse: ParserErrorCapturer,
|
|
446
|
-
parser: Parser,
|
|
447
|
-
): NativeModuleSchema {
|
|
448
|
-
const types = parser.getTypes(ast);
|
|
449
|
-
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
450
|
-
t => parser.isModuleInterface(t),
|
|
451
|
-
);
|
|
452
|
-
|
|
453
|
-
throwIfModuleInterfaceNotFound(
|
|
454
|
-
moduleSpecs.length,
|
|
455
|
-
hasteModuleName,
|
|
456
|
-
ast,
|
|
457
|
-
language,
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
461
|
-
hasteModuleName,
|
|
462
|
-
moduleSpecs,
|
|
463
|
-
language,
|
|
464
|
-
);
|
|
465
|
-
|
|
466
|
-
const [moduleSpec] = moduleSpecs;
|
|
467
|
-
|
|
468
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
469
|
-
|
|
470
|
-
// Parse Module Name
|
|
471
|
-
const moduleName = ((): string => {
|
|
472
|
-
const callExpressions = [];
|
|
473
|
-
visit(ast, {
|
|
474
|
-
CallExpression(node) {
|
|
475
|
-
if (isModuleRegistryCall(node)) {
|
|
476
|
-
callExpressions.push(node);
|
|
477
|
-
}
|
|
478
|
-
},
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
482
|
-
hasteModuleName,
|
|
483
|
-
moduleSpec,
|
|
484
|
-
callExpressions,
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
488
|
-
hasteModuleName,
|
|
489
|
-
callExpressions,
|
|
490
|
-
callExpressions.length,
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
const [callExpression] = callExpressions;
|
|
494
|
-
const {typeParameters} = callExpression;
|
|
495
|
-
const methodName = callExpression.callee.property.name;
|
|
496
|
-
|
|
497
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
498
|
-
hasteModuleName,
|
|
499
|
-
callExpression,
|
|
500
|
-
methodName,
|
|
501
|
-
callExpression.arguments.length,
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
throwIfIncorrectModuleRegistryCallArgument(
|
|
505
|
-
hasteModuleName,
|
|
506
|
-
callExpression.arguments[0],
|
|
507
|
-
methodName,
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
511
|
-
|
|
512
|
-
throwIfUntypedModule(
|
|
513
|
-
typeParameters,
|
|
514
|
-
hasteModuleName,
|
|
515
|
-
callExpression,
|
|
516
|
-
methodName,
|
|
517
|
-
$moduleName,
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
521
|
-
hasteModuleName,
|
|
522
|
-
typeParameters,
|
|
523
|
-
methodName,
|
|
524
|
-
$moduleName,
|
|
525
|
-
parser,
|
|
526
|
-
);
|
|
527
380
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
532
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
533
|
-
// Also check the hasteModuleName for platform suffix.
|
|
534
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
535
|
-
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
536
|
-
hasteModuleName,
|
|
537
|
-
moduleName,
|
|
538
|
-
);
|
|
539
|
-
|
|
540
|
-
// $FlowFixMe[missing-type-arg]
|
|
541
|
-
return (moduleSpec.body.body: $ReadOnlyArray<$FlowFixMe>)
|
|
542
|
-
.filter(
|
|
543
|
-
property =>
|
|
544
|
-
property.type === 'TSMethodSignature' ||
|
|
545
|
-
property.type === 'TSPropertySignature',
|
|
546
|
-
)
|
|
547
|
-
.map<?{
|
|
548
|
-
aliasMap: NativeModuleAliasMap,
|
|
549
|
-
enumMap: NativeModuleEnumMap,
|
|
550
|
-
propertyShape: NativeModulePropertyShape,
|
|
551
|
-
}>(property => {
|
|
552
|
-
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
553
|
-
const enumMap: {...NativeModuleEnumMap} = {};
|
|
554
|
-
|
|
555
|
-
return tryParse(() => ({
|
|
556
|
-
aliasMap: aliasMap,
|
|
557
|
-
enumMap: enumMap,
|
|
558
|
-
propertyShape: buildPropertySchema(
|
|
381
|
+
if (!commonType) {
|
|
382
|
+
throw new UnsupportedTypeAnnotationParserError(
|
|
559
383
|
hasteModuleName,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
translateTypeAnnotation,
|
|
568
|
-
parser,
|
|
569
|
-
),
|
|
570
|
-
}));
|
|
571
|
-
})
|
|
572
|
-
.filter(Boolean)
|
|
573
|
-
.reduce(
|
|
574
|
-
(
|
|
575
|
-
moduleSchema: NativeModuleSchema,
|
|
576
|
-
{aliasMap, enumMap, propertyShape},
|
|
577
|
-
) => {
|
|
578
|
-
return {
|
|
579
|
-
type: 'NativeModule',
|
|
580
|
-
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
581
|
-
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
582
|
-
spec: {
|
|
583
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
584
|
-
},
|
|
585
|
-
moduleName: moduleSchema.moduleName,
|
|
586
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
587
|
-
};
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
type: 'NativeModule',
|
|
591
|
-
aliasMap: {},
|
|
592
|
-
enumMap: {},
|
|
593
|
-
spec: {properties: []},
|
|
594
|
-
moduleName: moduleName,
|
|
595
|
-
excludedPlatforms:
|
|
596
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
597
|
-
},
|
|
598
|
-
);
|
|
384
|
+
typeAnnotation,
|
|
385
|
+
parser.language(),
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
return commonType;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
599
391
|
}
|
|
600
392
|
|
|
601
393
|
module.exports = {
|
|
602
|
-
buildModuleSchema,
|
|
603
394
|
typeScriptTranslateTypeAnnotation: translateTypeAnnotation,
|
|
604
395
|
};
|
|
@@ -38,22 +38,28 @@ function _toPrimitive(input, hint) {
|
|
|
38
38
|
}
|
|
39
39
|
return (hint === 'string' ? String : Number)(input);
|
|
40
40
|
}
|
|
41
|
+
const _require = require('./modules'),
|
|
42
|
+
typeScriptTranslateTypeAnnotation =
|
|
43
|
+
_require.typeScriptTranslateTypeAnnotation;
|
|
44
|
+
|
|
41
45
|
// $FlowFixMe[untyped-import] Use flow-types for @babel/parser
|
|
42
46
|
const babelParser = require('@babel/parser');
|
|
43
|
-
const
|
|
44
|
-
buildSchema =
|
|
45
|
-
const
|
|
46
|
-
Visitor =
|
|
47
|
-
const
|
|
48
|
-
buildComponentSchema =
|
|
49
|
-
const
|
|
50
|
-
wrapComponentSchema =
|
|
51
|
-
const
|
|
52
|
-
buildModuleSchema =
|
|
47
|
+
const _require2 = require('../parsers-commons'),
|
|
48
|
+
buildSchema = _require2.buildSchema;
|
|
49
|
+
const _require3 = require('../parsers-primitives'),
|
|
50
|
+
Visitor = _require3.Visitor;
|
|
51
|
+
const _require4 = require('./components'),
|
|
52
|
+
buildComponentSchema = _require4.buildComponentSchema;
|
|
53
|
+
const _require5 = require('../schema.js'),
|
|
54
|
+
wrapComponentSchema = _require5.wrapComponentSchema;
|
|
55
|
+
const _require6 = require('../parsers-commons.js'),
|
|
56
|
+
buildModuleSchema = _require6.buildModuleSchema;
|
|
57
|
+
const _require7 = require('./utils'),
|
|
58
|
+
resolveTypeAnnotation = _require7.resolveTypeAnnotation;
|
|
53
59
|
const fs = require('fs');
|
|
54
|
-
const
|
|
60
|
+
const _require8 = require('../errors'),
|
|
55
61
|
UnsupportedObjectPropertyTypeAnnotationParserError =
|
|
56
|
-
|
|
62
|
+
_require8.UnsupportedObjectPropertyTypeAnnotationParserError;
|
|
57
63
|
class TypeScriptParser {
|
|
58
64
|
constructor() {
|
|
59
65
|
_defineProperty(
|
|
@@ -80,7 +86,13 @@ class TypeScriptParser {
|
|
|
80
86
|
return 'TypeScript';
|
|
81
87
|
}
|
|
82
88
|
nameForGenericTypeAnnotation(typeAnnotation) {
|
|
83
|
-
|
|
89
|
+
var _typeAnnotation$typeN;
|
|
90
|
+
return typeAnnotation === null || typeAnnotation === void 0
|
|
91
|
+
? void 0
|
|
92
|
+
: (_typeAnnotation$typeN = typeAnnotation.typeName) === null ||
|
|
93
|
+
_typeAnnotation$typeN === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: _typeAnnotation$typeN.name;
|
|
84
96
|
}
|
|
85
97
|
checkIfInvalidModule(typeArguments) {
|
|
86
98
|
return (
|
|
@@ -113,6 +125,8 @@ class TypeScriptParser {
|
|
|
113
125
|
buildModuleSchema,
|
|
114
126
|
Visitor,
|
|
115
127
|
this,
|
|
128
|
+
resolveTypeAnnotation,
|
|
129
|
+
typeScriptTranslateTypeAnnotation,
|
|
116
130
|
);
|
|
117
131
|
}
|
|
118
132
|
parseModuleFixture(filename) {
|
|
@@ -216,6 +230,9 @@ class TypeScriptParser {
|
|
|
216
230
|
node.extends[0].expression.name === 'TurboModule'
|
|
217
231
|
);
|
|
218
232
|
}
|
|
233
|
+
isGenericTypeAnnotation(type) {
|
|
234
|
+
return type === 'TSTypeReference';
|
|
235
|
+
}
|
|
219
236
|
extractAnnotatedElement(typeAnnotation, types) {
|
|
220
237
|
return types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
221
238
|
}
|
|
@@ -249,6 +266,73 @@ class TypeScriptParser {
|
|
|
249
266
|
return types;
|
|
250
267
|
}, {});
|
|
251
268
|
}
|
|
269
|
+
callExpressionTypeParameters(callExpression) {
|
|
270
|
+
return callExpression.typeParameters || null;
|
|
271
|
+
}
|
|
272
|
+
computePartialProperties(
|
|
273
|
+
properties,
|
|
274
|
+
hasteModuleName,
|
|
275
|
+
types,
|
|
276
|
+
aliasMap,
|
|
277
|
+
enumMap,
|
|
278
|
+
tryParse,
|
|
279
|
+
cxxOnly,
|
|
280
|
+
) {
|
|
281
|
+
return properties.map(prop => {
|
|
282
|
+
return {
|
|
283
|
+
name: prop.key.name,
|
|
284
|
+
optional: true,
|
|
285
|
+
typeAnnotation: typeScriptTranslateTypeAnnotation(
|
|
286
|
+
hasteModuleName,
|
|
287
|
+
prop.typeAnnotation.typeAnnotation,
|
|
288
|
+
types,
|
|
289
|
+
aliasMap,
|
|
290
|
+
enumMap,
|
|
291
|
+
tryParse,
|
|
292
|
+
cxxOnly,
|
|
293
|
+
this,
|
|
294
|
+
),
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
functionTypeAnnotation(propertyValueType) {
|
|
299
|
+
return (
|
|
300
|
+
propertyValueType === 'TSFunctionType' ||
|
|
301
|
+
propertyValueType === 'TSMethodSignature'
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
getTypeArgumentParamsFromDeclaration(declaration) {
|
|
305
|
+
return declaration.typeParameters.params;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// This FlowFixMe is supposed to refer to typeArgumentParams and funcArgumentParams of generated AST.
|
|
309
|
+
getNativeComponentType(typeArgumentParams, funcArgumentParams) {
|
|
310
|
+
return {
|
|
311
|
+
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
312
|
+
componentName: funcArgumentParams[0].value,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
getAnnotatedElementProperties(annotatedElement) {
|
|
316
|
+
return annotatedElement.typeAnnotation.members;
|
|
317
|
+
}
|
|
318
|
+
bodyProperties(typeAlias) {
|
|
319
|
+
return typeAlias.body.body;
|
|
320
|
+
}
|
|
321
|
+
convertKeywordToTypeAnnotation(keyword) {
|
|
322
|
+
switch (keyword) {
|
|
323
|
+
case 'TSBooleanKeyword':
|
|
324
|
+
return 'BooleanTypeAnnotation';
|
|
325
|
+
case 'TSNumberKeyword':
|
|
326
|
+
return 'NumberTypeAnnotation';
|
|
327
|
+
case 'TSVoidKeyword':
|
|
328
|
+
return 'VoidTypeAnnotation';
|
|
329
|
+
case 'TSStringKeyword':
|
|
330
|
+
return 'StringTypeAnnotation';
|
|
331
|
+
case 'TSUnknownKeyword':
|
|
332
|
+
return 'MixedTypeAnnotation';
|
|
333
|
+
}
|
|
334
|
+
return keyword;
|
|
335
|
+
}
|
|
252
336
|
}
|
|
253
337
|
module.exports = {
|
|
254
338
|
TypeScriptParser,
|