From a70a8d0e75155c06e9660f95d886ced57779adb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osadnik?= Date: Wed, 17 Jul 2019 06:13:28 -0700 Subject: [PATCH] Add support for stringish in codegen for modules Summary: Currently codegen for components supposts stringish. I add it also for components. It fallbacks to StringTypeAnnotation (like in codegen for components). Reviewed By: rickhanlonii Differential Revision: D16284381 fbshipit-source-id: 8f03cb79d7e2e1dabbdf4f9353d18dd1daf739fd --- .../modules/__test_fixtures__/fixtures.js | 1 + .../__snapshots__/module-parser-test.js.snap | 19 +++++++++++++++ .../src/parsers/flow/modules/methods.js | 24 ++++++++++++++++--- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js index 2ff2a4653be..8342d6a1d77 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js @@ -122,6 +122,7 @@ export interface Spec extends TurboModule { +passBool?: (arg: boolean) => void; +passNumber: (arg: number) => void; +passString: (arg: string) => void; + +passStringish: (arg: Stringish) => void; } export default TurboModuleRegistry.getEnforcing('SampleTurboModule'); diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-test.js.snap b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-test.js.snap index cb5f2741167..3dac11c9d9c 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-test.js.snap +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-test.js.snap @@ -177,6 +177,25 @@ Object { "type": "FunctionTypeAnnotation", }, }, + Object { + "name": "passStringish", + "typeAnnotation": Object { + "optional": false, + "params": Array [ + Object { + "name": "arg", + "nullable": false, + "typeAnnotation": Object { + "type": "StringTypeAnnotation", + }, + }, + ], + "returnTypeAnnotation": Object { + "type": "VoidTypeAnnotation", + }, + "type": "FunctionTypeAnnotation", + }, + }, ], }, }, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/methods.js b/packages/react-native-codegen/src/parsers/flow/modules/methods.js index b8cff9a78c6..1d0ffb3dac2 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/methods.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/methods.js @@ -97,10 +97,14 @@ function getElementTypeForArrayOrObject( }; case 'NumberTypeAnnotation': case 'BooleanTypeAnnotation': - case 'StringTypeAnnotation': return { type, }; + case 'StringTypeAnnotation': + case 'Stringish': + return { + type: 'StringTypeAnnotation', + }; case 'Int32': return { type: 'Int32TypeAnnotation', @@ -201,7 +205,6 @@ function getTypeAnnotationForParam( }; case 'NumberTypeAnnotation': case 'BooleanTypeAnnotation': - case 'StringTypeAnnotation': return { nullable, name: paramName, @@ -209,6 +212,16 @@ function getTypeAnnotationForParam( type, }, }; + + case 'StringTypeAnnotation': + case 'Stringish': + return { + nullable, + name: paramName, + typeAnnotation: { + type: 'StringTypeAnnotation', + }, + }; case 'Int32': return { nullable, @@ -298,11 +311,16 @@ function getReturnTypeAnnotation( case 'BooleanTypeAnnotation': case 'NumberTypeAnnotation': - case 'StringTypeAnnotation': case 'VoidTypeAnnotation': return { type, }; + case 'StringTypeAnnotation': + case 'Stringish': + return { + type: 'StringTypeAnnotation', + }; + case 'Int32': return { type: 'Int32TypeAnnotation',