@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
|
@@ -10,6 +10,68 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
function ownKeys(object, enumerableOnly) {
|
|
14
|
+
var keys = Object.keys(object);
|
|
15
|
+
if (Object.getOwnPropertySymbols) {
|
|
16
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
17
|
+
enumerableOnly &&
|
|
18
|
+
(symbols = symbols.filter(function (sym) {
|
|
19
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
+
})),
|
|
21
|
+
keys.push.apply(keys, symbols);
|
|
22
|
+
}
|
|
23
|
+
return keys;
|
|
24
|
+
}
|
|
25
|
+
function _objectSpread(target) {
|
|
26
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
28
|
+
i % 2
|
|
29
|
+
? ownKeys(Object(source), !0).forEach(function (key) {
|
|
30
|
+
_defineProperty(target, key, source[key]);
|
|
31
|
+
})
|
|
32
|
+
: Object.getOwnPropertyDescriptors
|
|
33
|
+
? Object.defineProperties(
|
|
34
|
+
target,
|
|
35
|
+
Object.getOwnPropertyDescriptors(source),
|
|
36
|
+
)
|
|
37
|
+
: ownKeys(Object(source)).forEach(function (key) {
|
|
38
|
+
Object.defineProperty(
|
|
39
|
+
target,
|
|
40
|
+
key,
|
|
41
|
+
Object.getOwnPropertyDescriptor(source, key),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
function _defineProperty(obj, key, value) {
|
|
48
|
+
key = _toPropertyKey(key);
|
|
49
|
+
if (key in obj) {
|
|
50
|
+
Object.defineProperty(obj, key, {
|
|
51
|
+
value: value,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
obj[key] = value;
|
|
58
|
+
}
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
function _toPropertyKey(arg) {
|
|
62
|
+
var key = _toPrimitive(arg, 'string');
|
|
63
|
+
return typeof key === 'symbol' ? key : String(key);
|
|
64
|
+
}
|
|
65
|
+
function _toPrimitive(input, hint) {
|
|
66
|
+
if (typeof input !== 'object' || input === null) return input;
|
|
67
|
+
var prim = input[Symbol.toPrimitive];
|
|
68
|
+
if (prim !== undefined) {
|
|
69
|
+
var res = prim.call(input, hint || 'default');
|
|
70
|
+
if (typeof res !== 'object') return res;
|
|
71
|
+
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
72
|
+
}
|
|
73
|
+
return (hint === 'string' ? String : Number)(input);
|
|
74
|
+
}
|
|
13
75
|
function _slicedToArray(arr, i) {
|
|
14
76
|
return (
|
|
15
77
|
_arrayWithHoles(arr) ||
|
|
@@ -81,7 +143,10 @@ function _arrayWithHoles(arr) {
|
|
|
81
143
|
const _require = require('./utils'),
|
|
82
144
|
getConfigType = _require.getConfigType,
|
|
83
145
|
extractNativeModuleName = _require.extractNativeModuleName,
|
|
84
|
-
createParserErrorCapturer = _require.createParserErrorCapturer
|
|
146
|
+
createParserErrorCapturer = _require.createParserErrorCapturer,
|
|
147
|
+
visit = _require.visit,
|
|
148
|
+
isModuleRegistryCall = _require.isModuleRegistryCall,
|
|
149
|
+
verifyPlatforms = _require.verifyPlatforms;
|
|
85
150
|
const _require2 = require('./error-utils'),
|
|
86
151
|
throwIfPropertyValueTypeIsUnsupported =
|
|
87
152
|
_require2.throwIfPropertyValueTypeIsUnsupported,
|
|
@@ -89,7 +154,22 @@ const _require2 = require('./error-utils'),
|
|
|
89
154
|
_require2.throwIfUnsupportedFunctionParamTypeAnnotationParserError,
|
|
90
155
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError =
|
|
91
156
|
_require2.throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
92
|
-
throwIfModuleTypeIsUnsupported = _require2.throwIfModuleTypeIsUnsupported
|
|
157
|
+
throwIfModuleTypeIsUnsupported = _require2.throwIfModuleTypeIsUnsupported,
|
|
158
|
+
throwIfUnusedModuleInterfaceParserError =
|
|
159
|
+
_require2.throwIfUnusedModuleInterfaceParserError,
|
|
160
|
+
throwIfMoreThanOneModuleRegistryCalls =
|
|
161
|
+
_require2.throwIfMoreThanOneModuleRegistryCalls,
|
|
162
|
+
throwIfWrongNumberOfCallExpressionArgs =
|
|
163
|
+
_require2.throwIfWrongNumberOfCallExpressionArgs,
|
|
164
|
+
throwIfUntypedModule = _require2.throwIfUntypedModule,
|
|
165
|
+
throwIfIncorrectModuleRegistryCallTypeParameterParserError =
|
|
166
|
+
_require2.throwIfIncorrectModuleRegistryCallTypeParameterParserError,
|
|
167
|
+
throwIfIncorrectModuleRegistryCallArgument =
|
|
168
|
+
_require2.throwIfIncorrectModuleRegistryCallArgument,
|
|
169
|
+
throwIfModuleInterfaceNotFound = _require2.throwIfModuleInterfaceNotFound,
|
|
170
|
+
throwIfMoreThanOneModuleInterfaceParserError =
|
|
171
|
+
_require2.throwIfMoreThanOneModuleInterfaceParserError,
|
|
172
|
+
throwIfModuleInterfaceIsMisnamed = _require2.throwIfModuleInterfaceIsMisnamed;
|
|
93
173
|
const _require3 = require('./errors'),
|
|
94
174
|
MissingTypeParameterGenericParserError =
|
|
95
175
|
_require3.MissingTypeParameterGenericParserError,
|
|
@@ -337,7 +417,7 @@ function buildPropertySchema(
|
|
|
337
417
|
property.value,
|
|
338
418
|
key.name,
|
|
339
419
|
value.type,
|
|
340
|
-
parser
|
|
420
|
+
parser,
|
|
341
421
|
);
|
|
342
422
|
return {
|
|
343
423
|
name: methodName,
|
|
@@ -366,6 +446,8 @@ function buildSchemaFromConfigType(
|
|
|
366
446
|
buildComponentSchema,
|
|
367
447
|
buildModuleSchema,
|
|
368
448
|
parser,
|
|
449
|
+
resolveTypeAnnotation,
|
|
450
|
+
translateTypeAnnotation,
|
|
369
451
|
) {
|
|
370
452
|
switch (configType) {
|
|
371
453
|
case 'component': {
|
|
@@ -381,7 +463,14 @@ function buildSchemaFromConfigType(
|
|
|
381
463
|
parsingErrors = _createParserErrorCap2[0],
|
|
382
464
|
tryParse = _createParserErrorCap2[1];
|
|
383
465
|
const schema = tryParse(() =>
|
|
384
|
-
buildModuleSchema(
|
|
466
|
+
buildModuleSchema(
|
|
467
|
+
nativeModuleName,
|
|
468
|
+
ast,
|
|
469
|
+
tryParse,
|
|
470
|
+
parser,
|
|
471
|
+
resolveTypeAnnotation,
|
|
472
|
+
translateTypeAnnotation,
|
|
473
|
+
),
|
|
385
474
|
);
|
|
386
475
|
if (parsingErrors.length > 0) {
|
|
387
476
|
/**
|
|
@@ -414,6 +503,8 @@ function buildSchema(
|
|
|
414
503
|
buildModuleSchema,
|
|
415
504
|
Visitor,
|
|
416
505
|
parser,
|
|
506
|
+
resolveTypeAnnotation,
|
|
507
|
+
translateTypeAnnotation,
|
|
417
508
|
) {
|
|
418
509
|
// Early return for non-Spec JavaScript files
|
|
419
510
|
if (
|
|
@@ -434,8 +525,268 @@ function buildSchema(
|
|
|
434
525
|
buildComponentSchema,
|
|
435
526
|
buildModuleSchema,
|
|
436
527
|
parser,
|
|
528
|
+
resolveTypeAnnotation,
|
|
529
|
+
translateTypeAnnotation,
|
|
437
530
|
);
|
|
438
531
|
}
|
|
532
|
+
function createComponentConfig(foundConfig, commandsTypeNames) {
|
|
533
|
+
return _objectSpread(
|
|
534
|
+
_objectSpread({}, foundConfig),
|
|
535
|
+
{},
|
|
536
|
+
{
|
|
537
|
+
commandTypeName:
|
|
538
|
+
commandsTypeNames[0] == null
|
|
539
|
+
? null
|
|
540
|
+
: commandsTypeNames[0].commandTypeName,
|
|
541
|
+
commandOptionsExpression:
|
|
542
|
+
commandsTypeNames[0] == null
|
|
543
|
+
? null
|
|
544
|
+
: commandsTypeNames[0].commandOptionsExpression,
|
|
545
|
+
},
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
const parseModuleName = (hasteModuleName, moduleSpec, ast, parser) => {
|
|
549
|
+
const callExpressions = [];
|
|
550
|
+
visit(ast, {
|
|
551
|
+
CallExpression(node) {
|
|
552
|
+
if (isModuleRegistryCall(node)) {
|
|
553
|
+
callExpressions.push(node);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
throwIfUnusedModuleInterfaceParserError(
|
|
558
|
+
hasteModuleName,
|
|
559
|
+
moduleSpec,
|
|
560
|
+
callExpressions,
|
|
561
|
+
);
|
|
562
|
+
throwIfMoreThanOneModuleRegistryCalls(
|
|
563
|
+
hasteModuleName,
|
|
564
|
+
callExpressions,
|
|
565
|
+
callExpressions.length,
|
|
566
|
+
);
|
|
567
|
+
const callExpression = callExpressions[0];
|
|
568
|
+
const typeParameters = parser.callExpressionTypeParameters(callExpression);
|
|
569
|
+
const methodName = callExpression.callee.property.name;
|
|
570
|
+
throwIfWrongNumberOfCallExpressionArgs(
|
|
571
|
+
hasteModuleName,
|
|
572
|
+
callExpression,
|
|
573
|
+
methodName,
|
|
574
|
+
callExpression.arguments.length,
|
|
575
|
+
);
|
|
576
|
+
throwIfIncorrectModuleRegistryCallArgument(
|
|
577
|
+
hasteModuleName,
|
|
578
|
+
callExpression.arguments[0],
|
|
579
|
+
methodName,
|
|
580
|
+
);
|
|
581
|
+
const $moduleName = callExpression.arguments[0].value;
|
|
582
|
+
throwIfUntypedModule(
|
|
583
|
+
typeParameters,
|
|
584
|
+
hasteModuleName,
|
|
585
|
+
callExpression,
|
|
586
|
+
methodName,
|
|
587
|
+
$moduleName,
|
|
588
|
+
);
|
|
589
|
+
throwIfIncorrectModuleRegistryCallTypeParameterParserError(
|
|
590
|
+
hasteModuleName,
|
|
591
|
+
typeParameters,
|
|
592
|
+
methodName,
|
|
593
|
+
$moduleName,
|
|
594
|
+
parser,
|
|
595
|
+
);
|
|
596
|
+
return $moduleName;
|
|
597
|
+
};
|
|
598
|
+
const buildModuleSchema = (
|
|
599
|
+
hasteModuleName,
|
|
600
|
+
ast,
|
|
601
|
+
tryParse,
|
|
602
|
+
parser,
|
|
603
|
+
resolveTypeAnnotation,
|
|
604
|
+
translateTypeAnnotation,
|
|
605
|
+
) => {
|
|
606
|
+
const language = parser.language();
|
|
607
|
+
const types = parser.getTypes(ast);
|
|
608
|
+
const moduleSpecs = Object.values(types).filter(t =>
|
|
609
|
+
parser.isModuleInterface(t),
|
|
610
|
+
);
|
|
611
|
+
throwIfModuleInterfaceNotFound(
|
|
612
|
+
moduleSpecs.length,
|
|
613
|
+
hasteModuleName,
|
|
614
|
+
ast,
|
|
615
|
+
language,
|
|
616
|
+
);
|
|
617
|
+
throwIfMoreThanOneModuleInterfaceParserError(
|
|
618
|
+
hasteModuleName,
|
|
619
|
+
moduleSpecs,
|
|
620
|
+
language,
|
|
621
|
+
);
|
|
622
|
+
const _moduleSpecs = _slicedToArray(moduleSpecs, 1),
|
|
623
|
+
moduleSpec = _moduleSpecs[0];
|
|
624
|
+
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language);
|
|
625
|
+
|
|
626
|
+
// Parse Module Name
|
|
627
|
+
const moduleName = parseModuleName(hasteModuleName, moduleSpec, ast, parser);
|
|
628
|
+
|
|
629
|
+
// Some module names use platform suffix to indicate platform-exclusive modules.
|
|
630
|
+
// Eventually this should be made explicit in the Flow type itself.
|
|
631
|
+
// Also check the hasteModuleName for platform suffix.
|
|
632
|
+
// Note: this shape is consistent with ComponentSchema.
|
|
633
|
+
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleName),
|
|
634
|
+
cxxOnly = _verifyPlatforms.cxxOnly,
|
|
635
|
+
excludedPlatforms = _verifyPlatforms.excludedPlatforms;
|
|
636
|
+
const properties =
|
|
637
|
+
language === 'Flow' ? moduleSpec.body.properties : moduleSpec.body.body;
|
|
638
|
+
|
|
639
|
+
// $FlowFixMe[missing-type-arg]
|
|
640
|
+
return properties
|
|
641
|
+
.filter(
|
|
642
|
+
property =>
|
|
643
|
+
property.type === 'ObjectTypeProperty' ||
|
|
644
|
+
property.type === 'TSPropertySignature' ||
|
|
645
|
+
property.type === 'TSMethodSignature',
|
|
646
|
+
)
|
|
647
|
+
.map(property => {
|
|
648
|
+
const aliasMap = {};
|
|
649
|
+
const enumMap = {};
|
|
650
|
+
return tryParse(() => ({
|
|
651
|
+
aliasMap,
|
|
652
|
+
enumMap,
|
|
653
|
+
propertyShape: buildPropertySchema(
|
|
654
|
+
hasteModuleName,
|
|
655
|
+
property,
|
|
656
|
+
types,
|
|
657
|
+
aliasMap,
|
|
658
|
+
enumMap,
|
|
659
|
+
tryParse,
|
|
660
|
+
cxxOnly,
|
|
661
|
+
resolveTypeAnnotation,
|
|
662
|
+
translateTypeAnnotation,
|
|
663
|
+
parser,
|
|
664
|
+
),
|
|
665
|
+
}));
|
|
666
|
+
})
|
|
667
|
+
.filter(Boolean)
|
|
668
|
+
.reduce(
|
|
669
|
+
(moduleSchema, {aliasMap, enumMap, propertyShape}) => ({
|
|
670
|
+
type: 'NativeModule',
|
|
671
|
+
aliasMap: _objectSpread(
|
|
672
|
+
_objectSpread({}, moduleSchema.aliasMap),
|
|
673
|
+
aliasMap,
|
|
674
|
+
),
|
|
675
|
+
enumMap: _objectSpread(
|
|
676
|
+
_objectSpread({}, moduleSchema.enumMap),
|
|
677
|
+
enumMap,
|
|
678
|
+
),
|
|
679
|
+
spec: {
|
|
680
|
+
properties: [...moduleSchema.spec.properties, propertyShape],
|
|
681
|
+
},
|
|
682
|
+
moduleName: moduleSchema.moduleName,
|
|
683
|
+
excludedPlatforms: moduleSchema.excludedPlatforms,
|
|
684
|
+
}),
|
|
685
|
+
{
|
|
686
|
+
type: 'NativeModule',
|
|
687
|
+
aliasMap: {},
|
|
688
|
+
enumMap: {},
|
|
689
|
+
spec: {
|
|
690
|
+
properties: [],
|
|
691
|
+
},
|
|
692
|
+
moduleName,
|
|
693
|
+
excludedPlatforms:
|
|
694
|
+
excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined,
|
|
695
|
+
},
|
|
696
|
+
);
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* This function is used to find the type of a native component
|
|
701
|
+
* provided the default exports statement from generated AST.
|
|
702
|
+
* @param statement The statement to be parsed.
|
|
703
|
+
* @param foundConfigs The 'mutable' array of configs that have been found.
|
|
704
|
+
* @param parser The language parser to be used.
|
|
705
|
+
* @returns void
|
|
706
|
+
*/
|
|
707
|
+
function findNativeComponentType(statement, foundConfigs, parser) {
|
|
708
|
+
let declaration = statement.declaration;
|
|
709
|
+
|
|
710
|
+
// codegenNativeComponent can be nested inside a cast
|
|
711
|
+
// expression so we need to go one level deeper
|
|
712
|
+
if (
|
|
713
|
+
declaration.type === 'TSAsExpression' ||
|
|
714
|
+
declaration.type === 'TypeCastExpression'
|
|
715
|
+
) {
|
|
716
|
+
declaration = declaration.expression;
|
|
717
|
+
}
|
|
718
|
+
try {
|
|
719
|
+
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
720
|
+
const typeArgumentParams =
|
|
721
|
+
parser.getTypeArgumentParamsFromDeclaration(declaration);
|
|
722
|
+
const funcArgumentParams = declaration.arguments;
|
|
723
|
+
const nativeComponentType = parser.getNativeComponentType(
|
|
724
|
+
typeArgumentParams,
|
|
725
|
+
funcArgumentParams,
|
|
726
|
+
);
|
|
727
|
+
if (funcArgumentParams.length > 1) {
|
|
728
|
+
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
729
|
+
}
|
|
730
|
+
foundConfigs.push(nativeComponentType);
|
|
731
|
+
}
|
|
732
|
+
} catch (e) {
|
|
733
|
+
// ignore
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function getCommandOptions(commandOptionsExpression) {
|
|
737
|
+
if (commandOptionsExpression == null) {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
let foundOptions;
|
|
741
|
+
try {
|
|
742
|
+
foundOptions = commandOptionsExpression.properties.reduce(
|
|
743
|
+
(options, prop) => {
|
|
744
|
+
options[prop.key.name] = (
|
|
745
|
+
(prop && prop.value && prop.value.elements) ||
|
|
746
|
+
[]
|
|
747
|
+
).map(element => element && element.value);
|
|
748
|
+
return options;
|
|
749
|
+
},
|
|
750
|
+
{},
|
|
751
|
+
);
|
|
752
|
+
} catch (e) {
|
|
753
|
+
throw new Error(
|
|
754
|
+
'Failed to parse command options, please check that they are defined correctly',
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
return foundOptions;
|
|
758
|
+
}
|
|
759
|
+
function getOptions(optionsExpression) {
|
|
760
|
+
if (!optionsExpression) {
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
let foundOptions;
|
|
764
|
+
try {
|
|
765
|
+
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
|
766
|
+
if (prop.value.type === 'ArrayExpression') {
|
|
767
|
+
options[prop.key.name] = prop.value.elements.map(
|
|
768
|
+
element => element.value,
|
|
769
|
+
);
|
|
770
|
+
} else {
|
|
771
|
+
options[prop.key.name] = prop.value.value;
|
|
772
|
+
}
|
|
773
|
+
return options;
|
|
774
|
+
}, {});
|
|
775
|
+
} catch (e) {
|
|
776
|
+
throw new Error(
|
|
777
|
+
'Failed to parse codegen options, please check that they are defined correctly',
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
if (
|
|
781
|
+
foundOptions.paperComponentName &&
|
|
782
|
+
foundOptions.paperComponentNameDeprecated
|
|
783
|
+
) {
|
|
784
|
+
throw new Error(
|
|
785
|
+
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
return foundOptions;
|
|
789
|
+
}
|
|
439
790
|
module.exports = {
|
|
440
791
|
wrapModuleSchema,
|
|
441
792
|
unwrapNullable,
|
|
@@ -447,4 +798,10 @@ module.exports = {
|
|
|
447
798
|
buildPropertySchema,
|
|
448
799
|
buildSchemaFromConfigType,
|
|
449
800
|
buildSchema,
|
|
801
|
+
createComponentConfig,
|
|
802
|
+
parseModuleName,
|
|
803
|
+
buildModuleSchema,
|
|
804
|
+
findNativeComponentType,
|
|
805
|
+
getCommandOptions,
|
|
806
|
+
getOptions,
|
|
450
807
|
};
|