diff --git a/packages/react-native-codegen/src/parsers/flow/components/events.js b/packages/react-native-codegen/src/parsers/flow/components/events.js index 71c865dce29d12..78321272efb22c 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -22,7 +22,10 @@ const { throwIfBubblingTypeIsNull, throwIfArgumentPropsAreNull, } = require('../../error-utils'); -const {getEventArgument} = require('../../parsers-commons'); +const { + getEventArgument, + buildPropertiesForEvent, +} = require('../../parsers-commons'); const { emitBoolProp, emitDoubleProp, @@ -67,7 +70,7 @@ function getPropertyType( typeAnnotation: { type: 'ObjectTypeAnnotation', properties: typeAnnotation.properties.map(member => - buildPropertiesForEvent(member, parser), + buildPropertiesForEvent(member, parser, getPropertyType), ), }, }; @@ -126,7 +129,7 @@ function extractArrayElementType( return { type: 'ObjectTypeAnnotation', properties: typeAnnotation.properties.map(member => - buildPropertiesForEvent(member, parser), + buildPropertiesForEvent(member, parser, getPropertyType), ), }; case 'ArrayTypeAnnotation': @@ -229,19 +232,6 @@ function findEventArgumentsAndType( } } -function buildPropertiesForEvent( - /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's - * LTI update could not be added via codemod */ - property, - parser: Parser, -): NamedShape { - const name = property.key.name; - const optional = parser.isOptionalProperty(property); - const typeAnnotation = parser.getTypeAnnotationFromProperty(property); - - return getPropertyType(name, optional, typeAnnotation, parser); -} - function buildEventSchema( types: TypeMap, property: EventTypeAST, @@ -283,8 +273,8 @@ function buildEventSchema( type: 'EventTypeAnnotation', argument: getEventArgument( nonNullableArgumentProps, - buildPropertiesForEvent, parser, + getPropertyType, ), }, }; @@ -298,8 +288,8 @@ function buildEventSchema( type: 'EventTypeAnnotation', argument: getEventArgument( nonNullableArgumentProps, - buildPropertiesForEvent, parser, + getPropertyType, ), }, }; diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index 41f135329425ed..9629c5121d371b 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -894,16 +894,18 @@ function buildPropSchema( * LTI update could not be added via codemod */ function getEventArgument( argumentProps: PropAST, - buildPropertiesForEvent: ( - property: PropAST, + parser: Parser, + getPropertyType: ( + name: $FlowFixMe, + optional: boolean, + typeAnnotation: $FlowFixMe, parser: Parser, ) => NamedShape, - parser: Parser, ): ObjectTypeAnnotation { return { type: 'ObjectTypeAnnotation', properties: argumentProps.map(member => - buildPropertiesForEvent(member, parser), + buildPropertiesForEvent(member, parser, getPropertyType), ), }; } @@ -1053,6 +1055,23 @@ function handleGenericTypeAnnotation( }; } +function buildPropertiesForEvent( + property: $FlowFixMe, + parser: Parser, + getPropertyType: ( + name: $FlowFixMe, + optional: boolean, + typeAnnotation: $FlowFixMe, + parser: Parser, + ) => NamedShape, +): NamedShape { + const name = property.key.name; + const optional = parser.isOptionalProperty(property); + const typeAnnotation = parser.getTypeAnnotationFromProperty(property); + + return getPropertyType(name, optional, typeAnnotation, parser); +} + module.exports = { wrapModuleSchema, unwrapNullable, @@ -1079,4 +1098,5 @@ module.exports = { getCommandProperties, handleGenericTypeAnnotation, getTypeResolutionStatus, + buildPropertiesForEvent, }; diff --git a/packages/react-native-codegen/src/parsers/typescript/components/events.js b/packages/react-native-codegen/src/parsers/typescript/components/events.js index 5d12804238e1b1..fc0bc5530ae4de 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/events.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/events.js @@ -24,7 +24,10 @@ const { throwIfBubblingTypeIsNull, throwIfArgumentPropsAreNull, } = require('../../error-utils'); -const {getEventArgument} = require('../../parsers-commons'); +const { + getEventArgument, + buildPropertiesForEvent, +} = require('../../parsers-commons'); const { emitBoolProp, emitDoubleProp, @@ -69,7 +72,7 @@ function getPropertyType( typeAnnotation: { type: 'ObjectTypeAnnotation', properties: typeAnnotation.members.map(member => - buildPropertiesForEvent(member, parser), + buildPropertiesForEvent(member, parser, getPropertyType), ), }, }; @@ -136,7 +139,7 @@ function extractArrayElementType( return { type: 'ObjectTypeAnnotation', properties: typeAnnotation.members.map(member => - buildPropertiesForEvent(member, parser), + buildPropertiesForEvent(member, parser, getPropertyType), ), }; case 'TSArrayType': @@ -247,19 +250,6 @@ function findEventArgumentsAndType( } } -function buildPropertiesForEvent( - /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's - * LTI update could not be added via codemod */ - property, - parser: Parser, -): NamedShape { - const name = property.key.name; - const optional = parser.isOptionalProperty(property); - const typeAnnotation = parser.getTypeAnnotationFromProperty(property); - - return getPropertyType(name, optional, typeAnnotation, parser); -} - // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser type EventTypeAST = Object; @@ -296,8 +286,8 @@ function buildEventSchema( type: 'EventTypeAnnotation', argument: getEventArgument( nonNullableArgumentProps, - buildPropertiesForEvent, parser, + getPropertyType, ), }, }; @@ -311,8 +301,8 @@ function buildEventSchema( type: 'EventTypeAnnotation', argument: getEventArgument( nonNullableArgumentProps, - buildPropertiesForEvent, parser, + getPropertyType, ), }, };