@react-native/codegen 0.72.3 → 0.72.5
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/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/GenerateModuleH.js +1 -1
- package/lib/generators/modules/GenerateModuleH.js.flow +1 -1
- 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 +18 -113
- package/lib/parsers/flow/components/index.js.flow +15 -46
- 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 +41 -307
- package/lib/parsers/flow/modules/index.js.flow +18 -233
- package/lib/parsers/flow/parser.js +68 -12
- package/lib/parsers/flow/parser.js.flow +67 -3
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +65 -3
- package/lib/parsers/parserMock.js +44 -0
- package/lib/parsers/parserMock.js.flow +52 -1
- package/lib/parsers/parsers-commons.js +361 -4
- package/lib/parsers/parsers-commons.js.flow +341 -4
- package/lib/parsers/parsers-primitives.js +119 -3
- package/lib/parsers/parsers-primitives.js.flow +128 -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 +20 -115
- package/lib/parsers/typescript/components/index.js.flow +17 -48
- package/lib/parsers/typescript/modules/index.js +103 -421
- package/lib/parsers/typescript/modules/index.js.flow +84 -285
- package/lib/parsers/typescript/parser.js +69 -12
- package/lib/parsers/typescript/parser.js.flow +68 -3
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +11 -11
- 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,25 @@ 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
37
|
emitBoolean,
|
|
45
|
-
emitDouble,
|
|
46
|
-
emitFloat,
|
|
47
38
|
emitFunction,
|
|
48
39
|
emitNumber,
|
|
49
|
-
emitInt32,
|
|
50
40
|
emitGenericObject,
|
|
51
|
-
emitObject,
|
|
52
41
|
emitPromise,
|
|
53
42
|
emitRootTag,
|
|
54
43
|
emitVoid,
|
|
55
44
|
emitString,
|
|
56
|
-
emitStringish,
|
|
57
45
|
emitMixed,
|
|
58
46
|
emitUnion,
|
|
47
|
+
emitCommonTypes,
|
|
59
48
|
typeAliasResolution,
|
|
49
|
+
typeEnumResolution,
|
|
60
50
|
translateArrayTypeAnnotation,
|
|
61
51
|
} = require('../../parsers-primitives');
|
|
62
52
|
|
|
@@ -65,22 +55,6 @@ const {
|
|
|
65
55
|
UnsupportedTypeAnnotationParserError,
|
|
66
56
|
} = require('../../errors');
|
|
67
57
|
|
|
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
58
|
function translateObjectTypeAnnotation(
|
|
85
59
|
hasteModuleName: string,
|
|
86
60
|
/**
|
|
@@ -139,6 +113,74 @@ function translateObjectTypeAnnotation(
|
|
|
139
113
|
);
|
|
140
114
|
}
|
|
141
115
|
|
|
116
|
+
function translateTypeReferenceAnnotation(
|
|
117
|
+
typeName: string,
|
|
118
|
+
nullable: boolean,
|
|
119
|
+
typeAnnotation: $FlowFixMe,
|
|
120
|
+
hasteModuleName: string,
|
|
121
|
+
types: TypeDeclarationMap,
|
|
122
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
123
|
+
enumMap: {...NativeModuleEnumMap},
|
|
124
|
+
tryParse: ParserErrorCapturer,
|
|
125
|
+
cxxOnly: boolean,
|
|
126
|
+
parser: Parser,
|
|
127
|
+
): Nullable<NativeModuleTypeAnnotation> {
|
|
128
|
+
switch (typeName) {
|
|
129
|
+
case 'RootTag': {
|
|
130
|
+
return emitRootTag(nullable);
|
|
131
|
+
}
|
|
132
|
+
case 'Promise': {
|
|
133
|
+
return emitPromise(
|
|
134
|
+
hasteModuleName,
|
|
135
|
+
typeAnnotation,
|
|
136
|
+
parser,
|
|
137
|
+
nullable,
|
|
138
|
+
types,
|
|
139
|
+
aliasMap,
|
|
140
|
+
enumMap,
|
|
141
|
+
tryParse,
|
|
142
|
+
cxxOnly,
|
|
143
|
+
translateTypeAnnotation,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
case 'Array':
|
|
147
|
+
case 'ReadonlyArray': {
|
|
148
|
+
return emitArrayType(
|
|
149
|
+
hasteModuleName,
|
|
150
|
+
typeAnnotation,
|
|
151
|
+
parser,
|
|
152
|
+
types,
|
|
153
|
+
aliasMap,
|
|
154
|
+
enumMap,
|
|
155
|
+
cxxOnly,
|
|
156
|
+
nullable,
|
|
157
|
+
translateTypeAnnotation,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
const commonType = emitCommonTypes(
|
|
162
|
+
hasteModuleName,
|
|
163
|
+
types,
|
|
164
|
+
typeAnnotation,
|
|
165
|
+
aliasMap,
|
|
166
|
+
enumMap,
|
|
167
|
+
tryParse,
|
|
168
|
+
cxxOnly,
|
|
169
|
+
nullable,
|
|
170
|
+
parser,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
if (!commonType) {
|
|
174
|
+
throw new UnsupportedGenericParserError(
|
|
175
|
+
hasteModuleName,
|
|
176
|
+
typeAnnotation,
|
|
177
|
+
parser,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return commonType;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
142
184
|
function translateTypeAnnotation(
|
|
143
185
|
hasteModuleName: string,
|
|
144
186
|
/**
|
|
@@ -196,97 +238,18 @@ function translateTypeAnnotation(
|
|
|
196
238
|
}
|
|
197
239
|
}
|
|
198
240
|
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
|
-
}
|
|
241
|
+
return translateTypeReferenceAnnotation(
|
|
242
|
+
typeAnnotation.typeName.name,
|
|
243
|
+
nullable,
|
|
244
|
+
typeAnnotation,
|
|
245
|
+
hasteModuleName,
|
|
246
|
+
types,
|
|
247
|
+
aliasMap,
|
|
248
|
+
enumMap,
|
|
249
|
+
tryParse,
|
|
250
|
+
cxxOnly,
|
|
251
|
+
parser,
|
|
252
|
+
);
|
|
290
253
|
}
|
|
291
254
|
case 'TSInterfaceDeclaration': {
|
|
292
255
|
const baseTypes = (typeAnnotation.extends ?? []).map(
|
|
@@ -386,7 +349,6 @@ function translateTypeAnnotation(
|
|
|
386
349
|
typeResolutionStatus,
|
|
387
350
|
nullable,
|
|
388
351
|
hasteModuleName,
|
|
389
|
-
language,
|
|
390
352
|
enumMap,
|
|
391
353
|
parser,
|
|
392
354
|
);
|
|
@@ -430,175 +392,12 @@ function translateTypeAnnotation(
|
|
|
430
392
|
throw new UnsupportedTypeAnnotationParserError(
|
|
431
393
|
hasteModuleName,
|
|
432
394
|
typeAnnotation,
|
|
433
|
-
language,
|
|
395
|
+
parser.language(),
|
|
434
396
|
);
|
|
435
397
|
}
|
|
436
398
|
}
|
|
437
399
|
}
|
|
438
400
|
|
|
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
|
-
|
|
528
|
-
return $moduleName;
|
|
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(
|
|
559
|
-
hasteModuleName,
|
|
560
|
-
property,
|
|
561
|
-
types,
|
|
562
|
-
aliasMap,
|
|
563
|
-
enumMap,
|
|
564
|
-
tryParse,
|
|
565
|
-
cxxOnly,
|
|
566
|
-
resolveTypeAnnotation,
|
|
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
|
-
);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
401
|
module.exports = {
|
|
602
|
-
buildModuleSchema,
|
|
603
402
|
typeScriptTranslateTypeAnnotation: translateTypeAnnotation,
|
|
604
403
|
};
|
|
@@ -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(
|
|
@@ -113,6 +119,8 @@ class TypeScriptParser {
|
|
|
113
119
|
buildModuleSchema,
|
|
114
120
|
Visitor,
|
|
115
121
|
this,
|
|
122
|
+
resolveTypeAnnotation,
|
|
123
|
+
typeScriptTranslateTypeAnnotation,
|
|
116
124
|
);
|
|
117
125
|
}
|
|
118
126
|
parseModuleFixture(filename) {
|
|
@@ -249,6 +257,55 @@ class TypeScriptParser {
|
|
|
249
257
|
return types;
|
|
250
258
|
}, {});
|
|
251
259
|
}
|
|
260
|
+
callExpressionTypeParameters(callExpression) {
|
|
261
|
+
return callExpression.typeParameters || null;
|
|
262
|
+
}
|
|
263
|
+
computePartialProperties(
|
|
264
|
+
properties,
|
|
265
|
+
hasteModuleName,
|
|
266
|
+
types,
|
|
267
|
+
aliasMap,
|
|
268
|
+
enumMap,
|
|
269
|
+
tryParse,
|
|
270
|
+
cxxOnly,
|
|
271
|
+
) {
|
|
272
|
+
return properties.map(prop => {
|
|
273
|
+
return {
|
|
274
|
+
name: prop.key.name,
|
|
275
|
+
optional: true,
|
|
276
|
+
typeAnnotation: typeScriptTranslateTypeAnnotation(
|
|
277
|
+
hasteModuleName,
|
|
278
|
+
prop.typeAnnotation.typeAnnotation,
|
|
279
|
+
types,
|
|
280
|
+
aliasMap,
|
|
281
|
+
enumMap,
|
|
282
|
+
tryParse,
|
|
283
|
+
cxxOnly,
|
|
284
|
+
this,
|
|
285
|
+
),
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
functionTypeAnnotation(propertyValueType) {
|
|
290
|
+
return (
|
|
291
|
+
propertyValueType === 'TSFunctionType' ||
|
|
292
|
+
propertyValueType === 'TSMethodSignature'
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
getTypeArgumentParamsFromDeclaration(declaration) {
|
|
296
|
+
return declaration.typeParameters.params;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// This FlowFixMe is supposed to refer to typeArgumentParams and funcArgumentParams of generated AST.
|
|
300
|
+
getNativeComponentType(typeArgumentParams, funcArgumentParams) {
|
|
301
|
+
return {
|
|
302
|
+
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
303
|
+
componentName: funcArgumentParams[0].value,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
getAnnotatedElementProperties(annotatedElement) {
|
|
307
|
+
return annotatedElement.typeAnnotation.members;
|
|
308
|
+
}
|
|
252
309
|
}
|
|
253
310
|
module.exports = {
|
|
254
311
|
TypeScriptParser,
|
|
@@ -18,19 +18,24 @@ import type {
|
|
|
18
18
|
NativeModuleParamTypeAnnotation,
|
|
19
19
|
NativeModuleEnumMembers,
|
|
20
20
|
NativeModuleEnumMemberType,
|
|
21
|
+
NativeModuleAliasMap,
|
|
22
|
+
NativeModuleEnumMap,
|
|
21
23
|
} from '../../CodegenSchema';
|
|
22
24
|
import type {ParserType} from '../errors';
|
|
23
25
|
import type {Parser} from '../parser';
|
|
24
|
-
import type {TypeDeclarationMap} from '../utils';
|
|
26
|
+
import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
|
|
27
|
+
|
|
28
|
+
const {typeScriptTranslateTypeAnnotation} = require('./modules');
|
|
25
29
|
|
|
26
30
|
// $FlowFixMe[untyped-import] Use flow-types for @babel/parser
|
|
27
31
|
const babelParser = require('@babel/parser');
|
|
28
32
|
|
|
29
33
|
const {buildSchema} = require('../parsers-commons');
|
|
30
|
-
const {Visitor} = require('
|
|
34
|
+
const {Visitor} = require('../parsers-primitives');
|
|
31
35
|
const {buildComponentSchema} = require('./components');
|
|
32
36
|
const {wrapComponentSchema} = require('../schema.js');
|
|
33
|
-
const {buildModuleSchema} = require('
|
|
37
|
+
const {buildModuleSchema} = require('../parsers-commons.js');
|
|
38
|
+
const {resolveTypeAnnotation} = require('./utils');
|
|
34
39
|
|
|
35
40
|
const fs = require('fs');
|
|
36
41
|
|
|
@@ -103,6 +108,8 @@ class TypeScriptParser implements Parser {
|
|
|
103
108
|
buildModuleSchema,
|
|
104
109
|
Visitor,
|
|
105
110
|
this,
|
|
111
|
+
resolveTypeAnnotation,
|
|
112
|
+
typeScriptTranslateTypeAnnotation,
|
|
106
113
|
);
|
|
107
114
|
}
|
|
108
115
|
|
|
@@ -239,7 +246,65 @@ class TypeScriptParser implements Parser {
|
|
|
239
246
|
return types;
|
|
240
247
|
}, {});
|
|
241
248
|
}
|
|
249
|
+
|
|
250
|
+
callExpressionTypeParameters(callExpression: $FlowFixMe): $FlowFixMe | null {
|
|
251
|
+
return callExpression.typeParameters || null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
computePartialProperties(
|
|
255
|
+
properties: Array<$FlowFixMe>,
|
|
256
|
+
hasteModuleName: string,
|
|
257
|
+
types: TypeDeclarationMap,
|
|
258
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
259
|
+
enumMap: {...NativeModuleEnumMap},
|
|
260
|
+
tryParse: ParserErrorCapturer,
|
|
261
|
+
cxxOnly: boolean,
|
|
262
|
+
): Array<$FlowFixMe> {
|
|
263
|
+
return properties.map(prop => {
|
|
264
|
+
return {
|
|
265
|
+
name: prop.key.name,
|
|
266
|
+
optional: true,
|
|
267
|
+
typeAnnotation: typeScriptTranslateTypeAnnotation(
|
|
268
|
+
hasteModuleName,
|
|
269
|
+
prop.typeAnnotation.typeAnnotation,
|
|
270
|
+
types,
|
|
271
|
+
aliasMap,
|
|
272
|
+
enumMap,
|
|
273
|
+
tryParse,
|
|
274
|
+
cxxOnly,
|
|
275
|
+
this,
|
|
276
|
+
),
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
functionTypeAnnotation(propertyValueType: string): boolean {
|
|
282
|
+
return (
|
|
283
|
+
propertyValueType === 'TSFunctionType' ||
|
|
284
|
+
propertyValueType === 'TSMethodSignature'
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
getTypeArgumentParamsFromDeclaration(declaration: $FlowFixMe): $FlowFixMe {
|
|
289
|
+
return declaration.typeParameters.params;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// This FlowFixMe is supposed to refer to typeArgumentParams and funcArgumentParams of generated AST.
|
|
293
|
+
getNativeComponentType(
|
|
294
|
+
typeArgumentParams: $FlowFixMe,
|
|
295
|
+
funcArgumentParams: $FlowFixMe,
|
|
296
|
+
): {[string]: string} {
|
|
297
|
+
return {
|
|
298
|
+
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
299
|
+
componentName: funcArgumentParams[0].value,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
|
|
304
|
+
return annotatedElement.typeAnnotation.members;
|
|
305
|
+
}
|
|
242
306
|
}
|
|
307
|
+
|
|
243
308
|
module.exports = {
|
|
244
309
|
TypeScriptParser,
|
|
245
310
|
};
|
package/lib/parsers/utils.js
CHANGED
|
@@ -19,6 +19,7 @@ function extractNativeModuleName(filename) {
|
|
|
19
19
|
return path.basename(filename).split('.')[0];
|
|
20
20
|
}
|
|
21
21
|
function createParserErrorCapturer() {
|
|
22
|
+
// $FlowFixMe[missing-empty-array-annot]
|
|
22
23
|
const errors = [];
|
|
23
24
|
function guard(fn) {
|
|
24
25
|
try {
|
|
@@ -27,10 +28,13 @@ function createParserErrorCapturer() {
|
|
|
27
28
|
if (!(error instanceof ParserError)) {
|
|
28
29
|
throw error;
|
|
29
30
|
}
|
|
31
|
+
// $FlowFixMe[incompatible-call]
|
|
30
32
|
errors.push(error);
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
// $FlowFixMe[incompatible-return]
|
|
34
38
|
return [errors, guard];
|
|
35
39
|
}
|
|
36
40
|
function verifyPlatforms(hasteModuleName, moduleName) {
|
|
@@ -38,6 +38,7 @@ function createParserErrorCapturer(): [
|
|
|
38
38
|
Array<ParserError>,
|
|
39
39
|
ParserErrorCapturer,
|
|
40
40
|
] {
|
|
41
|
+
// $FlowFixMe[missing-empty-array-annot]
|
|
41
42
|
const errors = [];
|
|
42
43
|
function guard<T>(fn: () => T): ?T {
|
|
43
44
|
try {
|
|
@@ -46,12 +47,14 @@ function createParserErrorCapturer(): [
|
|
|
46
47
|
if (!(error instanceof ParserError)) {
|
|
47
48
|
throw error;
|
|
48
49
|
}
|
|
50
|
+
// $FlowFixMe[incompatible-call]
|
|
49
51
|
errors.push(error);
|
|
50
52
|
|
|
51
53
|
return null;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
// $FlowFixMe[incompatible-return]
|
|
55
58
|
return [errors, guard];
|
|
56
59
|
}
|
|
57
60
|
|