@react-native/codegen 0.72.3 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CodegenSchema.d.ts +10 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +33 -44
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +35 -44
- package/lib/generators/components/GenerateEventEmitterH.js +0 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +0 -2
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- package/lib/generators/modules/GenerateModuleCpp.js +3 -3
- package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
- package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
- package/lib/parsers/error-utils.js +9 -15
- package/lib/parsers/error-utils.js.flow +12 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +35 -168
- package/lib/parsers/flow/components/index.js.flow +33 -107
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +51 -327
- package/lib/parsers/flow/modules/index.js.flow +34 -258
- package/lib/parsers/flow/parser.js +84 -13
- package/lib/parsers/flow/parser.js.flow +80 -4
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -3
- package/lib/parsers/parserMock.js +53 -0
- package/lib/parsers/parserMock.js.flow +64 -1
- package/lib/parsers/parsers-commons.js +397 -4
- package/lib/parsers/parsers-commons.js.flow +391 -4
- package/lib/parsers/parsers-primitives.js +121 -3
- package/lib/parsers/parsers-primitives.js.flow +134 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +37 -170
- package/lib/parsers/typescript/components/index.js.flow +33 -109
- package/lib/parsers/typescript/modules/index.js +113 -441
- package/lib/parsers/typescript/modules/index.js.flow +100 -309
- package/lib/parsers/typescript/parser.js +97 -13
- package/lib/parsers/typescript/parser.js.flow +94 -4
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
|
@@ -34,7 +34,6 @@ import type {
|
|
|
34
34
|
NativeModuleObjectTypeAnnotation,
|
|
35
35
|
NativeModuleEnumDeclaration,
|
|
36
36
|
} from '../CodegenSchema';
|
|
37
|
-
import type {ParserType} from './errors';
|
|
38
37
|
import type {Parser} from './parser';
|
|
39
38
|
import type {
|
|
40
39
|
ParserErrorCapturer,
|
|
@@ -50,6 +49,8 @@ const {
|
|
|
50
49
|
|
|
51
50
|
const {
|
|
52
51
|
throwIfArrayElementTypeAnnotationIsUnsupported,
|
|
52
|
+
throwIfPartialNotAnnotatingTypeParameter,
|
|
53
|
+
throwIfPartialWithMoreParameter,
|
|
53
54
|
} = require('./error-utils');
|
|
54
55
|
const {nullGuard} = require('./parsers-utils');
|
|
55
56
|
const {
|
|
@@ -59,6 +60,8 @@ const {
|
|
|
59
60
|
translateFunctionTypeAnnotation,
|
|
60
61
|
} = require('./parsers-commons');
|
|
61
62
|
|
|
63
|
+
const {isModuleRegistryCall} = require('./utils');
|
|
64
|
+
|
|
62
65
|
function emitBoolean(nullable: boolean): Nullable<BooleanTypeAnnotation> {
|
|
63
66
|
return wrapNullable(nullable, {
|
|
64
67
|
type: 'BooleanTypeAnnotation',
|
|
@@ -204,7 +207,6 @@ function typeEnumResolution(
|
|
|
204
207
|
typeResolution: TypeResolutionStatus,
|
|
205
208
|
nullable: boolean,
|
|
206
209
|
hasteModuleName: string,
|
|
207
|
-
language: ParserType,
|
|
208
210
|
enumMap: {...NativeModuleEnumMap},
|
|
209
211
|
parser: Parser,
|
|
210
212
|
): Nullable<NativeModuleEnumDeclaration> {
|
|
@@ -212,7 +214,7 @@ function typeEnumResolution(
|
|
|
212
214
|
throw new UnsupportedTypeAnnotationParserError(
|
|
213
215
|
hasteModuleName,
|
|
214
216
|
typeAnnotation,
|
|
215
|
-
language,
|
|
217
|
+
parser.language(),
|
|
216
218
|
);
|
|
217
219
|
}
|
|
218
220
|
|
|
@@ -439,6 +441,132 @@ function emitArrayType(
|
|
|
439
441
|
);
|
|
440
442
|
}
|
|
441
443
|
|
|
444
|
+
function Visitor(infoMap: {isComponent: boolean, isModule: boolean}): {
|
|
445
|
+
[type: string]: (node: $FlowFixMe) => void,
|
|
446
|
+
} {
|
|
447
|
+
return {
|
|
448
|
+
CallExpression(node: $FlowFixMe) {
|
|
449
|
+
if (
|
|
450
|
+
node.callee.type === 'Identifier' &&
|
|
451
|
+
node.callee.name === 'codegenNativeComponent'
|
|
452
|
+
) {
|
|
453
|
+
infoMap.isComponent = true;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (isModuleRegistryCall(node)) {
|
|
457
|
+
infoMap.isModule = true;
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
InterfaceExtends(node: $FlowFixMe) {
|
|
461
|
+
if (node.id.name === 'TurboModule') {
|
|
462
|
+
infoMap.isModule = true;
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
TSInterfaceDeclaration(node: $FlowFixMe) {
|
|
466
|
+
if (
|
|
467
|
+
Array.isArray(node.extends) &&
|
|
468
|
+
node.extends.some(
|
|
469
|
+
extension => extension.expression.name === 'TurboModule',
|
|
470
|
+
)
|
|
471
|
+
) {
|
|
472
|
+
infoMap.isModule = true;
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function emitPartial(
|
|
479
|
+
nullable: boolean,
|
|
480
|
+
hasteModuleName: string,
|
|
481
|
+
typeAnnotation: $FlowFixMe,
|
|
482
|
+
types: TypeDeclarationMap,
|
|
483
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
484
|
+
enumMap: {...NativeModuleEnumMap},
|
|
485
|
+
tryParse: ParserErrorCapturer,
|
|
486
|
+
cxxOnly: boolean,
|
|
487
|
+
parser: Parser,
|
|
488
|
+
): Nullable<NativeModuleTypeAnnotation> {
|
|
489
|
+
throwIfPartialWithMoreParameter(typeAnnotation);
|
|
490
|
+
|
|
491
|
+
throwIfPartialNotAnnotatingTypeParameter(typeAnnotation, types, parser);
|
|
492
|
+
|
|
493
|
+
const annotatedElement = parser.extractAnnotatedElement(
|
|
494
|
+
typeAnnotation,
|
|
495
|
+
types,
|
|
496
|
+
);
|
|
497
|
+
const annotatedElementProperties =
|
|
498
|
+
parser.getAnnotatedElementProperties(annotatedElement);
|
|
499
|
+
|
|
500
|
+
const partialProperties = parser.computePartialProperties(
|
|
501
|
+
annotatedElementProperties,
|
|
502
|
+
hasteModuleName,
|
|
503
|
+
types,
|
|
504
|
+
aliasMap,
|
|
505
|
+
enumMap,
|
|
506
|
+
tryParse,
|
|
507
|
+
cxxOnly,
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
return emitObject(nullable, partialProperties);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function emitCommonTypes(
|
|
514
|
+
hasteModuleName: string,
|
|
515
|
+
types: TypeDeclarationMap,
|
|
516
|
+
typeAnnotation: $FlowFixMe,
|
|
517
|
+
aliasMap: {...NativeModuleAliasMap},
|
|
518
|
+
enumMap: {...NativeModuleEnumMap},
|
|
519
|
+
tryParse: ParserErrorCapturer,
|
|
520
|
+
cxxOnly: boolean,
|
|
521
|
+
nullable: boolean,
|
|
522
|
+
parser: Parser,
|
|
523
|
+
): $FlowFixMe {
|
|
524
|
+
const typeMap = {
|
|
525
|
+
Stringish: emitStringish,
|
|
526
|
+
Int32: emitInt32,
|
|
527
|
+
Double: emitDouble,
|
|
528
|
+
Float: emitFloat,
|
|
529
|
+
UnsafeObject: emitGenericObject,
|
|
530
|
+
Object: emitGenericObject,
|
|
531
|
+
$Partial: emitPartial,
|
|
532
|
+
Partial: emitPartial,
|
|
533
|
+
BooleanTypeAnnotation: emitBoolean,
|
|
534
|
+
NumberTypeAnnotation: emitNumber,
|
|
535
|
+
VoidTypeAnnotation: emitVoid,
|
|
536
|
+
StringTypeAnnotation: emitString,
|
|
537
|
+
MixedTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject,
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
const typeAnnotationName = parser.convertKeywordToTypeAnnotation(
|
|
541
|
+
typeAnnotation.type,
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
const simpleEmitter = typeMap[typeAnnotationName];
|
|
545
|
+
if (simpleEmitter) {
|
|
546
|
+
return simpleEmitter(nullable);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const genericTypeAnnotationName =
|
|
550
|
+
parser.nameForGenericTypeAnnotation(typeAnnotation);
|
|
551
|
+
|
|
552
|
+
const emitter = typeMap[genericTypeAnnotationName];
|
|
553
|
+
if (!emitter) {
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return emitter(
|
|
558
|
+
nullable,
|
|
559
|
+
hasteModuleName,
|
|
560
|
+
typeAnnotation,
|
|
561
|
+
types,
|
|
562
|
+
aliasMap,
|
|
563
|
+
enumMap,
|
|
564
|
+
tryParse,
|
|
565
|
+
cxxOnly,
|
|
566
|
+
parser,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
442
570
|
module.exports = {
|
|
443
571
|
emitArrayType,
|
|
444
572
|
emitBoolean,
|
|
@@ -456,7 +584,10 @@ module.exports = {
|
|
|
456
584
|
emitStringish,
|
|
457
585
|
emitMixed,
|
|
458
586
|
emitUnion,
|
|
587
|
+
emitPartial,
|
|
588
|
+
emitCommonTypes,
|
|
459
589
|
typeAliasResolution,
|
|
460
590
|
typeEnumResolution,
|
|
461
591
|
translateArrayTypeAnnotation,
|
|
592
|
+
Visitor,
|
|
462
593
|
};
|
|
@@ -193,7 +193,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
193
193
|
|
|
194
194
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
195
195
|
|
|
196
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
196
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
197
197
|
import type {ImageSource} from 'ImageSource';
|
|
198
198
|
import type {
|
|
199
199
|
ColorValue,
|
|
@@ -306,6 +306,10 @@ export interface ModuleProps extends ViewProps {
|
|
|
306
306
|
dimension_optional_key?: DimensionValue;
|
|
307
307
|
dimension_optional_value: DimensionValue | null | undefined;
|
|
308
308
|
dimension_optional_both?: DimensionValue | null | undefined;
|
|
309
|
+
|
|
310
|
+
// Mixed props
|
|
311
|
+
mixed_required: UnsafeMixed,
|
|
312
|
+
mixed_optional_key?: UnsafeMixed,
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
export default codegenNativeComponent<ModuleProps>(
|
|
@@ -197,7 +197,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
197
197
|
|
|
198
198
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
199
199
|
|
|
200
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
200
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
201
201
|
import type {ImageSource} from 'ImageSource';
|
|
202
202
|
import type {
|
|
203
203
|
ColorValue,
|
|
@@ -310,6 +310,10 @@ export interface ModuleProps extends ViewProps {
|
|
|
310
310
|
dimension_optional_key?: DimensionValue;
|
|
311
311
|
dimension_optional_value: DimensionValue | null | undefined;
|
|
312
312
|
dimension_optional_both?: DimensionValue | null | undefined;
|
|
313
|
+
|
|
314
|
+
// Mixed props
|
|
315
|
+
mixed_required: UnsafeMixed,
|
|
316
|
+
mixed_optional_key?: UnsafeMixed,
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
export default codegenNativeComponent<ModuleProps>(
|
|
@@ -252,6 +252,10 @@ function getCommonTypeAnnotation(
|
|
|
252
252
|
return {
|
|
253
253
|
type: 'StringTypeAnnotation',
|
|
254
254
|
};
|
|
255
|
+
case 'UnsafeMixed':
|
|
256
|
+
return {
|
|
257
|
+
type: 'MixedTypeAnnotation',
|
|
258
|
+
};
|
|
255
259
|
default:
|
|
256
260
|
return undefined;
|
|
257
261
|
}
|
|
@@ -389,6 +393,10 @@ function getTypeAnnotation(name, annotation, defaultValue, types, buildSchema) {
|
|
|
389
393
|
throw new Error(
|
|
390
394
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
391
395
|
);
|
|
396
|
+
case 'TSFunctionType':
|
|
397
|
+
throw new Error(
|
|
398
|
+
`Cannot use "${type}" type annotation for "${name}": must use a specific function type like BubblingEventHandler, or DirectEventHandler`,
|
|
399
|
+
);
|
|
392
400
|
default:
|
|
393
401
|
type;
|
|
394
402
|
throw new Error(`Unknown prop type for "${name}": "${type}"`);
|
|
@@ -262,6 +262,10 @@ function getCommonTypeAnnotation<T>(
|
|
|
262
262
|
return {
|
|
263
263
|
type: 'StringTypeAnnotation',
|
|
264
264
|
};
|
|
265
|
+
case 'UnsafeMixed':
|
|
266
|
+
return {
|
|
267
|
+
type: 'MixedTypeAnnotation',
|
|
268
|
+
};
|
|
265
269
|
default:
|
|
266
270
|
return undefined;
|
|
267
271
|
}
|
|
@@ -416,6 +420,10 @@ function getTypeAnnotation<T>(
|
|
|
416
420
|
throw new Error(
|
|
417
421
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
418
422
|
);
|
|
423
|
+
case 'TSFunctionType':
|
|
424
|
+
throw new Error(
|
|
425
|
+
`Cannot use "${type}" type annotation for "${name}": must use a specific function type like BubblingEventHandler, or DirectEventHandler`,
|
|
426
|
+
);
|
|
419
427
|
default:
|
|
420
428
|
(type: empty);
|
|
421
429
|
throw new Error(`Unknown prop type for "${name}": "${type}"`);
|
|
@@ -10,114 +10,37 @@
|
|
|
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
|
-
}
|
|
75
13
|
const _require = require('./commands'),
|
|
76
14
|
getCommands = _require.getCommands;
|
|
77
15
|
const _require2 = require('./events'),
|
|
78
16
|
getEvents = _require2.getEvents;
|
|
79
17
|
const _require3 = require('./extends'),
|
|
80
18
|
categorizeProps = _require3.categorizeProps;
|
|
81
|
-
const _require4 = require('./
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
19
|
+
const _require4 = require('./props'),
|
|
20
|
+
getProps = _require4.getProps;
|
|
21
|
+
const _require5 = require('./componentsUtils.js'),
|
|
22
|
+
getProperties = _require5.getProperties;
|
|
23
|
+
const _require6 = require('../../error-utils'),
|
|
24
|
+
throwIfMoreThanOneCodegenNativecommands =
|
|
25
|
+
_require6.throwIfMoreThanOneCodegenNativecommands;
|
|
26
|
+
const _require7 = require('../../parsers-commons'),
|
|
27
|
+
createComponentConfig = _require7.createComponentConfig,
|
|
28
|
+
findNativeComponentType = _require7.findNativeComponentType,
|
|
29
|
+
propertyNames = _require7.propertyNames,
|
|
30
|
+
getCommandOptions = _require7.getCommandOptions,
|
|
31
|
+
getOptions = _require7.getOptions,
|
|
32
|
+
getCommandTypeNameAndOptionsExpression =
|
|
33
|
+
_require7.getCommandTypeNameAndOptionsExpression;
|
|
88
34
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
function findComponentConfig(ast) {
|
|
35
|
+
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
36
|
+
function findComponentConfig(ast, parser) {
|
|
92
37
|
const foundConfigs = [];
|
|
93
38
|
const defaultExports = ast.body.filter(
|
|
94
39
|
node => node.type === 'ExportDefaultDeclaration',
|
|
95
40
|
);
|
|
96
|
-
defaultExports.forEach(statement =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// codegenNativeComponent can be nested inside a cast
|
|
100
|
-
// expression so we need to go one level deeper
|
|
101
|
-
if (declaration.type === 'TSAsExpression') {
|
|
102
|
-
declaration = declaration.expression;
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
if (declaration.callee.name === 'codegenNativeComponent') {
|
|
106
|
-
const typeArgumentParams = declaration.typeParameters.params;
|
|
107
|
-
const funcArgumentParams = declaration.arguments;
|
|
108
|
-
const nativeComponentType = {
|
|
109
|
-
propsTypeName: typeArgumentParams[0].typeName.name,
|
|
110
|
-
componentName: funcArgumentParams[0].value,
|
|
111
|
-
};
|
|
112
|
-
if (funcArgumentParams.length > 1) {
|
|
113
|
-
nativeComponentType.optionsExpression = funcArgumentParams[1];
|
|
114
|
-
}
|
|
115
|
-
foundConfigs.push(nativeComponentType);
|
|
116
|
-
}
|
|
117
|
-
} catch (e) {
|
|
118
|
-
// ignore
|
|
119
|
-
}
|
|
120
|
-
});
|
|
41
|
+
defaultExports.forEach(statement =>
|
|
42
|
+
findNativeComponentType(statement, foundConfigs, parser),
|
|
43
|
+
);
|
|
121
44
|
if (foundConfigs.length === 0) {
|
|
122
45
|
throw new Error('Could not find component config for native component');
|
|
123
46
|
}
|
|
@@ -129,82 +52,33 @@ function findComponentConfig(ast) {
|
|
|
129
52
|
node => node.type === 'ExportNamedDeclaration',
|
|
130
53
|
);
|
|
131
54
|
const commandsTypeNames = namedExports
|
|
132
|
-
.map(statement =>
|
|
133
|
-
let callExpression;
|
|
134
|
-
let calleeName;
|
|
135
|
-
try {
|
|
136
|
-
callExpression = statement.declaration.declarations[0].init;
|
|
137
|
-
calleeName = callExpression.callee.name;
|
|
138
|
-
} catch (e) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (calleeName !== 'codegenNativeCommands') {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// const statement.declaration.declarations[0].init
|
|
146
|
-
if (callExpression.arguments.length !== 1) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
'codegenNativeCommands must be passed options including the supported commands',
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
const typeArgumentParam = callExpression.typeParameters.params[0];
|
|
152
|
-
if (typeArgumentParam.type !== 'TSTypeReference') {
|
|
153
|
-
throw new Error(
|
|
154
|
-
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias",
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
commandTypeName: typeArgumentParam.typeName.name,
|
|
159
|
-
commandOptionsExpression: callExpression.arguments[0],
|
|
160
|
-
};
|
|
161
|
-
})
|
|
55
|
+
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser))
|
|
162
56
|
.filter(Boolean);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return _objectSpread(
|
|
167
|
-
_objectSpread({}, foundConfig),
|
|
168
|
-
{},
|
|
169
|
-
{
|
|
170
|
-
commandTypeName:
|
|
171
|
-
commandsTypeNames[0] == null
|
|
172
|
-
? null
|
|
173
|
-
: commandsTypeNames[0].commandTypeName,
|
|
174
|
-
commandOptionsExpression:
|
|
175
|
-
commandsTypeNames[0] == null
|
|
176
|
-
? null
|
|
177
|
-
: commandsTypeNames[0].commandOptionsExpression,
|
|
178
|
-
},
|
|
179
|
-
);
|
|
57
|
+
throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
|
|
58
|
+
return createComponentConfig(foundConfig, commandsTypeNames);
|
|
180
59
|
}
|
|
181
|
-
function getCommandProperties(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
types,
|
|
186
|
-
commandOptions,
|
|
187
|
-
) {
|
|
60
|
+
function getCommandProperties(ast, parser) {
|
|
61
|
+
const _findComponentConfig = findComponentConfig(ast, parser),
|
|
62
|
+
commandTypeName = _findComponentConfig.commandTypeName,
|
|
63
|
+
commandOptionsExpression = _findComponentConfig.commandOptionsExpression;
|
|
188
64
|
if (commandTypeName == null) {
|
|
189
65
|
return [];
|
|
190
66
|
}
|
|
67
|
+
const types = parser.getTypes(ast);
|
|
191
68
|
const typeAlias = types[commandTypeName];
|
|
192
69
|
if (typeAlias.type !== 'TSInterfaceDeclaration') {
|
|
193
70
|
throw new Error(
|
|
194
71
|
`The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`,
|
|
195
72
|
);
|
|
196
73
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
properties = typeAlias.body.body;
|
|
200
|
-
} catch (e) {
|
|
74
|
+
const properties = parser.bodyProperties(typeAlias);
|
|
75
|
+
if (!properties) {
|
|
201
76
|
throw new Error(
|
|
202
77
|
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`,
|
|
203
78
|
);
|
|
204
79
|
}
|
|
205
|
-
const typeScriptPropertyNames = properties
|
|
206
|
-
|
|
207
|
-
.filter(Boolean);
|
|
80
|
+
const typeScriptPropertyNames = propertyNames(properties);
|
|
81
|
+
const commandOptions = getCommandOptions(commandOptionsExpression);
|
|
208
82
|
if (commandOptions == null || commandOptions.supportedCommands == null) {
|
|
209
83
|
throw new Error(
|
|
210
84
|
'codegenNativeCommands must be given an options object with supportedCommands array',
|
|
@@ -230,20 +104,13 @@ function getCommandProperties(
|
|
|
230
104
|
|
|
231
105
|
// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
|
|
232
106
|
function buildComponentSchema(ast, parser) {
|
|
233
|
-
const
|
|
234
|
-
componentName =
|
|
235
|
-
propsTypeName =
|
|
236
|
-
|
|
237
|
-
commandOptionsExpression = _findComponentConfig.commandOptionsExpression,
|
|
238
|
-
optionsExpression = _findComponentConfig.optionsExpression;
|
|
107
|
+
const _findComponentConfig2 = findComponentConfig(ast, parser),
|
|
108
|
+
componentName = _findComponentConfig2.componentName,
|
|
109
|
+
propsTypeName = _findComponentConfig2.propsTypeName,
|
|
110
|
+
optionsExpression = _findComponentConfig2.optionsExpression;
|
|
239
111
|
const types = parser.getTypes(ast);
|
|
240
112
|
const propProperties = getProperties(propsTypeName, types);
|
|
241
|
-
const
|
|
242
|
-
const commandProperties = getCommandProperties(
|
|
243
|
-
commandTypeName,
|
|
244
|
-
types,
|
|
245
|
-
commandOptions,
|
|
246
|
-
);
|
|
113
|
+
const commandProperties = getCommandProperties(ast, parser);
|
|
247
114
|
const options = getOptions(optionsExpression);
|
|
248
115
|
const extendsProps = [];
|
|
249
116
|
const componentPropAsts = [];
|