Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Codegen-119] add emitBuildEventSchema to parser commons #38810

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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