@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.
Files changed (71) hide show
  1. package/lib/CodegenSchema.d.ts +10 -10
  2. package/lib/CodegenSchema.js.flow +6 -1
  3. package/lib/SchemaValidator.d.ts +1 -1
  4. package/lib/generators/RNCodegen.d.ts +98 -0
  5. package/lib/generators/RNCodegen.js +33 -4
  6. package/lib/generators/RNCodegen.js.flow +35 -4
  7. package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
  8. package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
  9. package/lib/generators/components/CppHelpers.js +2 -0
  10. package/lib/generators/components/CppHelpers.js.flow +2 -0
  11. package/lib/generators/components/GeneratePropsH.js +2 -0
  12. package/lib/generators/components/GeneratePropsH.js.flow +2 -0
  13. package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
  14. package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
  15. package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
  16. package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
  17. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
  18. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
  19. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
  20. package/lib/generators/components/GenerateViewConfigJs.js +1 -0
  21. package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
  22. package/lib/generators/components/JavaHelpers.js +7 -0
  23. package/lib/generators/components/JavaHelpers.js.flow +8 -0
  24. package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
  25. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
  26. package/lib/generators/modules/GenerateModuleH.js +1 -1
  27. package/lib/generators/modules/GenerateModuleH.js.flow +1 -1
  28. package/lib/parsers/error-utils.js +9 -15
  29. package/lib/parsers/error-utils.js.flow +12 -15
  30. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
  31. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
  32. package/lib/parsers/flow/components/componentsUtils.js +4 -0
  33. package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
  34. package/lib/parsers/flow/components/index.js +18 -113
  35. package/lib/parsers/flow/components/index.js.flow +15 -46
  36. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
  37. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
  38. package/lib/parsers/flow/modules/index.js +41 -307
  39. package/lib/parsers/flow/modules/index.js.flow +18 -233
  40. package/lib/parsers/flow/parser.js +68 -12
  41. package/lib/parsers/flow/parser.js.flow +67 -3
  42. package/lib/parsers/parser.d.ts +2 -2
  43. package/lib/parsers/parser.js.flow +65 -3
  44. package/lib/parsers/parserMock.js +44 -0
  45. package/lib/parsers/parserMock.js.flow +52 -1
  46. package/lib/parsers/parsers-commons.js +361 -4
  47. package/lib/parsers/parsers-commons.js.flow +341 -4
  48. package/lib/parsers/parsers-primitives.js +119 -3
  49. package/lib/parsers/parsers-primitives.js.flow +128 -3
  50. package/lib/parsers/schema/index.d.ts +1 -1
  51. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
  52. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
  53. package/lib/parsers/typescript/components/componentsUtils.js +8 -0
  54. package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
  55. package/lib/parsers/typescript/components/index.js +20 -115
  56. package/lib/parsers/typescript/components/index.js.flow +17 -48
  57. package/lib/parsers/typescript/modules/index.js +103 -421
  58. package/lib/parsers/typescript/modules/index.js.flow +84 -285
  59. package/lib/parsers/typescript/parser.js +69 -12
  60. package/lib/parsers/typescript/parser.js.flow +68 -3
  61. package/lib/parsers/utils.js +4 -0
  62. package/lib/parsers/utils.js.flow +3 -0
  63. package/package.json +11 -11
  64. package/lib/parsers/flow/Visitor.js +0 -37
  65. package/lib/parsers/flow/Visitor.js.flow +0 -41
  66. package/lib/parsers/flow/components/options.js +0 -72
  67. package/lib/parsers/flow/components/options.js.flow +0 -87
  68. package/lib/parsers/typescript/Visitor.js +0 -42
  69. package/lib/parsers/typescript/Visitor.js.flow +0 -47
  70. package/lib/parsers/typescript/components/options.js +0 -72
  71. 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,126 @@ 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
