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 a2e30dc commit 5ae1703
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 @@ -27,6 +27,7 @@ const {
getEventArgument,
buildPropertiesForEvent,
handleEventHandler,
emitBuildEventSchema,
} = require('../../parsers-commons');
const {
emitBoolProp,
Expand Down Expand Up @@ -245,36 +246,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 @@ -1125,6 +1126,37 @@ function handleEventHandler(
}
}

function emitBuildEventSchema(
paperTopLevelNameDeprecated: $FlowFixMe,
name: $FlowFixMe,
optional: $FlowFixMe,
nonNullableBubblingType: '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 @@ -1154,4 +1186,5 @@ module.exports = {
buildPropertiesForEvent,
verifyPropNotAlreadyDefined,
handleEventHandler,
emitBuildEventSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
getEventArgument,
buildPropertiesForEvent,
handleEventHandler,
emitBuildEventSchema,
} = require('../../parsers-commons');
const {
emitBoolProp,
Expand Down Expand Up @@ -259,36 +260,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 5ae1703

Please sign in to comment.