@@ -21,45 +21,23 @@ const {categorizeProps} = require('./extends');
2121const { getCommandOptions, getOptions} = require ( './options' ) ;
2222const { getProps} = require ( './props' ) ;
2323const { getProperties} = require ( './componentsUtils.js' ) ;
24- const { createComponentConfig} = require ( '../../parsers-commons' ) ;
2524const { throwIfMoreThanOneCodegenNativecommands} = require ( '../../error-utils' ) ;
25+ const {
26+ createComponentConfig,
27+ findNativeComponentType,
28+ } = require ( '../../parsers-commons' ) ;
2629
27- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
28- * LTI update could not be added via codemod */
29- function findComponentConfig ( ast ) {
30- const foundConfigs = [ ] ;
30+ // $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
31+ function findComponentConfig ( ast : $FlowFixMe , parser : Parser ) {
32+ const foundConfigs : Array < { [ string ] : string } > = [ ] ;
3133
3234 const defaultExports = ast . body . filter (
3335 node => node . type === 'ExportDefaultDeclaration' ,
3436 ) ;
3537
36- defaultExports . forEach ( statement => {
37- let declaration = statement . declaration ;
38-
39- // codegenNativeComponent can be nested inside a cast
40- // expression so we need to go one level deeper
41- if ( declaration . type === 'TSAsExpression' ) {
42- declaration = declaration . expression ;
43- }
44-
45- try {
46- if ( declaration . callee . name === 'codegenNativeComponent' ) {
47- const typeArgumentParams = declaration . typeParameters . params ;
48- const funcArgumentParams = declaration . arguments ;
49-
50- const nativeComponentType : { [ string ] : string } = {
51- propsTypeName : typeArgumentParams [ 0 ] . typeName . name ,
52- componentName : funcArgumentParams [ 0 ] . value ,
53- } ;
54- if ( funcArgumentParams . length > 1 ) {
55- nativeComponentType . optionsExpression = funcArgumentParams [ 1 ] ;
56- }
57- foundConfigs . push ( nativeComponentType ) ;
58- }
59- } catch ( e ) {
60- // ignore
61- }
62- } ) ;
38+ defaultExports . forEach ( statement =>
39+ findNativeComponentType ( statement , foundConfigs , parser ) ,
40+ ) ;
6341
6442 if ( foundConfigs . length === 0 ) {
6543 throw new Error ( 'Could not find component config for native component' ) ;
@@ -185,7 +163,7 @@ function buildComponentSchema(
185163 commandTypeName,
186164 commandOptionsExpression,
187165 optionsExpression,
188- } = findComponentConfig ( ast ) ;
166+ } = findComponentConfig ( ast , parser ) ;
189167
190168 const types = parser . getTypes ( ast ) ;
191169
0 commit comments