+ hasteModuleName: string,
480
+ typeAnnotation: $FlowFixMe,
481
+ types: TypeDeclarationMap,
482
+ aliasMap: {...NativeModuleAliasMap},
483
+ enumMap: {...NativeModuleEnumMap},
484
+ tryParse: ParserErrorCapturer,
485
+ cxxOnly: boolean,
486
+ nullable: 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 genericTypeAnnotationName =
525
+ parser.nameForGenericTypeAnnotation(typeAnnotation);
526
+
527
+ switch (genericTypeAnnotationName) {
528
+ case 'Stringish': {
529
+ return emitStringish(nullable);
530
+ }
531
+ case 'Int32': {
532
+ return emitInt32(nullable);
533
+ }
534
+ case 'Double': {
535
+ return emitDouble(nullable);
536
+ }
537
+ case 'Float': {
538
+ return emitFloat(nullable);
539
+ }
540
+ case 'UnsafeObject':
541
+ case 'Object': {
542
+ return emitGenericObject(nullable);
543
+ }
544
+ case '$Partial':
545
+ case 'Partial': {
546
+ return emitPartial(
547
+ hasteModuleName,
548
+ typeAnnotation,
549
+ types,
550
+ aliasMap,
551
+ enumMap,
552
+ tryParse,
553
+ cxxOnly,
554
+ nullable,
555
+ parser,
556
+ );
557
+ }
558
+ default: {
559
+ return null;
560
+ }
561
+ }
562
+ }
563
+
442
564
  module.exports = {
443
565
  emitArrayType,
444
566
  emitBoolean,
@@ -456,7 +578,10 @@ module.exports = {
456
578
  emitStringish,
457
579
  emitMixed,
458
580
  emitUnion,
581
+ emitPartial,
582
+ emitCommonTypes,
459
583
  typeAliasResolution,
460
584
  typeEnumResolution,
461
585
  translateArrayTypeAnnotation,
586
+ Visitor,
462
587
  };
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type { SchemaType } from "../../CodegenSchema";
8
+ import type { SchemaType } from '../../CodegenSchema';
9
9
 
10
10
  export declare function parse(filename: string): SchemaType | undefined;
@@ -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,34 @@
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('./options'),
82
- getCommandOptions = _require4.getCommandOptions,
83
- getOptions = _require4.getOptions;
84
- const _require5 = require('./props'),
85
- getProps = _require5.getProps;
86
- const _require6 = require('./componentsUtils.js'),
87
- getProperties = _require6.getProperties;
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
+ getCommandOptions = _require7.getCommandOptions,
30
+ getOptions = _require7.getOptions;
88
31
 
89
- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
90
- * LTI update could not be added via codemod */
91
- function findComponentConfig(ast) {
32
+ // $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
33
+ function findComponentConfig(ast, parser) {
92
34
  const foundConfigs = [];
93
35
  const defaultExports = ast.body.filter(
94
36
  node => node.type === 'ExportDefaultDeclaration',
95
37
  );
96
- defaultExports.forEach(statement => {
97
- let declaration = statement.declaration;
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
- });
38
+ defaultExports.forEach(statement =>
39
+ findNativeComponentType(statement, foundConfigs, parser),
40
+ );
121
41
  if (foundConfigs.length === 0) {
122
42
  throw new Error('Could not find component config for native component');
123
43
  }
@@ -160,23 +80,8 @@ function findComponentConfig(ast) {
160
80
  };
161
81
  })
162
82
  .filter(Boolean);
163
- if (commandsTypeNames.length > 1) {
164
- throw new Error('codegenNativeCommands may only be called once in a file');
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
- );
83
+ throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
84
+ return createComponentConfig(foundConfig, commandsTypeNames);
180
85
  }
