From 1809c75b60ef52badc4e102c1cbee4f1c4bfd684 Mon Sep 17 00:00:00 2001 From: MaeIg Date: Wed, 15 Mar 2023 07:14:26 -0700 Subject: [PATCH] Remove hardcoded language from modules/index.js (#36435) Summary: This PR aims to remove the hardcoded language constants to use common parser instead. It is a task of https://github.com/facebook/react-native/issues/34872: > [Codegen 89 - Assigned to MaeIg] Remove the const language variable from flow/modules/index.js and replace its usage with parser.language() > [Codegen 90 - Assigned to MaeIg] Remove the const language variable from typescript/modules/index.js and replace its usage with parser.language() ## Changelog [Internal] [Changed] - Remove hardcoded language from modules/index.js to use common parser instead Pull Request resolved: https://github.com/facebook/react-native/pull/36435 Test Plan: yarn flow: image yarn lint: image yarn test image Reviewed By: cortinico Differential Revision: D43979030 Pulled By: cipolleschi fbshipit-source-id: 39c5b99fc628620f1831ed8c4ee531eec0e866c4 --- .../src/parsers/__tests__/parsers-primitives-test.js | 2 -- .../react-native-codegen/src/parsers/flow/modules/index.js | 5 +---- .../react-native-codegen/src/parsers/parsers-primitives.js | 4 +--- .../src/parsers/typescript/modules/index.js | 5 +---- 4 files changed, 3 insertions(+), 13 deletions(-) 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 ee0a229bded74b..6c09b098daaf84 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 @@ -359,7 +359,6 @@ describe('typeEnumResolution', () => { {successful: true, type: 'enum', name: 'Foo'}, true /* nullable */, 'SomeModule' /* name */, - 'Flow', enumMap, parser, ); @@ -403,7 +402,6 @@ describe('typeEnumResolution', () => { {successful: true, type: 'enum', name: 'Foo'}, true /* nullable */, 'SomeModule' /* name */, - 'Flow', enumMap, parser, ); 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 b76ebec34dab1e..83d512b2435ea9 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -60,8 +60,6 @@ const { throwIfPartialWithMoreParameter, } = require('../../error-utils'); -const language = 'Flow'; - function translateTypeAnnotation( hasteModuleName: string, /** @@ -295,7 +293,6 @@ function translateTypeAnnotation( typeResolutionStatus, nullable, hasteModuleName, - language, enumMap, parser, ); @@ -304,7 +301,7 @@ function translateTypeAnnotation( throw new UnsupportedTypeAnnotationParserError( hasteModuleName, typeAnnotation, - language, + parser.language(), ); } } diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index c87a749d72deb7..13fcb2ce198fdc 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -34,7 +34,6 @@ import type { NativeModuleObjectTypeAnnotation, NativeModuleEnumDeclaration, } from '../CodegenSchema'; -import type {ParserType} from './errors'; import type {Parser} from './parser'; import type { ParserErrorCapturer, @@ -206,7 +205,6 @@ function typeEnumResolution( typeResolution: TypeResolutionStatus, nullable: boolean, hasteModuleName: string, - language: ParserType, enumMap: {...NativeModuleEnumMap}, parser: Parser, ): Nullable { @@ -214,7 +212,7 @@ function typeEnumResolution( throw new UnsupportedTypeAnnotationParserError( hasteModuleName, typeAnnotation, - language, + parser.language(), ); } 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 5208ed333ee78d..2dc95350ddd200 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -64,8 +64,6 @@ const { throwIfPartialWithMoreParameter, } = require('../../error-utils'); -const language = 'TypeScript'; - function translateObjectTypeAnnotation( hasteModuleName: string, /** @@ -362,7 +360,6 @@ function translateTypeAnnotation( typeResolutionStatus, nullable, hasteModuleName, - language, enumMap, parser, ); @@ -406,7 +403,7 @@ function translateTypeAnnotation( throw new UnsupportedTypeAnnotationParserError( hasteModuleName, typeAnnotation, - language, + parser.language(), ); } }