From 95e685a44d4e755d30bb5440c5cb784f1c979e61 Mon Sep 17 00:00:00 2001 From: Pranav Yadav Date: Fri, 4 Nov 2022 05:11:39 -0700 Subject: [PATCH] mv `emitMixedTypeAnnotation` fn > `parsers-primitives.js` (#35185) Summary: This PR is a task of https://github.com/facebook/react-native/issues/34872 - Moved the [emitMixedTypeAnnotation](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L102) function to the [`parser-primitives.js` file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-primitives.js). - Moved tests for the same respectively - Fixed/Updated imports and exports for the same respectively ## Changelog [INTERNAL] [Changed] - Moved the `emitMixedTypeAnnotation` function to the `parser-primitives.js` file. Pull Request resolved: https://github.com/facebook/react-native/pull/35185 Test Plan: `yarn test-ci` ![image](https://user-images.githubusercontent.com/55224033/199693475-60c034bf-cd5c-4cb8-bfe8-e7c7ccbc4300.png) Reviewed By: cipolleschi Differential Revision: D40993027 Pulled By: rshest fbshipit-source-id: 5e025804f4ef6723396accf2f859483f76cb6cd6 --- .../parsers/__tests__/parsers-commons-test.js | 27 ------------------- .../__tests__/parsers-primitives-test.js | 27 +++++++++++++++++++ .../src/parsers/flow/modules/index.js | 2 +- .../src/parsers/parsers-commons.js | 10 ------- .../src/parsers/parsers-primitives.js | 11 ++++++++ .../src/parsers/typescript/modules/index.js | 2 +- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js index 7e0237fa924..232a75c4fdc 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js @@ -16,7 +16,6 @@ import type {ParserType} from '../errors'; const { wrapNullable, unwrapNullable, - emitMixedTypeAnnotation, emitUnionTypeAnnotation, } = require('../parsers-commons.js'); const {UnsupportedUnionTypeAnnotationParserError} = require('../errors'); @@ -250,32 +249,6 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => { }); }); -describe('emitMixedTypeAnnotation', () => { - describe('when nullable is true', () => { - it('returns nullable type annotation', () => { - const result = emitMixedTypeAnnotation(true); - const expected = { - type: 'NullableTypeAnnotation', - typeAnnotation: { - type: 'MixedTypeAnnotation', - }, - }; - - expect(result).toEqual(expected); - }); - }); - describe('when nullable is false', () => { - it('returns non nullable type annotation', () => { - const result = emitMixedTypeAnnotation(false); - const expected = { - type: 'MixedTypeAnnotation', - }; - - expect(result).toEqual(expected); - }); - }); -}); - describe('emitUnionTypeAnnotation', () => { const hasteModuleName = 'SampleTurboModule'; diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js index b64c48f776a..ecd36400bc6 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js @@ -23,6 +23,7 @@ const { emitVoid, emitString, emitStringish, + emitMixedTypeAnnotation, typeAliasResolution, } = require('../parsers-primitives.js'); @@ -452,3 +453,29 @@ describe('emitObject', () => { }); }); }); + +describe('emitMixedTypeAnnotation', () => { + describe('when nullable is true', () => { + it('returns nullable type annotation', () => { + const result = emitMixedTypeAnnotation(true); + const expected = { + type: 'NullableTypeAnnotation', + typeAnnotation: { + type: 'MixedTypeAnnotation', + }, + }; + + expect(result).toEqual(expected); + }); + }); + describe('when nullable is false', () => { + it('returns non nullable type annotation', () => { + const result = emitMixedTypeAnnotation(false); + const expected = { + type: 'MixedTypeAnnotation', + }; + + expect(result).toEqual(expected); + }); + }); +}); 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 cd6e2f3e440..ee7842bdb51 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -33,7 +33,6 @@ const { unwrapNullable, wrapNullable, assertGenericTypeAnnotationHasExactlyOneTypeParameter, - emitMixedTypeAnnotation, emitUnionTypeAnnotation, translateDefault, } = require('../../parsers-commons'); @@ -50,6 +49,7 @@ const { emitVoid, emitString, emitStringish, + emitMixedTypeAnnotation, typeAliasResolution, } = require('../../parsers-primitives'); diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index 28ac2725e26..cdeb0c7bf5c 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -15,7 +15,6 @@ import type { NativeModuleSchema, NativeModuleTypeAnnotation, Nullable, - NativeModuleMixedTypeAnnotation, UnionTypeAnnotationMemberType, NativeModuleUnionTypeAnnotation, } from '../CodegenSchema.js'; @@ -107,14 +106,6 @@ function assertGenericTypeAnnotationHasExactlyOneTypeParameter( } } -function emitMixedTypeAnnotation( - nullable: boolean, -): Nullable { - return wrapNullable(nullable, { - type: 'MixedTypeAnnotation', - }); -} - function remapUnionTypeAnnotationMemberNames( types: $FlowFixMe, language: ParserType, @@ -233,7 +224,6 @@ module.exports = { unwrapNullable, wrapNullable, assertGenericTypeAnnotationHasExactlyOneTypeParameter, - emitMixedTypeAnnotation, emitUnionTypeAnnotation, getKeyName, translateDefault, diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index 1b450d044ee..7ccfebc293a 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -17,6 +17,7 @@ import type { NativeModuleFunctionTypeAnnotation, NativeModuleTypeAliasTypeAnnotation, NativeModuleNumberTypeAnnotation, + NativeModuleMixedTypeAnnotation, BooleanTypeAnnotation, DoubleTypeAnnotation, Int32TypeAnnotation, @@ -80,6 +81,7 @@ function emitStringish(nullable: boolean): Nullable { type: 'StringTypeAnnotation', }); } + function emitFunction( nullable: boolean, translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation, @@ -87,6 +89,14 @@ function emitFunction( return wrapNullable(nullable, translateFunctionTypeAnnotationValue); } +function emitMixedTypeAnnotation( + nullable: boolean, +): Nullable { + return wrapNullable(nullable, { + type: 'MixedTypeAnnotation', + }); +} + function emitString(nullable: boolean): Nullable { return wrapNullable(nullable, { type: 'StringTypeAnnotation', @@ -193,5 +203,6 @@ module.exports = { emitVoid, emitString, emitStringish, + emitMixedTypeAnnotation, typeAliasResolution, }; 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 bc5aae5f65e..045b4d6df07 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -36,7 +36,6 @@ const { unwrapNullable, wrapNullable, assertGenericTypeAnnotationHasExactlyOneTypeParameter, - emitMixedTypeAnnotation, emitUnionTypeAnnotation, translateDefault, } = require('../../parsers-commons'); @@ -53,6 +52,7 @@ const { emitVoid, emitString, emitStringish, + emitMixedTypeAnnotation, typeAliasResolution, } = require('../../parsers-primitives'); const {