@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
|
@@ -21,24 +21,37 @@ import type {
|
|
|
21
21
|
NativeModuleParamTypeAnnotation,
|
|
22
22
|
NativeModulePropertyShape,
|
|
23
23
|
SchemaType,
|
|
24
|
+
NativeModuleEnumMap,
|
|
25
|
+
OptionsShape,
|
|
24
26
|
} from '../CodegenSchema.js';
|
|
25
27
|
|
|
26
28
|
import type {Parser} from './parser';
|
|
27
29
|
import type {ParserType} from './errors';
|
|
28
30
|
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
|
|
29
|
-
import type {ComponentSchemaBuilderConfig} from './
|
|
31
|
+
import type {ComponentSchemaBuilderConfig} from './schema.js';
|
|
30
32
|
|
|
31
33
|
const {
|
|
32
34
|
getConfigType,
|
|
33
35
|
extractNativeModuleName,
|
|
34
36
|
createParserErrorCapturer,
|
|
37
|
+
visit,
|
|
38
|
+
isModuleRegistryCall,
|
|
39
|
+
verifyPlatforms,
|
|
35
40
|
} = require('./utils');
|
|
36
|
-
|
|
37
41
|
const {
|
|
38
42
|
throwIfPropertyValueTypeIsUnsupported,
|
|
39
43
|
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
40
44
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
41
45
|
throwIfModuleTypeIsUnsupported,
|
|
46
|
+
throwIfUnusedModuleInterfaceParserError,
|
|
47
|
+
throwIfMoreThanOneModuleRegistryCalls,
|
|
48
|
+
throwIfWrongNumberOfCallExpressionArgs,
|
|
49
|
+
throwIfUntypedModule,
|
|
50
|
+
throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
51
|
+
throwIfIncorrectModuleRegistryCallArgument,
|
|
52
|
+
throwIfModuleInterfaceNotFound,
|
|
53
|
+
throwIfMoreThanOneModuleInterfaceParserError,
|
|
54
|
+
throwIfModuleInterfaceIsMisnamed,
|
|
42
55
|
} = require('./error-utils');
|
|
43
56
|
|
|
44
57
|
const {
|
|
@@ -48,7 +61,13 @@ const {
|
|
|
48
61
|
} = require('./errors');
|
|
49
62
|
|
|
50
63
|
const invariant = require('invariant');
|
|
51
|
-
|
|
64
|
+
|
|
65
|
+
export type CommandOptions = $ReadOnly<{
|
|
66
|
+
supportedCommands: $ReadOnlyArray<string>,
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
|
|
70
|
+
type OptionsAST = Object;
|
|
52
71
|
|
|
53
72
|
function wrapModuleSchema(
|
|
54
73
|
nativeModuleSchema: NativeModuleSchema,
|
|
@@ -317,7 +336,7 @@ function buildPropertySchema(
|
|
|
317
336
|
property.value,
|
|
318
337
|
key.name,
|
|
319
338
|
value.type,
|
|
320
|
-
parser
|
|
339
|
+
parser,
|
|
321
340
|
);
|
|
322
341
|
|
|
323
342
|
return {
|
|
@@ -345,18 +364,25 @@ function buildSchemaFromConfigType(
|
|
|
345
364
|
filename: ?string,
|
|
346
365
|
ast: $FlowFixMe,
|
|
347
366
|
wrapComponentSchema: (config: ComponentSchemaBuilderConfig) => SchemaType,
|
|
348
|
-
buildComponentSchema: (
|
|
367
|
+
buildComponentSchema: (
|
|
368
|
+
ast: $FlowFixMe,
|
|
369
|
+
parser: Parser,
|
|
370
|
+
) => ComponentSchemaBuilderConfig,
|
|
349
371
|
buildModuleSchema: (
|
|
350
372
|
hasteModuleName: string,
|
|
351
373
|
ast: $FlowFixMe,
|
|
352
374
|
tryParse: ParserErrorCapturer,
|
|
353
375
|
parser: Parser,
|
|
376
|
+
resolveTypeAnnotation: $FlowFixMe,
|
|
377
|
+
translateTypeAnnotation: $FlowFixMe,
|
|
354
378
|
) => NativeModuleSchema,
|
|
355
379
|
parser: Parser,
|
|
380
|
+
resolveTypeAnnotation: $FlowFixMe,
|
|
381
|
+
translateTypeAnnotation: $FlowFixMe,
|
|
356
382
|
): SchemaType {
|
|
357
383
|
switch (configType) {
|
|
358
384
|
case 'component': {
|
|
359
|
-
return wrapComponentSchema(buildComponentSchema(ast));
|
|
385
|
+
return wrapComponentSchema(buildComponentSchema(ast, parser));
|
|
360
386
|
}
|
|
361
387
|
case 'module': {
|
|
362
388
|
if (filename === undefined || filename === null) {
|
|
@@ -367,7 +393,14 @@ function buildSchemaFromConfigType(
|
|
|
367
393
|
const [parsingErrors, tryParse] = createParserErrorCapturer();
|
|
368
394
|
|
|
369
395
|
const schema = tryParse(() =>
|
|
370
|
-
buildModuleSchema(
|
|
396
|
+
buildModuleSchema(
|
|
397
|
+
nativeModuleName,
|
|
398
|
+
ast,
|
|
399
|
+
tryParse,
|
|
400
|
+
parser,
|
|
401
|
+
resolveTypeAnnotation,
|
|
402
|
+
translateTypeAnnotation,
|
|
403
|
+
),
|
|
371
404
|
);
|
|
372
405
|
|
|
373
406
|
if (parsingErrors.length > 0) {
|
|
@@ -398,17 +431,24 @@ function buildSchema(
|
|
|
398
431
|
contents: string,
|
|
399
432
|
filename: ?string,
|
|
400
433
|
wrapComponentSchema: (config: ComponentSchemaBuilderConfig) => SchemaType,
|
|
401
|
-
buildComponentSchema: (
|
|
434
|
+
buildComponentSchema: (
|
|
435
|
+
ast: $FlowFixMe,
|
|
436
|
+
parser: Parser,
|
|
437
|
+
) => ComponentSchemaBuilderConfig,
|
|
402
438
|
buildModuleSchema: (
|
|
403
439
|
hasteModuleName: string,
|
|
404
440
|
ast: $FlowFixMe,
|
|
405
441
|
tryParse: ParserErrorCapturer,
|
|
406
442
|
parser: Parser,
|
|
443
|
+
resolveTypeAnnotation: $FlowFixMe,
|
|
444
|
+
translateTypeAnnotation: $FlowFixMe,
|
|
407
445
|
) => NativeModuleSchema,
|
|
408
446
|
Visitor: ({isComponent: boolean, isModule: boolean}) => {
|
|
409
447
|
[type: string]: (node: $FlowFixMe) => void,
|
|
410
448
|
},
|
|
411
449
|
parser: Parser,
|
|
450
|
+
resolveTypeAnnotation: $FlowFixMe,
|
|
451
|
+
translateTypeAnnotation: $FlowFixMe,
|
|
412
452
|
): SchemaType {
|
|
413
453
|
// Early return for non-Spec JavaScript files
|
|
414
454
|
if (
|
|
@@ -429,7 +469,304 @@ function buildSchema(
|
|
|
429
469
|
buildComponentSchema,
|
|
430
470
|
buildModuleSchema,
|
|
431
471
|
parser,
|
|
472
|
+
resolveTypeAnnotation,
|
|
473
|
+
translateTypeAnnotation,
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function createComponentConfig(
|
|
478
|
+
foundConfig: $FlowFixMe,
|
|
479
|
+
commandsTypeNames: $FlowFixMe,
|
|
480
|
+
): $FlowFixMe {
|
|
481
|
+
return {
|
|
482
|
+
...foundConfig,
|
|
483
|
+
commandTypeName:
|
|
484
|
+
commandsTypeNames[0] == null
|
|
485
|
+
? null
|
|
486
|
+
: commandsTypeNames[0].commandTypeName,
|
|
487
|
+
commandOptionsExpression:
|
|
488
|
+
commandsTypeNames[0] == null
|
|
489
|
+
? null
|
|
490
|
+
: commandsTypeNames[0].commandOptionsExpression,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const parseModuleName = (
|
|
495
|
+
hasteModuleName: string,
|
|
496
|
+
moduleSpec: $FlowFixMe,
|
|
497
|
+
ast: $FlowFixMe,
|
|
498
|
+
parser: Parser,
|
|
499
|
+
): string => {
|
|
500
|
+
const callExpressions = [];
|
|
501
|
+
visit(ast, {
|
|
502
|
+
CallExpression(node) {
|
|
503
|
+
if (isModuleRegistryCall(node)) {
|
|
504
|
+
callExpressions.push(node);
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
throwIfUnusedModuleInterfaceParserError(
|
|
510
|
+
hasteModuleName,
|
|
511
|
+
moduleSpec,
|
|
512
|
+
callExpressions,
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
throwIfMoreThanOneModuleRegistryCalls(
|
|
516
|
+
hasteModuleName,
|
|
517
|
+
callExpressions,
|
|
518
|
+
callExpressions.length,
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
const [callExpression] = callExpressions;
|
|
522
|
+
const typeParameters = parser.callExpressionTypeParameters(callExpression);
|
|
523
|
+
const methodName = callExpression.callee.property.name;
|
|
524
|
+
|
|
525
|
+
throwIfWrongNumberOfCallExpressionArgs(
|
|
526
|
+
hasteModuleName,
|
|
527
|
+
callExpression,
|
|
528
|
+
methodName,
|
|
529
|
+
callExpression.arguments.length,
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
533
|
+
hasteModuleName,
|
|
534
|
+
callExpression.arguments[0],
|
|
535
|
+
methodName,
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
const $moduleName = callExpression.arguments[0].value;
|
|
539
|
+
|
|
540
|
+
throwIfUntypedModule(
|
|
541
|
+
typeParameters,
|
|
542
|
+
hasteModuleName,
|
|
543
|
+
callExpression,
|
|
544
|
+
methodName,
|
|
545
|
+
$moduleName,
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
549
|
+
hasteModuleName,
|
|
550
|
+
typeParameters,
|
|
551
|
+
methodName,
|
|
552
|
+
$moduleName,
|
|
553
|
+
parser,
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
return $moduleName;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const buildModuleSchema = (
|
|
560
|
+
hasteModuleName: string,
|
|
561
|
+
/**
|
|
562
|
+
* TODO(T71778680): Flow-type this node.
|
|
563
|
+
*/
|
|
564
|
+
ast: $FlowFixMe,
|
|
565
|
+
tryParse: ParserErrorCapturer,
|
|
566
|
+
parser: Parser,
|
|
567
|
+
resolveTypeAnnotation: $FlowFixMe,
|
|
568
|
+
translateTypeAnnotation: $FlowFixMe,
|
|
569
|
+
): NativeModuleSchema => {
|
|
570
|
+
const language = parser.language();
|
|
571
|
+
const types = parser.getTypes(ast);
|
|
572
|
+
const moduleSpecs = (Object.values(types): $ReadOnlyArray<$FlowFixMe>).filter(
|
|
573
|
+
t => parser.isModuleInterface(t),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
throwIfModuleInterfaceNotFound(
|
|
577
|
+
moduleSpecs.length,
|
|
578
|
+
hasteModuleName,
|
|
579
|
+
ast,
|
|
580
|
+
language,
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
throwIfMoreThanOneModuleInterfaceParserError(
|
|
584
|
+
hasteModuleName,
|
|
585
|
+
moduleSpecs,
|
|
586
|
+
language,
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
const [moduleSpec] = moduleSpecs;
|
|
590
|
+
|
|
591
|
+
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
592
|
+
|
|
593
|
+
// Parse Module Name
|
|
594
|
+
const moduleName = parseModuleName(hasteModuleName, moduleSpec, ast, parser);
|
|
595
|
+
|
|
596
|
+
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
597
|
+
// Eventually this should be made explicit in the Flow type itself.
|
|
598
|
+
// Also check the hasteModuleName for platform suffix.
|
|
599
|
+
// Note: this shape is consistent with ComponentSchema.
|
|
600
|
+
const {cxxOnly, excludedPlatforms} = verifyPlatforms(
|
|
601
|
+
hasteModuleName,
|
|
602
|
+
moduleName,
|
|
432
603
|
);
|
|
604
|
+
|
|
605
|
+
const properties: $ReadOnlyArray<$FlowFixMe> =
|
|
606
|
+
language === 'Flow' ? moduleSpec.body.properties : moduleSpec.body.body;
|
|
607
|
+
|
|
608
|
+
// $FlowFixMe[missing-type-arg]
|
|
609
|
+
return properties
|
|
610
|
+
.filter(
|
|
611
|
+
property =>
|
|
612
|
+
property.type === 'ObjectTypeProperty' ||
|
|
613
|
+
property.type === 'TSPropertySignature' ||
|
|
614
|
+
property.type === 'TSMethodSignature',
|
|
615
|
+
)
|
|
616
|
+
.map<?{
|
|
617
|
+
aliasMap: NativeModuleAliasMap,
|
|
618
|
+
enumMap: NativeModuleEnumMap,
|
|
619
|
+
propertyShape: NativeModulePropertyShape,
|
|
620
|
+
}>(property => {
|
|
621
|
+
const aliasMap: {...NativeModuleAliasMap} = {};
|
|
622
|
+
const enumMap: {...NativeModuleEnumMap} = {};
|
|
623
|
+
|
|
624
|
+
return tryParse(() => ({
|
|
625
|
+
aliasMap,
|
|
626
|
+
enumMap,
|
|
627
|
+
propertyShape: buildPropertySchema(
|
|
628
|
+
hasteModuleName,
|
|
629
|
+
property,
|
|
630
|
+
types,
|
|
631
|
+
aliasMap,
|
|
632
|
+
enumMap,
|
|
633
|
+
tryParse,
|
|
634
|
+
cxxOnly,
|
|
635
|
+
resolveTypeAnnotation,
|
|
636
|
+
translateTypeAnnotation,
|
|
637
|
+
parser,
|
|
638
|
+
),
|
|
639
|
+
}));
|
|
640
|
+
})
|
|
641
|
+
.filter(Boolean)
|
|
642
|
+
.reduce(
|
|
643
|
+
(
|
|
644
|
+
moduleSchema: NativeModuleSchema,
|
|
645
|
+
{aliasMap, enumMap, propertyShape},
|
|
646
|
+
) => ({
|
|
647
|
+
type: 'NativeModule',
|
|
648
|
+
aliasMap: {...moduleSchema.aliasMap, ...aliasMap},
|
|
649
|
+
enumMap: {...moduleSchema.enumMap, ...enumMap},
|
|
650
|
+
spec: {
|
|
651
|
+
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
652
|
+
},
|
|
653
|
+
moduleName: moduleSchema.moduleName,
|
|
654
|
+
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
655
|
+
}),
|
|
656
|
+
{
|
|
657
|
+
type: 'NativeModule',
|
|
658
|
+
aliasMap: {},
|
|
659
|
+
enumMap: {},
|
|
660
|
+
spec: {properties: []},
|
|
661
|
+
moduleName,
|
|
662
|
+
excludedPlatforms:
|
|
663
|
+
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
664
|
+
},
|
|
665
|
+
);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* This function is used to find the type of a native component
|
|
670
|
+
* provided the default exports statement from generated AST.
|
|
671
|
+
* @param statement The statement to be parsed.
|
|
672
|
+
* @param foundConfigs The 'mutable' array of configs that have been found.
|
|
673
|
+
* @param parser The language parser to be used.
|
|
674
|
+
* @returns void
|
|
675
|
+
*/
|
|
676
|
+
function findNativeComponentType(
|
|
677
|
+
statement: $FlowFixMe,
|
|
678
|
+
foundConfigs: Array<{[string]: string}>,
|
|
679
|
+
parser: Parser,
|
|
680
|
+
): void {
|
|
681
|
+
let declaration = statement.declaration;
|
|
682
|
+
|
|
683
|
+
// codegenNativeComponent can be nested inside a cast
|
|
684
|
+
// expression so we need to go one level deeper
|
|
685
|
+
if (
|
|
686
|
+
declaration.type === 'TSAsExpression' ||
|
|
687
|
+
declaration.type === 'TypeCastExpression'
|
|
688
|
+
) {
|
|
689
|
+
declaration = declaration.expression;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
try {
|
|
693
|
+
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
694
|
+
const typeArgumentParams =
|
|
695
|
+
parser.getTypeArgumentParamsFromDeclaration(declaration);
|
|
696
|
+
const funcArgumentParams = declaration.arguments;
|
|
697
|
+
|
|
698
|
+
const nativeComponentType: {[string]: string} =
|
|
699
|
+
parser.getNativeComponentType(typeArgumentParams, funcArgumentParams);
|
|
700
|
+
if (funcArgumentParams.length > 1) {
|
|
701
|
+
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
702
|
+
}
|
|
703
|
+
foundConfigs.push(nativeComponentType);
|
|
704
|
+
}
|
|
705
|
+
} catch (e) {
|
|
706
|
+
// ignore
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function getCommandOptions(
|
|
711
|
+
commandOptionsExpression: OptionsAST,
|
|
712
|
+
): ?CommandOptions {
|
|
713
|
+
if (commandOptionsExpression == null) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
let foundOptions;
|
|
718
|
+
try {
|
|
719
|
+
foundOptions = commandOptionsExpression.properties.reduce(
|
|
720
|
+
(options, prop) => {
|
|
721
|
+
options[prop.key.name] = (
|
|
722
|
+
(prop && prop.value && prop.value.elements) ||
|
|
723
|
+
[]
|
|
724
|
+
).map(element => element && element.value);
|
|
725
|
+
return options;
|
|
726
|
+
},
|
|
727
|
+
{},
|
|
728
|
+
);
|
|
729
|
+
} catch (e) {
|
|
730
|
+
throw new Error(
|
|
731
|
+
'Failed to parse command options, please check that they are defined correctly',
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
return foundOptions;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function getOptions(optionsExpression: OptionsAST): ?OptionsShape {
|
|
739
|
+
if (!optionsExpression) {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
let foundOptions;
|
|
743
|
+
try {
|
|
744
|
+
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
745
|
+
if (prop.value.type === 'ArrayExpression') {
|
|
746
|
+
options[prop.key.name] = prop.value.elements.map(
|
|
747
|
+
element => element.value,
|
|
748
|
+
);
|
|
749
|
+
} else {
|
|
750
|
+
options[prop.key.name] = prop.value.value;
|
|
751
|
+
}
|
|
752
|
+
return options;
|
|
753
|
+
}, {});
|
|
754
|
+
} catch (e) {
|
|
755
|
+
throw new Error(
|
|
756
|
+
'Failed to parse codegen options, please check that they are defined correctly',
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
if (
|
|
761
|
+
foundOptions.paperComponentName &&
|
|
762
|
+
foundOptions.paperComponentNameDeprecated
|
|
763
|
+
) {
|
|
764
|
+
throw new Error(
|
|
765
|
+
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return foundOptions;
|
|
433
770
|
}
|
|
434
771
|
|
|
435
772
|
module.exports = {
|
|
@@ -443,4 +780,10 @@ module.exports = {
|
|
|
443
780
|
buildPropertySchema,
|
|
444
781
|
buildSchemaFromConfigType,
|
|
445
782
|
buildSchema,
|
|
783
|
+
createComponentConfig,
|
|
784
|
+
parseModuleName,
|
|
785
|
+
buildModuleSchema,
|
|
786
|
+
findNativeComponentType,
|
|
787
|
+
getCommandOptions,
|
|
788
|
+
getOptions,
|
|
446
789
|
};
|
|
@@ -86,7 +86,10 @@ const _require = require('./errors'),
|
|
|
86
86
|
ParserError = _require.ParserError;
|
|
87
87
|
const _require2 = require('./error-utils'),
|
|
88
88
|
throwIfArrayElementTypeAnnotationIsUnsupported =
|
|
89
|
-
_require2.throwIfArrayElementTypeAnnotationIsUnsupported
|
|
89
|
+
_require2.throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
90
|
+
throwIfPartialNotAnnotatingTypeParameter =
|
|
91
|
+
_require2.throwIfPartialNotAnnotatingTypeParameter,
|
|
92
|
+
throwIfPartialWithMoreParameter = _require2.throwIfPartialWithMoreParameter;
|
|
90
93
|
const _require3 = require('./parsers-utils'),
|
|
91
94
|
nullGuard = _require3.nullGuard;
|
|
92
95
|
const _require4 = require('./parsers-commons'),
|
|
@@ -95,6 +98,8 @@ const _require4 = require('./parsers-commons'),
|
|
|
95
98
|
wrapNullable = _require4.wrapNullable,
|
|
96
99
|
unwrapNullable = _require4.unwrapNullable,
|
|
97
100
|
translateFunctionTypeAnnotation = _require4.translateFunctionTypeAnnotation;
|
|
101
|
+
const _require5 = require('./utils'),
|
|
102
|
+
isModuleRegistryCall = _require5.isModuleRegistryCall;
|
|
98
103
|
function emitBoolean(nullable) {
|
|
99
104
|
return wrapNullable(nullable, {
|
|
100
105
|
type: 'BooleanTypeAnnotation',
|
|
@@ -220,7 +225,6 @@ function typeEnumResolution(
|
|
|
220
225
|
typeResolution,
|
|
221
226
|
nullable,
|
|
222
227
|
hasteModuleName,
|
|
223
|
-
language,
|
|
224
228
|
enumMap,
|
|
225
229
|
parser,
|
|
226
230
|
) {
|
|
@@ -228,7 +232,7 @@ function typeEnumResolution(
|
|
|
228
232
|
throw new UnsupportedTypeAnnotationParserError(
|
|
229
233
|
hasteModuleName,
|
|
230
234
|
typeAnnotation,
|
|
231
|
-
language,
|
|
235
|
+
parser.language(),
|
|
232
236
|
);
|
|
233
237
|
}
|
|
234
238
|
const enumName = typeResolution.name;
|
|
@@ -427,6 +431,115 @@ function emitArrayType(
|
|
|
427
431
|
parser,
|
|
428
432
|
);
|
|
429
433
|
}
|
|
434
|
+
function Visitor(infoMap) {
|
|
435
|
+
return {
|
|
436
|
+
CallExpression(node) {
|
|
437
|
+
if (
|
|
438
|
+
node.callee.type === 'Identifier' &&
|
|
439
|
+
node.callee.name === 'codegenNativeComponent'
|
|
440
|
+
) {
|
|
441
|
+
infoMap.isComponent = true;
|
|
442
|
+
}
|
|
443
|
+
if (isModuleRegistryCall(node)) {
|
|
444
|
+
infoMap.isModule = true;
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
InterfaceExtends(node) {
|
|
448
|
+
if (node.id.name === 'TurboModule') {
|
|
449
|
+
infoMap.isModule = true;
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
TSInterfaceDeclaration(node) {
|
|
453
|
+
if (
|
|
454
|
+
Array.isArray(node.extends) &&
|
|
455
|
+
node.extends.some(
|
|
456
|
+
extension => extension.expression.name === 'TurboModule',
|
|
457
|
+
)
|
|
458
|
+
) {
|
|
459
|
+
infoMap.isModule = true;
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function emitPartial(
|
|
465
|
+
hasteModuleName,
|
|
466
|
+
typeAnnotation,
|
|
467
|
+
types,
|
|
468
|
+
aliasMap,
|
|
469
|
+
enumMap,
|
|
470
|
+
tryParse,
|
|
471
|
+
cxxOnly,
|
|
472
|
+
nullable,
|
|
473
|
+
parser,
|
|
474
|
+
) {
|
|
475
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
476
|
+
throwIfPartialNotAnnotatingTypeParameter(typeAnnotation, types, parser);
|
|
477
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
478
|
+
typeAnnotation,
|
|
479
|
+
types,
|
|
480
|
+
);
|
|
481
|
+
const annotatedElementProperties =
|
|
482
|
+
parser.getAnnotatedElementProperties(annotatedElement);
|
|
483
|
+
const partialProperties = parser.computePartialProperties(
|
|
484
|
+
annotatedElementProperties,
|
|
485
|
+
hasteModuleName,
|
|
486
|
+
types,
|
|
487
|
+
aliasMap,
|
|
488
|
+
enumMap,
|
|
489
|
+
tryParse,
|
|
490
|
+
cxxOnly,
|
|
491
|
+
);
|
|
492
|
+
return emitObject(nullable, partialProperties);
|
|
493
|
+
}
|
|
494
|
+
function emitCommonTypes(
|
|
495
|
+
hasteModuleName,
|
|
496
|
+
types,
|
|
497
|
+
typeAnnotation,
|
|
498
|
+
aliasMap,
|
|
499
|
+
enumMap,
|
|
500
|
+
tryParse,
|
|
501
|
+
cxxOnly,
|
|
502
|
+
nullable,
|
|
503
|
+
parser,
|
|
504
|
+
) {
|
|
505
|
+
const genericTypeAnnotationName =
|
|
506
|
+
parser.nameForGenericTypeAnnotation(typeAnnotation);
|
|
507
|
+
switch (genericTypeAnnotationName) {
|
|
508
|
+
case 'Stringish': {
|
|
509
|
+
return emitStringish(nullable);
|
|
510
|
+
}
|
|
511
|
+
case 'Int32': {
|
|
512
|
+
return emitInt32(nullable);
|
|
513
|
+
}
|
|
514
|
+
case 'Double': {
|
|
515
|
+
return emitDouble(nullable);
|
|
516
|
+
}
|
|
517
|
+
case 'Float': {
|
|
518
|
+
return emitFloat(nullable);
|
|
519
|
+
}
|
|
520
|
+
case 'UnsafeObject':
|
|
521
|
+
case 'Object': {
|
|
522
|
+
return emitGenericObject(nullable);
|
|
523
|
+
}
|
|
524
|
+
case '$Partial':
|
|
525
|
+
case 'Partial': {
|
|
526
|
+
return emitPartial(
|
|
527
|
+
hasteModuleName,
|
|
528
|
+
typeAnnotation,
|
|
529
|
+
types,
|
|
530
|
+
aliasMap,
|
|
531
|
+
enumMap,
|
|
532
|
+
tryParse,
|
|
533
|
+
cxxOnly,
|
|
534
|
+
nullable,
|
|
535
|
+
parser,
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
default: {
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
430
543
|
module.exports = {
|
|
431
544
|
emitArrayType,
|
|
432
545
|
emitBoolean,
|
|
@@ -444,7 +557,10 @@ module.exports = {
|
|
|
444
557
|
emitStringish,
|
|
445
558
|
emitMixed,
|
|
446
559
|
emitUnion,
|
|
560
|
+
emitPartial,
|
|
561
|
+
emitCommonTypes,
|
|
447
562
|
typeAliasResolution,
|
|
448
563
|
typeEnumResolution,
|
|
449
564
|
translateArrayTypeAnnotation,
|
|
565
|
+
Visitor,
|
|
450
566
|
};
|