@react-native/codegen 0.72.2 → 0.72.4
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/parsers/error-utils.js +50 -15
- package/lib/parsers/error-utils.js.flow +57 -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 +27 -126
- package/lib/parsers/flow/components/index.js.flow +22 -52
- 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 -317
- package/lib/parsers/flow/modules/index.js.flow +19 -247
- package/lib/parsers/flow/parser.js +119 -12
- package/lib/parsers/flow/parser.js.flow +124 -3
- package/lib/parsers/flow/utils.js +0 -38
- package/lib/parsers/flow/utils.js.flow +0 -38
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -0
- package/lib/parsers/parserMock.js +58 -0
- package/lib/parsers/parserMock.js.flow +72 -0
- package/lib/parsers/parsers-commons.js +362 -5
- package/lib/parsers/parsers-commons.js.flow +351 -8
- 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/schema.js.flow → schema.js.flow} +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 +28 -127
- package/lib/parsers/typescript/components/index.js.flow +24 -54
- package/lib/parsers/typescript/modules/index.js +103 -434
- package/lib/parsers/typescript/modules/index.js.flow +85 -299
- package/lib/parsers/typescript/parser.js +113 -12
- package/lib/parsers/typescript/parser.js.flow +115 -3
- package/lib/parsers/typescript/utils.js +0 -31
- package/lib/parsers/typescript/utils.js.flow +0 -31
- 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/flow/components/schema.js +0 -106
- package/lib/parsers/flow/components/schema.js.flow +0 -62
- 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
- /package/lib/parsers/{typescript/components/schema.js → schema.js} +0 -0
|
@@ -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,55 +28,33 @@ import type {
|
|
|
30
28
|
const {flattenIntersectionType} = require('../parseTopLevelType');
|
|
31
29
|
const {flattenProperties} = require('../components/componentsUtils');
|
|
32
30
|
|
|
33
|
-
const {
|
|
34
|
-
const {resolveTypeAnnotation, getTypes} = require('../utils');
|
|
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
|
|
|
63
53
|
const {
|
|
64
54
|
UnsupportedGenericParserError,
|
|
65
55
|
UnsupportedTypeAnnotationParserError,
|
|
66
|
-
IncorrectModuleRegistryCallArgumentTypeParserError,
|
|
67
56
|
} = require('../../errors');
|
|
68
57
|
|
|
69
|
-
const {
|
|
70
|
-
throwIfUntypedModule,
|
|
71
|
-
throwIfUnusedModuleInterfaceParserError,
|
|
72
|
-
throwIfModuleInterfaceNotFound,
|
|
73
|
-
throwIfModuleInterfaceIsMisnamed,
|
|
74
|
-
throwIfWrongNumberOfCallExpressionArgs,
|
|
75
|
-
throwIfMoreThanOneModuleRegistryCalls,
|
|
76
|
-
throwIfMoreThanOneModuleInterfaceParserError,
|
|
77
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
78
|
-
} = require('../../error-utils');
|
|
79
|
-
|
|
80
|
-
const language = 'TypeScript';
|
|
81
|
-
|
|
82
58
|
function translateObjectTypeAnnotation(
|
|
83
59
|
hasteModuleName: string,
|
|
84
60
|
/**
|
|
@@ -137,6 +113,74 @@ function translateObjectTypeAnnotation(
|
|
|
137
113
|
);
|
|
138
114
|
}
|
|
139
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
|
+
}
|
|
140
184
|
function translateTypeAnnotation(
|
|
141
185
|
hasteModuleName: string,
|
|
142
186
|
/**
|
|
@@ -194,99 +238,18 @@ function translateTypeAnnotation(
|
|
|
194
238
|
}
|
|
195
239
|
}
|
|
196
240
|
case 'TSTypeReference': {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
enumMap,
|
|
210
|
-
tryParse,
|
|
211
|
-
cxxOnly,
|
|
212
|
-
translateTypeAnnotation,
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
case 'Array':
|
|
216
|
-
case 'ReadonlyArray': {
|
|
217
|
-
return emitArrayType(
|
|
218
|
-
hasteModuleName,
|
|
219
|
-
typeAnnotation,
|
|
220
|
-
parser,
|
|
221
|
-
types,
|
|
222
|
-
aliasMap,
|
|
223
|
-
enumMap,
|
|
224
|
-
cxxOnly,
|
|
225
|
-
nullable,
|
|
226
|
-
translateTypeAnnotation,
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
case 'Stringish': {
|
|
230
|
-
return emitStringish(nullable);
|
|
231
|
-
}
|
|
232
|
-
case 'Int32': {
|
|
233
|
-
return emitInt32(nullable);
|
|
234
|
-
}
|
|
235
|
-
case 'Double': {
|
|
236
|
-
return emitDouble(nullable);
|
|
237
|
-
}
|
|
238
|
-
case 'Float': {
|
|
239
|
-
return emitFloat(nullable);
|
|
240
|
-
}
|
|
241
|
-
case 'UnsafeObject':
|
|
242
|
-
case 'Object': {
|
|
243
|
-
return emitGenericObject(nullable);
|
|
244
|
-
}
|
|
245
|
-
case 'Partial': {
|
|
246
|
-
if (typeAnnotation.typeParameters.params.length !== 1) {
|
|
247
|
-
throw new Error(
|
|
248
|
-
'Partials only support annotating exactly one parameter.',
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const annotatedElement =
|
|
253
|
-
types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
254
|
-
|
|
255
|
-
if (!annotatedElement) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
'Partials only support annotating a type parameter.',
|
|
258
|
-
);
|
|
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,188 +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 isModuleInterface(node: $FlowFixMe) {
|
|
440
|
-
return (
|
|
441
|
-
node.type === 'TSInterfaceDeclaration' &&
|
|
442
|
-
node.extends?.length === 1 &&
|
|
443
|
-
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
444
|
-
node.extends[0].expression.name === 'TurboModule'
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function buildModuleSchema(
|
|
449
|
-
hasteModuleName: string,
|
|
450
|
-
/**
|
|
451
|
-
* TODO(T108222691): Use flow-types for @babel/parser
|
|
452
|
-
*/
|
|
453
|
-
ast: $FlowFixMe,
|
|
454
|
-
tryParse: ParserErrorCapturer,
|
|
455
|
-
parser: Parser,
|
|
456
|
-
): NativeModuleSchema {
|
|
457
|
-
const types = getTypes(ast);
|
|
458
|
-
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
459
|
-
isModuleInterface,
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
throwIfModuleInterfaceNotFound(
|
|
463
|
-
moduleSpecs.length,
|
|
464
|
-
hasteModuleName,
|
|
465
|
-
ast,
|
|
466
|
-
language,
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
throwIfMoreThanOneModuleInterfaceParserError(
|
|
470
|
-
hasteModuleName,
|
|
471
|
-
moduleSpecs,
|
|
472
|
-
language,
|
|
473
|
-
);
|
|
474
|
-
|
|
475
|
-
const [moduleSpec] = moduleSpecs;
|
|
476
|
-
|
|
477
|
-
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
478
|
-
|
|
479
|
-
// Parse Module Name
|
|
480
|
-
const moduleName = ((): string => {
|
|
481
|
-
const callExpressions = [];
|
|
482
|
-
visit(ast, {
|
|
483
|
-
CallExpression(node) {
|
|
484
|
-
if (isModuleRegistryCall(node)) {
|
|
485
|
-
callExpressions.push(node);
|
|
486
|
-
}
|
|
487
|
-
},
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
throwIfUnusedModuleInterfaceParserError(
|
|
491
|
-
hasteModuleName,
|
|
492
|
-
moduleSpec,
|
|
493
|
-
callExpressions,
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
throwIfMoreThanOneModuleRegistryCalls(
|
|
497
|
-
hasteModuleName,
|
|
498
|
-
callExpressions,
|
|
499
|
-
callExpressions.length,
|
|
500
|
-
);
|
|
501
|
-
|
|
502
|
-
const [callExpression] = callExpressions;
|
|
503
|
-
const {typeParameters} = callExpression;
|
|
504
|
-
const methodName = callExpression.callee.property.name;
|
|
505
|
-
|
|
506
|
-
throwIfWrongNumberOfCallExpressionArgs(
|
|
507
|
-
hasteModuleName,
|
|
508
|
-
callExpression,
|
|
509
|
-
methodName,
|
|
510
|
-
callExpression.arguments.length,
|
|
511
|
-
);
|
|
512
|
-
|
|
513
|
-
if (callExpression.arguments[0].type !== 'StringLiteral') {
|
|
514
|
-
const {type} = callExpression.arguments[0];
|
|
515
|
-
throw new IncorrectModuleRegistryCallArgumentTypeParserError(
|
|
516
|
-
hasteModuleName,
|
|
517
|
-
callExpression.arguments[0],
|
|
518
|
-
methodName,
|
|
519
|
-
type,
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
const $moduleName = callExpression.arguments[0].value;
|
|
524
|
-
|
|
525
|
-
throwIfUntypedModule(
|
|
526
|
-
typeParameters,
|
|
527
|
-
hasteModuleName,
|
|
528
|
-
callExpression,
|
|
529
|
-
methodName,
|
|
530
|
-
$moduleName,
|
|
531
|
-
);
|
|
532
|
-
|
|
533
|
-
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
534
|
-
hasteModuleName,
|
|
535
|
-
typeParameters,
|
|
536
|
-
methodName,
|
|
537
|
-
$moduleName,
|
|
538
|
-
parser,
|
|
539
|
-
);
|
|
540
|
-
|
|
541
|
-
return $moduleName;
|
|
542
|
-
})();
|
|
543
|
-
|
|
544
|
-
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
545
|
-
// Eventually this should be made explicit in the Flow type itself.
|
|
546
|
-
// Also check the hasteModuleName for platform suffix.
|
|
547
|
-
// Note: this shape is consistent with ComponentSchema.
|
|
548
|
-
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
549
|
-
hasteModuleName,
|
|
550
|
-
moduleName,
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
// $FlowFixMe[missing-type-arg]
|
|
554
|
-
return (moduleSpec.body.body: $ReadOnlyArray<$FlowFixMe>)
|
|
555
|
-
.filter(
|
|
556
|
-
property =>
|
|
557
|
-
property.type === 'TSMethodSignature' ||
|
|
558
|
-
property.type === 'TSPropertySignature',
|
|
559
|
-
)
|
|
560
|
-
.map<?{
|
|
561
|
-
aliasMap: NativeModuleAliasMap,
|
|
562
|
-
enumMap: NativeModuleEnumMap,
|
|
563
|
-
propertyShape: NativeModulePropertyShape,
|
|
564
|
-
}>(property => {
|
|
565
|
-
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
566
|
-
const enumMap: {...NativeModuleEnumMap} = {};
|
|
567
|
-
|
|
568
|
-
return tryParse(() => ({
|
|
569
|
-
aliasMap: aliasMap,
|
|
570
|
-
enumMap: enumMap,
|
|
571
|
-
propertyShape: buildPropertySchema(
|
|
572
|
-
hasteModuleName,
|
|
573
|
-
property,
|
|
574
|
-
types,
|
|
575
|
-
aliasMap,
|
|
576
|
-
enumMap,
|
|
577
|
-
tryParse,
|
|
578
|
-
cxxOnly,
|
|
579
|
-
resolveTypeAnnotation,
|
|
580
|
-
translateTypeAnnotation,
|
|
581
|
-
parser,
|
|
582
|
-
),
|
|
583
|
-
}));
|
|
584
|
-
})
|
|
585
|
-
.filter(Boolean)
|
|
586
|
-
.reduce(
|
|
587
|
-
(
|
|
588
|
-
moduleSchema: NativeModuleSchema,
|
|
589
|
-
{aliasMap, enumMap, propertyShape},
|
|
590
|
-
) => {
|
|
591
|
-
return {
|
|
592
|
-
type: 'NativeModule',
|
|
593
|
-
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
594
|
-
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
595
|
-
spec: {
|
|
596
|
-
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
597
|
-
},
|
|
598
|
-
moduleName: moduleSchema.moduleName,
|
|
599
|
-
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
600
|
-
};
|
|
601
|
-
},
|
|
602
|
-
{
|
|
603
|
-
type: 'NativeModule',
|
|
604
|
-
aliasMap: {},
|
|
605
|
-
enumMap: {},
|
|
606
|
-
spec: {properties: []},
|
|
607
|
-
moduleName: moduleName,
|
|
608
|
-
excludedPlatforms:
|
|
609
|
-
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
610
|
-
},
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
401
|
module.exports = {
|
|
615
|
-
buildModuleSchema,
|
|
616
402
|
typeScriptTranslateTypeAnnotation: translateTypeAnnotation,
|
|
617
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) {
|
|
@@ -205,6 +213,99 @@ class TypeScriptParser {
|
|
|
205
213
|
};
|
|
206
214
|
});
|
|
207
215
|
}
|
|
216
|
+
isModuleInterface(node) {
|
|
217
|
+
var _node$extends;
|
|
218
|
+
return (
|
|
219
|
+
node.type === 'TSInterfaceDeclaration' &&
|
|
220
|
+
((_node$extends = node.extends) === null || _node$extends === void 0
|
|
221
|
+
? void 0
|
|
222
|
+
: _node$extends.length) === 1 &&
|
|
223
|
+
node.extends[0].type === 'TSExpressionWithTypeArguments' &&
|
|
224
|
+
node.extends[0].expression.name === 'TurboModule'
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
extractAnnotatedElement(typeAnnotation, types) {
|
|
228
|
+
return types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* TODO(T108222691): Use flow-types for @babel/parser
|
|
233
|
+
*/
|
|
234
|
+
getTypes(ast) {
|
|
235
|
+
return ast.body.reduce((types, node) => {
|
|
236
|
+
switch (node.type) {
|
|
237
|
+
case 'ExportNamedDeclaration': {
|
|
238
|
+
if (node.declaration) {
|
|
239
|
+
switch (node.declaration.type) {
|
|
240
|
+
case 'TSTypeAliasDeclaration':
|
|
241
|
+
case 'TSInterfaceDeclaration':
|
|
242
|
+
case 'TSEnumDeclaration': {
|
|
243
|
+
types[node.declaration.id.name] = node.declaration;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case 'TSTypeAliasDeclaration':
|
|
251
|
+
case 'TSInterfaceDeclaration':
|
|
252
|
+
case 'TSEnumDeclaration': {
|
|
253
|
+
types[node.id.name] = node;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return types;
|
|
258
|
+
}, {});
|
|
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
|
+
}
|
|
208
309
|
}
|
|
209
310
|
module.exports = {
|
|
210
311
|
TypeScriptParser,
|