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 f801d21
Show file tree
Hide file tree
Showing 3 changed files with 55 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
33 changes: 33 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
PropTypeAnnotation,
EventTypeAnnotation,
ObjectTypeAnnotation,
EventTypeShape,
} from '../CodegenSchema.js';

import type {Parser} from './parser';
Expand Down Expand Up @@ -1083,6 +1084,37 @@ function verifyPropNotAlreadyDefined(
}
}

function emitBuildEventSchema(
paperTopLevelNameDeprecated: $FlowFixMe,
name: $FlowFixMe,
optional: $FlowFixMe,
nonNullableBubblingType: void | 'direct' | 'bubble',
argument: ObjectTypeAnnotation<EventTypeAnnotation>,
): ?EventTypeShape {
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 +1143,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 f801d21

Please sign in to comment.