Skip to content

Commit

Permalink
Remove hardcoded language from modules/index.js (#36435)
Browse files Browse the repository at this point in the history
Summary:
This PR aims to remove the hardcoded language constants to use common parser instead. It is a task of #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

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Remove hardcoded language from modules/index.js to use common parser instead

Pull Request resolved: #36435

Test Plan:
yarn flow:
<img width="145" alt="image" src="https://user-images.githubusercontent.com/40902940/224333480-600cefd0-9dc6-4142-8e88-db20785e49e6.png">

yarn lint:
<img width="504" alt="image" src="https://user-images.githubusercontent.com/40902940/224333852-d510594f-053e-4866-8ceb-5e3e3d074bc2.png">

yarn test
<img width="383" alt="image" src="https://user-images.githubusercontent.com/40902940/224333600-8c772829-2362-4943-895d-1949a0d88918.png">

Reviewed By: cortinico

Differential Revision: D43979030

Pulled By: cipolleschi

fbshipit-source-id: 39c5b99fc628620f1831ed8c4ee531eec0e866c4
  • Loading branch information
MaeIg authored and facebook-github-bot committed Mar 15, 2023
1 parent d9f2cbe commit 26b22a6
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ describe('typeEnumResolution', () => {
{successful: true, type: 'enum', name: 'Foo'},
true /* nullable */,
'SomeModule' /* name */,
'Flow',
enumMap,
parser,
);
Expand Down Expand Up @@ -403,7 +402,6 @@ describe('typeEnumResolution', () => {
{successful: true, type: 'enum', name: 'Foo'},
true /* nullable */,
'SomeModule' /* name */,
'Flow',
enumMap,
parser,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const {
throwIfPartialWithMoreParameter,
} = require('../../error-utils');

const language = 'Flow';

function translateTypeAnnotation(
hasteModuleName: string,
/**
Expand Down Expand Up @@ -295,7 +293,6 @@ function translateTypeAnnotation(
typeResolutionStatus,
nullable,
hasteModuleName,
language,
enumMap,
parser,
);
Expand All @@ -304,7 +301,7 @@ function translateTypeAnnotation(
throw new UnsupportedTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
language,
parser.language(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import type {
NativeModuleObjectTypeAnnotation,
NativeModuleEnumDeclaration,
} from '../CodegenSchema';
import type {ParserType} from './errors';
import type {Parser} from './parser';
import type {
ParserErrorCapturer,
Expand Down Expand Up @@ -206,15 +205,14 @@ function typeEnumResolution(
typeResolution: TypeResolutionStatus,
nullable: boolean,
hasteModuleName: string,
language: ParserType,
enumMap: {...NativeModuleEnumMap},
parser: Parser,
): Nullable<NativeModuleEnumDeclaration> {
if (!typeResolution.successful || typeResolution.type !== 'enum') {
throw new UnsupportedTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
language,
parser.language(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const {
throwIfPartialWithMoreParameter,
} = require('../../error-utils');

const language = 'TypeScript';

function translateObjectTypeAnnotation(
hasteModuleName: string,
/**
Expand Down Expand Up @@ -362,7 +360,6 @@ function translateTypeAnnotation(
typeResolutionStatus,
nullable,
hasteModuleName,
language,
enumMap,
parser,
);
Expand Down Expand Up @@ -406,7 +403,7 @@ function translateTypeAnnotation(
throw new UnsupportedTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
language,
parser.language(),
);
}
}
Expand Down

0 comments on commit 26b22a6

Please sign in to comment.