Skip to content

Commit

Permalink
Chore: move translateFunctionTypeAnnotation into emitFunction (#35287)
Browse files Browse the repository at this point in the history
Summary:
Part of #34872

In this PR was moved the translateFunctionTypeAnnotation invocation ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L362), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L376)) into the emitFunction call so that the case FuntionTypeAnnotation results in a one-liner

## Changelog

[Internal] [Changed] - Move the translateFunctionTypeAnnotation invocation into the emitFunction

Pull Request resolved: #35287

Test Plan: <img width="266" alt="image" src="https://user-images.githubusercontent.com/18408823/200852605-96c233d9-b524-4b7c-bc41-5543534c296b.png">

Reviewed By: christophpurrer

Differential Revision: D41157574

Pulled By: rshest

fbshipit-source-id: 21f6fe7dcffd30f4009ca91a6dec81bbd4b0902a
  • Loading branch information
Marcoo09 authored and facebook-github-bot committed Nov 9, 2022
1 parent 1f0c2c2 commit 64ea7ce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
23 changes: 11 additions & 12 deletions packages/react-native-codegen/src/parsers/flow/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,17 @@ function translateTypeAnnotation(
return emitString(nullable);
}
case 'FunctionTypeAnnotation': {
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
translateFunctionTypeAnnotation(
hasteModuleName,
typeAnnotation,
types,
aliasMap,
tryParse,
cxxOnly,
translateTypeAnnotation,
language,
);
return emitFunction(nullable, translateFunctionTypeAnnotationValue);
return emitFunction(
nullable,
hasteModuleName,
typeAnnotation,
types,
aliasMap,
tryParse,
cxxOnly,
translateTypeAnnotation,
language,
);
}
case 'UnionTypeAnnotation': {
if (cxxOnly) {
Expand Down
20 changes: 19 additions & 1 deletion packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,26 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {

function emitFunction(
nullable: boolean,
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
hasteModuleName: string,
typeAnnotation: $FlowFixMe,
types: TypeDeclarationMap,
aliasMap: {...NativeModuleAliasMap},
tryParse: ParserErrorCapturer,
cxxOnly: boolean,
translateTypeAnnotation: $FlowFixMe,
language: ParserType,
): Nullable<NativeModuleFunctionTypeAnnotation> {
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
translateFunctionTypeAnnotation(
hasteModuleName,
typeAnnotation,
types,
aliasMap,
tryParse,
cxxOnly,
translateTypeAnnotation,
language,
);
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,17 @@ function translateTypeAnnotation(
return emitString(nullable);
}
case 'TSFunctionType': {
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
translateFunctionTypeAnnotation(
hasteModuleName,
typeAnnotation,
types,
aliasMap,
tryParse,
cxxOnly,
translateTypeAnnotation,
language,
);

return emitFunction(nullable, translateFunctionTypeAnnotationValue);
return emitFunction(
nullable,
hasteModuleName,
typeAnnotation,
types,
aliasMap,
tryParse,
cxxOnly,
translateTypeAnnotation,
language,
);
}
case 'TSUnionType': {
if (cxxOnly) {
Expand Down

0 comments on commit 64ea7ce

Please sign in to comment.