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 fa2b236722f257..2931d148dd7980 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -25,6 +25,7 @@ const { const { getEventArgument, buildPropertiesForEvent, + emitBuildEventSchema, } = require('../../parsers-commons'); const { emitBoolProp, @@ -260,36 +261,19 @@ function buildEventSchema( ); const nonNullableBubblingType = throwIfBubblingTypeIsNull(bubblingType, name); - if (paperTopLevelNameDeprecated != null) { - return { - name, - optional, - bubblingType: nonNullableBubblingType, - paperTopLevelNameDeprecated, - typeAnnotation: { - type: 'EventTypeAnnotation', - argument: getEventArgument( - nonNullableArgumentProps, - parser, - getPropertyType, - ), - }, - }; - } + const argument = getEventArgument( + nonNullableArgumentProps, + parser, + getPropertyType, + ); - return { + return emitBuildEventSchema( + paperTopLevelNameDeprecated, name, optional, - bubblingType: nonNullableBubblingType, - typeAnnotation: { - type: 'EventTypeAnnotation', - argument: getEventArgument( - nonNullableArgumentProps, - parser, - getPropertyType, - ), - }, - }; + nonNullableBubblingType, + argument, + ); } // $FlowFixMe[unclear-type] there's no flowtype for ASTs diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index fb5e639d6123b1..3ac1c0f22a2d91 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -1083,6 +1083,37 @@ function verifyPropNotAlreadyDefined( } } +function emitBuildEventSchema( + paperTopLevelNameDeprecated: $FlowFixMe, + name: $FlowFixMe, + optional: $FlowFixMe, + nonNullableBubblingType: void | 'direct' | 'bubble', + argument: ObjectTypeAnnotation, +) { + if (paperTopLevelNameDeprecated != null) { + return { + name, + optional, + bubblingType: nonNullableBubblingType, + paperTopLevelNameDeprecated, + typeAnnotation: { + type: 'EventTypeAnnotation', + argument: argument, + }, + }; + } + + return { + name, + optional, + bubblingType: nonNullableBubblingType, + typeAnnotation: { + type: 'EventTypeAnnotation', + argument: argument, + }, + }; +} + module.exports = { wrapModuleSchema, unwrapNullable, @@ -1111,4 +1142,5 @@ module.exports = { getTypeResolutionStatus, buildPropertiesForEvent, verifyPropNotAlreadyDefined, + emitBuildEventSchema, }; 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 bcc56ea4f51af8..cedc879b33afb3 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/events.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/events.js @@ -27,6 +27,7 @@ const { const { getEventArgument, buildPropertiesForEvent, + emitBuildEventSchema, } = require('../../parsers-commons'); const { emitBoolProp, @@ -272,36 +273,19 @@ function buildEventSchema( ); const nonNullableBubblingType = throwIfBubblingTypeIsNull(bubblingType, name); - if (paperTopLevelNameDeprecated != null) { - return { - name, - optional, - bubblingType: nonNullableBubblingType, - paperTopLevelNameDeprecated, - typeAnnotation: { - type: 'EventTypeAnnotation', - argument: getEventArgument( - nonNullableArgumentProps, - parser, - getPropertyType, - ), - }, - }; - } + const argument = getEventArgument( + nonNullableArgumentProps, + parser, + getPropertyType, + ); - return { + return emitBuildEventSchema( + paperTopLevelNameDeprecated, name, optional, - bubblingType: nonNullableBubblingType, - typeAnnotation: { - type: 'EventTypeAnnotation', - argument: getEventArgument( - nonNullableArgumentProps, - parser, - getPropertyType, - ), - }, - }; + nonNullableBubblingType, + argument, + ); } function getEvents(