181
86
  function getCommandProperties(
182
87
  /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
@@ -230,7 +135,7 @@ function getCommandProperties(
230
135
 
231
136
  // $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
232
137
  function buildComponentSchema(ast, parser) {
233
- const _findComponentConfig = findComponentConfig(ast),
138
+ const _findComponentConfig = findComponentConfig(ast, parser),
234
139
  componentName = _findComponentConfig.componentName,
235
140
  propsTypeName = _findComponentConfig.propsTypeName,
236
141
  commandTypeName = _findComponentConfig.commandTypeName,
@@ -12,52 +12,33 @@
12
12
  import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
13
13
  import type {Parser} from '../../parser';
14
14
  import type {TypeDeclarationMap} from '../../utils';
15
- import type {CommandOptions} from './options';
15
+ import type {CommandOptions} from '../../parsers-commons';
16
16
  import type {ComponentSchemaBuilderConfig} from '../../schema.js';
17
17
 
18
18
  const {getCommands} = require('./commands');
19
19
  const {getEvents} = require('./events');
20
20
  const {categorizeProps} = require('./extends');
21
- const {getCommandOptions, getOptions} = require('./options');
22
21
  const {getProps} = require('./props');
23
22
  const {getProperties} = require('./componentsUtils.js');
23
+ const {throwIfMoreThanOneCodegenNativecommands} = require('../../error-utils');
24
+ const {
25
+ createComponentConfig,
26
+ findNativeComponentType,
27
+ getCommandOptions,
28
+ getOptions,
29
+ } = require('../../parsers-commons');
24
30
 
25
- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
26
- * LTI update could not be added via codemod */
27
- function findComponentConfig(ast) {
28
- const foundConfigs = [];
31
+ // $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
32
+ function findComponentConfig(ast: $FlowFixMe, parser: Parser) {
33
+ const foundConfigs: Array<{[string]: string}> = [];
29
34
 
30
35
  const defaultExports = ast.body.filter(
31
36
  node => node.type === 'ExportDefaultDeclaration',
32
37
  );
33
38
 
34
- defaultExports.forEach(statement => {
35
- let declaration = statement.declaration;
36
-
37
- // codegenNativeComponent can be nested inside a cast
38
- // expression so we need to go one level deeper
39
- if (declaration.type === 'TSAsExpression') {
40
- declaration = declaration.expression;
41
- }
42
-
43
- try {
44
- if (declaration.callee.name === 'codegenNativeComponent') {
45
- const typeArgumentParams = declaration.typeParameters.params;
46
- const funcArgumentParams = declaration.arguments;
47
-
48
- const nativeComponentType: {[string]: string} = {
49
- propsTypeName: typeArgumentParams[0].typeName.name,
50
- componentName: funcArgumentParams[0].value,
51
- };
52
- if (funcArgumentParams.length > 1) {
53
- nativeComponentType.optionsExpression = funcArgumentParams[1];
54
- }
55
- foundConfigs.push(nativeComponentType);
56
- }
57
- } catch (e) {
58
- // ignore
59
- }
60
- });
39
+ defaultExports.forEach(statement =>
40
+ findNativeComponentType(statement, foundConfigs, parser),
41
+ );
61
42
 
62
43
  if (foundConfigs.length === 0) {
63
44
  throw new Error('Could not find component config for native component');
@@ -109,21 +90,9 @@ function findComponentConfig(ast) {
109
90
  })
110
91
  .filter(Boolean);
111
92
 
112
- if (commandsTypeNames.length > 1) {
113
- throw new Error('codegenNativeCommands may only be called once in a file');
114
- }
93
+ throwIfMoreThanOneCodegenNativecommands(commandsTypeNames);
115
94
 
116
- return {
117
- ...foundConfig,
118
- commandTypeName:
119
- commandsTypeNames[0] == null
120
- ? null
121
- : commandsTypeNames[0].commandTypeName,
122
- commandOptionsExpression:
123
- commandsTypeNames[0] == null
124
- ? null
125
- : commandsTypeNames[0].commandOptionsExpression,
126
- };
95
+ return createComponentConfig(foundConfig, commandsTypeNames);
127
96
  }
128
97
 
129
98
  function getCommandProperties(
@@ -195,7 +164,7 @@ function buildComponentSchema(
195
164
  commandTypeName,
196
165
  commandOptionsExpression,
197
166
  optionsExpression,
198
- } = findComponentConfig(ast);
167
+ } = findComponentConfig(ast, parser);
199
168
 
200
169
  const types = parser.getTypes(ast);
201
170