Skip to content

Commit

Permalink
feat: add emitBuildEventSchema to parser-commons
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Aug 7, 2023
1 parent 589aea0 commit 096734c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
38 changes: 11 additions & 27 deletions packages/react-native-codegen/src/parsers/flow/components/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
const {
getEventArgument,
buildPropertiesForEvent,
emitBuildEventSchema,
} = require('../../parsers-commons');
const {
emitBoolProp,
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,37 @@ function verifyPropNotAlreadyDefined(
}
}

function emitBuildEventSchema(
paperTopLevelNameDeprecated: $FlowFixMe,
name: $FlowFixMe,
optional: $FlowFixMe,
nonNullableBubblingType: void | 'direct' | 'bubble',
argument: ObjectTypeAnnotation<EventTypeAnnotation>,
) {
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,
Expand Down Expand Up @@ -1111,4 +1142,5 @@ module.exports = {
getTypeResolutionStatus,
buildPropertiesForEvent,
verifyPropNotAlreadyDefined,
emitBuildEventSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
const {
getEventArgument,
buildPropertiesForEvent,
emitBuildEventSchema,
} = require('../../parsers-commons');
const {
emitBoolProp,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 096734c

Please sign in to comment.