Extracted content of the case FunctionTypeAnnotation into emitFunction in parsers-primitives file (#34950)

Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts the content of the case `FunctionTypeAnnotation` into a single `emitFunction` function inside the parsers-primitives.js file and uses it in both Flow and TypeScript parsers

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract the content of the case `FunctionTypeAnnotation` into a single `emitFunction` function

Pull Request resolved: https://github.com/facebook/react-native/pull/34950

Test Plan:
Run yarn jest react-native-codegen and ensure CI is green
<img width="984" alt="Screenshot 2022-10-12 at 11 18 54 AM" src="https://user-images.githubusercontent.com/86604753/195260414-136f918f-e4b7-4fcf-b0b9-9142872f3cf9.png">

Reviewed By: christophpurrer

Differential Revision: D40296823

Pulled By: cipolleschi

fbshipit-source-id: 3cac407d260481bd6ae7c3e46642e4c16bba3376
This commit is contained in:
mohitcharkha
2022-10-14 03:09:51 -07:00
committed by Facebook GitHub Bot
parent 1eaa092daf
commit c403cd4f11
3 changed files with 19 additions and 10 deletions
@@ -41,6 +41,7 @@ const {
const {
emitBoolean,
emitDouble,
emitFunction,
emitNumber,
emitInt32,
emitObject,
@@ -372,8 +373,7 @@ function translateTypeAnnotation(
});
}
case 'FunctionTypeAnnotation': {
return wrapNullable(
nullable,
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
translateFunctionTypeAnnotation(
hasteModuleName,
typeAnnotation,
@@ -381,8 +381,8 @@ function translateTypeAnnotation(
aliasMap,
tryParse,
cxxOnly,
),
);
);
return emitFunction(nullable, translateFunctionTypeAnnotationValue);
}
case 'UnionTypeAnnotation': {
if (cxxOnly) {
@@ -14,6 +14,7 @@ import type {
Nullable,
NativeModuleAliasMap,
NativeModuleBaseTypeAnnotation,
NativeModuleFunctionTypeAnnotation,
NativeModuleTypeAliasTypeAnnotation,
NativeModuleNumberTypeAnnotation,
BooleanTypeAnnotation,
@@ -23,8 +24,8 @@ import type {
ReservedTypeAnnotation,
ObjectTypeAnnotation,
NativeModulePromiseTypeAnnotation,
VoidTypeAnnotation,
StringTypeAnnotation,
VoidTypeAnnotation,
} from '../CodegenSchema';
import type {ParserType} from './errors';
import type {TypeAliasResolutionStatus} from './utils';
@@ -78,6 +79,12 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
type: 'StringTypeAnnotation',
});
}
function emitFunction(
nullable: boolean,
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
): Nullable<NativeModuleFunctionTypeAnnotation> {
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
}
function typeAliasResolution(
typeAliasResolutionStatus: TypeAliasResolutionStatus,
@@ -161,12 +168,13 @@ function emitObject(
module.exports = {
emitBoolean,
emitDouble,
emitFunction,
emitInt32,
emitNumber,
emitObject,
emitPromise,
emitRootTag,
emitVoid,
emitStringish,
emitVoid,
typeAliasResolution,
};
@@ -41,6 +41,7 @@ const {
const {
emitBoolean,
emitDouble,
emitFunction,
emitNumber,
emitInt32,
emitObject,
@@ -387,8 +388,7 @@ function translateTypeAnnotation(
});
}
case 'TSFunctionType': {
return wrapNullable(
nullable,
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
translateFunctionTypeAnnotation(
hasteModuleName,
typeAnnotation,
@@ -396,8 +396,9 @@ function translateTypeAnnotation(
aliasMap,
tryParse,
cxxOnly,
),
);
);
return emitFunction(nullable, translateFunctionTypeAnnotationValue);
}
case 'TSUnionType': {
if (cxxOnly) {