Add support for casting codegenNativeComponent

Summary: Adds support for casting the codegenNativeComponent export

Reviewed By: TheSavior

Differential Revision: D16676207

fbshipit-source-id: 5e874bd5a72eb7e67e05b0f671856ae3319a335e
This commit is contained in:
Rick Hanlon
2019-08-08 09:22:08 -07:00
committed by Facebook Github Bot
parent 57fe1f4b82
commit 9b1465b74f
5 changed files with 273 additions and 148 deletions
@@ -23,16 +23,12 @@ const COMMANDS_DEFINED_INLINE = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEvent,
DirectEvent,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
export type ModuleProps = $ReadOnly<{|
...ViewProps,
@@ -40,12 +36,14 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<{
+hotspotUpdate: (ref: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
+hotspotUpdate: (ref: React.Ref<'RCTView'>, x: Int32, y: Int32) => void,
}>({
supportedCommands: ['hotspotUpdate']
supportedCommands: ['hotspotUpdate'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_MULTIPLE_TIMES = `
@@ -61,16 +59,12 @@ const COMMANDS_DEFINED_MULTIPLE_TIMES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEvent,
DirectEvent,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
@@ -82,13 +76,15 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate']
supportedCommands: ['hotspotUpdate'],
});
export const Commands2 = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate']
supportedCommands: ['hotspotUpdate'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_WITHOUT_REF = `
@@ -104,16 +100,12 @@ const COMMANDS_DEFINED_WITHOUT_REF = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEvent,
DirectEvent,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (x: Int32, y: Int32) => void;
@@ -125,10 +117,12 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate']
supportedCommands: ['hotspotUpdate'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_WITH_NULLABLE_REF = `
@@ -144,16 +138,12 @@ const COMMANDS_DEFINED_WITH_NULLABLE_REF = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEvent,
DirectEvent,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (viewRef: ?React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
@@ -165,10 +155,12 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate']
supportedCommands: ['hotspotUpdate'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_WITH_MISMATCHED_METHOD_NAMES = `
@@ -184,20 +176,20 @@ const COMMANDS_DEFINED_WITH_MISMATCHED_METHOD_NAMES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
+scrollTo: (viewRef: React.Ref<'RCTView'>, y: Int32, animated: boolean) => void;
+scrollTo: (
viewRef: React.Ref<'RCTView'>,
y: Int32,
animated: boolean,
) => void;
}
export type ModuleProps = $ReadOnly<{|
@@ -206,10 +198,12 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['scrollTo']
supportedCommands: ['scrollTo'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_WITHOUT_METHOD_NAMES = `
@@ -225,20 +219,20 @@ const COMMANDS_DEFINED_WITHOUT_METHOD_NAMES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
+scrollTo: (viewRef: React.Ref<'RCTView'>, y: Int32, animated: boolean) => void;
+scrollTo: (
viewRef: React.Ref<'RCTView'>,
y: Int32,
animated: boolean,
) => void;
}
export type ModuleProps = $ReadOnly<{|
@@ -248,7 +242,9 @@ export type ModuleProps = $ReadOnly<{|
export const Commands = codegenNativeCommands<NativeCommands>();
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const NULLABLE_WITH_DEFAULT = `
@@ -266,20 +262,18 @@ const NULLABLE_WITH_DEFAULT = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {
WithDefault,
Float,
} from 'CodegenTypes';
import type {WithDefault, Float} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
export type ModuleProps = $ReadOnly<{|
...ViewProps,
nullable_with_default: ?WithDefault<Float, 1.0>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE = `
@@ -297,21 +291,20 @@ const NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {
WithDefault,
Float,
} from 'CodegenTypes';
import type {WithDefault, Float} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
export type ModuleProps = $ReadOnly<{|
...ViewProps,
required_key_with_default: WithDefault<Float, 1.0>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
module.exports = {
COMMANDS_DEFINED_INLINE,
COMMANDS_DEFINED_MULTIPLE_TIMES,
@@ -82,8 +82,48 @@ import type {
DirectEventHandler,
WithDefault,
} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
// Props
boolean_default_true_optional_both?: WithDefault<boolean, true>,
// Events
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
export default (codegenNativeComponent<ModuleProps>('Module', {
interfaceOnly: true,
paperComponentName: 'RCTModule',
}): NativeComponent<ModuleProps>);
`;
const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS_NO_CAST = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
import type {
BubblingEventHandler,
DirectEventHandler,
WithDefault,
} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
@@ -118,14 +158,15 @@ const NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
|}>;
export default codegenNativeComponent<ModuleProps>('Module', {
export default (codegenNativeComponent<ModuleProps>('Module', {
deprecatedViewConfigName: 'DeprecateModuleName',
});
}): NativeComponent<ModuleProps>);
`;
const ALL_PROP_TYPES_NO_EVENTS = `
@@ -143,15 +184,11 @@ const ALL_PROP_TYPES_NO_EVENTS = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
Float,
WithDefault,
} from 'CodegenTypes';
import type {ColorValue, ColorArrayValue, PointValue} from 'StyleSheetTypes';
import type {Int32, Float, WithDefault} from 'CodegenTypes';
import type {ImageSource} from 'ImageSource';
import type {ColorValue, ColorArrayValue, PointValue} from 'StyleSheetTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
@@ -191,8 +228,8 @@ type ModuleProps = $ReadOnly<{|
int32_optional_both?: WithDefault<Int32, 1>,
// String enum props
enum_optional_key?: WithDefault<('small' | 'large'), 'small'>,
enum_optional_both?: WithDefault<('small' | 'large'), 'small'>,
enum_optional_key?: WithDefault<'small' | 'large', 'small'>,
enum_optional_both?: WithDefault<'small' | 'large', 'small'>,
// ImageSource props
image_required: ImageSource,
@@ -218,7 +255,9 @@ type ModuleProps = $ReadOnly<{|
point_optional_both?: ?PointValue,
|}>;
export default codegenNativeComponent<ModuleProps, Options>('Module');
export default (codegenNativeComponent<ModuleProps, Options>(
'Module',
): NativeComponent<ModuleProps>);
`;
const ARRAY_PROP_TYPES_NO_EVENTS = `
@@ -236,15 +275,11 @@ const ARRAY_PROP_TYPES_NO_EVENTS = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
Float,
WithDefault,
} from 'CodegenTypes';
import type {ColorValue, PointValue} from 'StyleSheetTypes';
import type {Int32, Float, WithDefault} from 'CodegenTypes';
import type {ImageSource} from 'ImageSource';
import type {ColorValue, PointValue} from 'StyleSheetTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
@@ -275,8 +310,14 @@ type ModuleProps = $ReadOnly<{|
array_int32_optional_both?: ?$ReadOnlyArray<Int32>,
// String enum props
array_enum_optional_key?: WithDefault<$ReadOnlyArray<('small' | 'large')>, 'small'>,
array_enum_optional_both?: WithDefault<$ReadOnlyArray<('small' | 'large')>, 'small'>,
array_enum_optional_key?: WithDefault<
$ReadOnlyArray<'small' | 'large'>,
'small',
>,
array_enum_optional_both?: WithDefault<
$ReadOnlyArray<'small' | 'large'>,
'small',
>,
// ImageSource props
array_image_required: $ReadOnlyArray<ImageSource>,
@@ -297,7 +338,9 @@ type ModuleProps = $ReadOnly<{|
array_point_optional_both?: ?$ReadOnlyArray<PointValue>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const EVENTS_DEFINED_INLINE_WITH_ALL_TYPES = `
@@ -313,6 +356,7 @@ const EVENTS_DEFINED_INLINE_WITH_ALL_TYPES = `
'use strict';
import type {NativeComponent} from 'codegenNativeComponent';
const codegenNativeComponent = require('codegenNativeComponent');
import type {
@@ -402,8 +446,9 @@ type ModuleProps = $ReadOnly<{|
>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const EVENTS_DEFINED_AS_NULL_INLINE = `
@@ -421,14 +466,9 @@ const EVENTS_DEFINED_AS_NULL_INLINE = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypese';
import type {BubblingEventHandler, DirectEventHandler} from 'CodegenTypese';
import type {ViewProps} from 'ViewPropTypes';
const codegenNativeComponent = require('codegenNativeComponent');
import type {NativeComponent} from 'codegenNativeComponent';
type ModuleProps = $ReadOnly<{|
...ViewProps,
@@ -436,28 +476,28 @@ type ModuleProps = $ReadOnly<{|
// No props
// Events defined inline
onDirectEventDefinedInlineNull:DirectEventHandler<null>,
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onDirectEventDefinedInlineNullOptionalKey?: DirectEventHandler<null>,
onDirectEventDefinedInlineNullOptionalValue: ?DirectEventHandler<null>,
onDirectEventDefinedInlineNullOptionalBoth?: DirectEventHandler<null>,
onDirectEventDefinedInlineNullWithPaperName?: ?
DirectEventHandler<
null,
'paperDirectEventDefinedInlineNullWithPaperName',
>,
onDirectEventDefinedInlineNullWithPaperName?: ?DirectEventHandler<
null,
'paperDirectEventDefinedInlineNullWithPaperName',
>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
onBubblingEventDefinedInlineNullOptionalKey?: BubblingEventHandler<null>,
onBubblingEventDefinedInlineNullOptionalValue: ?BubblingEventHandler<null>,
onBubblingEventDefinedInlineNullOptionalBoth?: ?BubblingEventHandler<null>,
onBubblingEventDefinedInlineNullWithPaperName?: ?
BubblingEventHandler<
null,
'paperBubblingEventDefinedInlineNullWithPaperName',
>,
onBubblingEventDefinedInlineNullWithPaperName?: ?BubblingEventHandler<
null,
'paperBubblingEventDefinedInlineNullWithPaperName',
>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const PROPS_AND_EVENTS_TYPES_EXPORTED = `
@@ -477,8 +517,8 @@ import type {
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
const codegenNativeComponent = require('codegenNativeComponent');
@@ -498,7 +538,9 @@ export type ModuleProps = $ReadOnly<{|
onDirectEventDefinedInlineWithPaperName: DirectEventHandler<EventInFile, 'paperDirectEventDefinedInlineWithPaperName'>,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const PROPS_AS_EXTERNAL_TYPES = `
@@ -514,6 +556,10 @@ const PROPS_AS_EXTERNAL_TYPES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
import type {NativeComponent} from 'codegenNativeComponent';
export type String = string;
export type AnotherArray = $ReadOnlyArray<String>;
@@ -522,7 +568,9 @@ export type ModuleProps = $ReadOnly<{|
array: AnotherArray,
|}>;
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_DEFINED_WITH_ALL_TYPES = `
@@ -538,20 +586,20 @@ const COMMANDS_DEFINED_WITH_ALL_TYPES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
interface NativeCommands {
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
+scrollTo: (viewRef: React.Ref<'RCTView'>, y: Int32, animated: boolean) => void;
+scrollTo: (
viewRef: React.Ref<'RCTView'>,
y: Int32,
animated: boolean,
) => void;
}
export type ModuleProps = $ReadOnly<{|
@@ -560,10 +608,12 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate', 'scrollTo']
supportedCommands: ['hotspotUpdate', 'scrollTo'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_WITH_EXTERNAL_TYPES = `
@@ -579,22 +629,22 @@ const COMMANDS_WITH_EXTERNAL_TYPES = `
'use strict';
const codegenNativeComponent = require('codegenNativeComponent');
const codegenNativeCommands = require('codegenNativeCommands');
const codegenNativeComponent = require('codegenNativeComponent');
import type {
Int32,
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {Int32} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
export type Boolean = boolean;
export type Int = Int32;
export type Void = void;
export type ScrollTo = (viewRef: React.Ref<'RCTView'>, y: Int, animated: Boolean) => Void
export type ScrollTo = (
viewRef: React.Ref<'RCTView'>,
y: Int,
animated: Boolean,
) => Void;
interface NativeCommands {
+scrollTo: ScrollTo;
@@ -606,10 +656,12 @@ export type ModuleProps = $ReadOnly<{|
|}>;
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['scrollTo']
supportedCommands: ['scrollTo'],
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
const COMMANDS_AND_EVENTS_TYPES_EXPORTED = `
@@ -629,8 +681,8 @@ import type {
BubblingEventHandler,
DirectEventHandler,
} from 'CodegenTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {NativeComponent} from 'codegenNativeComponent';
const codegenNativeComponent = require('codegenNativeComponent');
@@ -664,13 +716,16 @@ export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['scrollTo']
});
export default codegenNativeComponent<ModuleProps>('Module');
export default (codegenNativeComponent<ModuleProps>(
'Module',
): NativeComponent<ModuleProps>);
`;
module.exports = {
ALL_PROP_TYPES_NO_EVENTS,
ARRAY_PROP_TYPES_NO_EVENTS,
ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS,
ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS_NO_CAST,
NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION,
EVENTS_DEFINED_INLINE_WITH_ALL_TYPES,
EVENTS_DEFINED_AS_NULL_INLINE,
@@ -4293,6 +4293,64 @@ Object {
}
`;
exports[`RN Codegen Flow Parser can generate fixture ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS_NO_CAST 1`] = `
Object {
"modules": Object {
"Module": Object {
"components": Object {
"Module": Object {
"commands": Array [],
"events": Array [
Object {
"bubblingType": "direct",
"name": "onDirectEventDefinedInlineNull",
"optional": false,
"typeAnnotation": Object {
"argument": Object {
"properties": Array [],
"type": "ObjectTypeAnnotation",
},
"type": "EventTypeAnnotation",
},
},
Object {
"bubblingType": "bubble",
"name": "onBubblingEventDefinedInlineNull",
"optional": false,
"typeAnnotation": Object {
"argument": Object {
"properties": Array [],
"type": "ObjectTypeAnnotation",
},
"type": "EventTypeAnnotation",
},
},
],
"extendsProps": Array [
Object {
"knownTypeName": "ReactNativeCoreViewProps",
"type": "ReactNativeBuiltInType",
},
],
"interfaceOnly": true,
"paperComponentName": "RCTModule",
"props": Array [
Object {
"name": "boolean_default_true_optional_both",
"optional": true,
"typeAnnotation": Object {
"default": true,
"type": "BooleanTypeAnnotation",
},
},
],
},
},
},
},
}
`;
exports[`RN Codegen Flow Parser can generate fixture PROPS_AND_EVENTS_TYPES_EXPORTED 1`] = `
Object {
"modules": Object {
@@ -25,10 +25,18 @@ function findComponentConfig(ast) {
);
defaultExports.forEach(statement => {
let declaration = statement.declaration;
// codegenNativeComponent can be nested inside a cast
// expression so we need to go one level deeper
if (declaration.type === 'TypeCastExpression') {
declaration = declaration.expression;
}
try {
if (statement.declaration.callee.name === 'codegenNativeComponent') {
const typeArgumentParams = statement.declaration.typeArguments.params;
const funcArgumentParams = statement.declaration.arguments;
if (declaration.callee.name === 'codegenNativeComponent') {
const typeArgumentParams = declaration.typeArguments.params;
const funcArgumentParams = declaration.arguments;
const nativeComponentType = {};
nativeComponentType.propsTypeName = typeArgumentParams[0].id.name;
+16 -5
View File
@@ -40,11 +40,22 @@ function getConfigType(ast, types): 'module' | 'component' {
const defaultExports = ast.body.filter(
node => node.type === 'ExportDefaultDeclaration',
);
const isComponent =
defaultExports[0] &&
defaultExports[0].declaration &&
defaultExports[0].declaration.callee &&
defaultExports[0].declaration.callee.name === 'codegenNativeComponent';
let isComponent = false;
if (defaultExports.length > 0) {
let declaration = defaultExports[0].declaration;
// codegenNativeComponent can be nested inside a cast
// expression so we need to go one level deeper
if (declaration.type === 'TypeCastExpression') {
declaration = declaration.expression;
}
isComponent =
declaration &&
declaration.callee &&
declaration.callee.name === 'codegenNativeComponent';
}
const typesExtendingTurboModule = Object.keys(types)
.map(typeName => types[typeName])