From 64ea7ce6c5d0e9144e8332224b63f500315a7a48 Mon Sep 17 00:00:00 2001 From: Marco Fiorito Date: Wed, 9 Nov 2022 12:18:31 -0800 Subject: [PATCH] Chore: move translateFunctionTypeAnnotation into emitFunction (#35287) Summary: Part of https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/35287 Test Plan: image Reviewed By: christophpurrer Differential Revision: D41157574 Pulled By: rshest fbshipit-source-id: 21f6fe7dcffd30f4009ca91a6dec81bbd4b0902a --- .../src/parsers/flow/modules/index.js | 23 +++++++++--------- .../src/parsers/parsers-primitives.js | 20 +++++++++++++++- .../src/parsers/typescript/modules/index.js | 24 +++++++++---------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/flow/modules/index.js b/packages/react-native-codegen/src/parsers/flow/modules/index.js index c03e150b5dfb13..677e26058e1c41 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -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) { diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index d0f449ed0aea59..edf32c4cf7169c 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -99,8 +99,26 @@ function emitStringish(nullable: boolean): Nullable { function emitFunction( nullable: boolean, - translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation, + hasteModuleName: string, + typeAnnotation: $FlowFixMe, + types: TypeDeclarationMap, + aliasMap: {...NativeModuleAliasMap}, + tryParse: ParserErrorCapturer, + cxxOnly: boolean, + translateTypeAnnotation: $FlowFixMe, + language: ParserType, ): Nullable { + const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation = + translateFunctionTypeAnnotation( + hasteModuleName, + typeAnnotation, + types, + aliasMap, + tryParse, + cxxOnly, + translateTypeAnnotation, + language, + ); return wrapNullable(nullable, translateFunctionTypeAnnotationValue); } diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/index.js b/packages/react-native-codegen/src/parsers/typescript/modules/index.js index e3f9d2c7c8e18d..9086d36fa8aef7 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -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) {