Skip to content

Commit

Permalink
Remove unused language argument in codegen errors (#35732)
Browse files Browse the repository at this point in the history
Summary:
This is not a task from #34872 but I noticed that we were passing `language` arguments that were never used for several errors so I removed them.

## 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 unused language argument in Codegen errors

Pull Request resolved: #35732

Test Plan: I tested using Flow and Jest.

Reviewed By: christophpurrer

Differential Revision: D42266490

Pulled By: rshest

fbshipit-source-id: 7953a98586bf9e927a58222cc27cf88e9c1c1163
  • Loading branch information
Antoine Doubovetzky authored and pull[bot] committed May 9, 2023
1 parent 35df5cc commit 3331238
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,24 @@ describe('throwIfMoreThanOneModuleRegistryCalls', () => {
{name: 'callExpression1'},
{name: 'callExpression2'},
];
const parserType = 'Flow';

expect(() => {
throwIfMoreThanOneModuleRegistryCalls(
nativeModuleName,
callExpressions,
callExpressions.length,
parserType,
);
}).toThrow(MoreThanOneModuleRegistryCallsParserError);
});
it("don't throw error if single module registry call", () => {
const nativeModuleName = 'moduleName';
const callExpressions = [{name: 'callExpression1'}];
const parserType = 'TypeScript';

expect(() => {
throwIfMoreThanOneModuleRegistryCalls(
nativeModuleName,
callExpressions,
callExpressions.length,
parserType,
);
}).not.toThrow(MoreThanOneModuleRegistryCallsParserError);
});
Expand All @@ -123,13 +119,11 @@ describe('throwIfUnusedModuleInterfaceParserError', () => {
const nativeModuleName = 'moduleName';
const callExpressions: Array<$FlowFixMe> = [];
const spec = {name: 'Spec'};
const parserType = 'Flow';
expect(() => {
throwIfUnusedModuleInterfaceParserError(
nativeModuleName,
spec,
callExpressions,
parserType,
);
}).toThrow(UnusedModuleInterfaceParserError);
});
Expand All @@ -138,13 +132,11 @@ describe('throwIfUnusedModuleInterfaceParserError', () => {
const nativeModuleName = 'moduleName';
const callExpressions = [{name: 'callExpression1'}];
const spec = {name: 'Spec'};
const parserType = 'TypeScript';
expect(() => {
throwIfUnusedModuleInterfaceParserError(
nativeModuleName,
spec,
callExpressions,
parserType,
);
}).not.toThrow(UnusedModuleInterfaceParserError);
});
Expand All @@ -156,14 +148,12 @@ describe('throwErrorIfWrongNumberOfCallExpressionArgs', () => {
const flowCallExpression: {argument: Array<$FlowFixMe>} = {argument: []};
const methodName = 'methodName';
const numberOfCallExpressionArgs = flowCallExpression.argument.length;
const language = 'Flow';
expect(() => {
throwIfWrongNumberOfCallExpressionArgs(
nativeModuleName,
flowCallExpression,
methodName,
numberOfCallExpressionArgs,
language,
);
}).toThrow(IncorrectModuleRegistryCallArityParserError);
});
Expand All @@ -173,14 +163,12 @@ describe('throwErrorIfWrongNumberOfCallExpressionArgs', () => {
const flowCallExpression = {argument: ['argument']};
const methodName = 'methodName';
const numberOfCallExpressionArgs = flowCallExpression.argument.length;
const language = 'Flow';
expect(() => {
throwIfWrongNumberOfCallExpressionArgs(
nativeModuleName,
flowCallExpression,
methodName,
numberOfCallExpressionArgs,
language,
);
}).not.toThrow(IncorrectModuleRegistryCallArityParserError);
});
Expand All @@ -191,8 +179,7 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => {
returnType: '',
},
nativeModuleName = 'moduleName',
invalidReturnType = 'FunctionTypeAnnotation',
language = 'Flow';
invalidReturnType = 'FunctionTypeAnnotation';

it('do not throw error if cxxOnly is true', () => {
const cxxOnly = true,
Expand All @@ -203,7 +190,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => {
nativeModuleName,
returnTypeAnnotation,
invalidReturnType,
language,
cxxOnly,
returnType,
);
Expand All @@ -219,7 +205,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => {
nativeModuleName,
returnTypeAnnotation,
invalidReturnType,
language,
cxxOnly,
returnType,
);
Expand All @@ -235,7 +220,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => {
nativeModuleName,
returnTypeAnnotation,
invalidReturnType,
language,
cxxOnly,
returnType,
);
Expand Down Expand Up @@ -485,15 +469,13 @@ describe('throwIfUntypedModule', () => {

it('should throw error if module does not have a type', () => {
const typeArguments = null;
const language = 'Flow';
expect(() =>
throwIfUntypedModule(
typeArguments,
hasteModuleName,
callExpressions,
methodName,
moduleName,
language,
),
).toThrowError(UntypedModuleRegistryCallParserError);
});
Expand All @@ -504,15 +486,13 @@ describe('throwIfUntypedModule', () => {
params: [],
};

const language = 'TypeScript';
expect(() =>
throwIfUntypedModule(
typeArguments,
hasteModuleName,
callExpressions,
methodName,
moduleName,
language,
),
).not.toThrowError(UntypedModuleRegistryCallParserError);
});
Expand Down Expand Up @@ -644,7 +624,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
UnsupportedArrayElementTypeAnnotationParserError,
} = require('../errors.js');
const moduleName = 'moduleName';
const language = 'Flow';

it('throws the error if it is the type is void type annotation', () => {
expect(() => {
Expand All @@ -653,7 +632,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
undefined,
'Array',
'VoidTypeAnnotation',
language,
);
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError);
});
Expand All @@ -665,7 +643,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
undefined,
'Array',
'PromiseTypeAnnotation',
language,
);
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError);
});
Expand All @@ -677,7 +654,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
undefined,
'Array',
'FunctionTypeAnnotation',
language,
);
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError);
});
Expand All @@ -689,7 +665,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => {
undefined,
'Array',
'StringTypeAnnotation',
language,
);
}).not.toThrow(UnsupportedArrayElementTypeAnnotationParserError);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ describe('emitUnion', () => {
hasteModuleName,
typeAnnotation,
unionTypes,
flowParser.language(),
);

expect(() => {
Expand All @@ -687,7 +686,6 @@ describe('emitUnion', () => {
hasteModuleName,
typeAnnotation,
unionTypes,
flowParser.language(),
);

expect(() => {
Expand Down Expand Up @@ -887,7 +885,6 @@ describe('emitUnion', () => {
hasteModuleName,
typeAnnotation,
unionTypes,
typeScriptParser.language(),
);

expect(() => {
Expand All @@ -902,7 +899,6 @@ describe('emitUnion', () => {
hasteModuleName,
typeAnnotation,
unionTypes,
typeScriptParser.language(),
);

expect(() => {
Expand Down
20 changes: 1 addition & 19 deletions packages/react-native-codegen/src/parsers/error-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ function throwIfMoreThanOneModuleRegistryCalls(
hasteModuleName: string,
callExpressions: $FlowFixMe,
callExpressionsLength: number,
language: ParserType,
) {
if (callExpressions.length > 1) {
throw new MoreThanOneModuleRegistryCallsParserError(
hasteModuleName,
callExpressions,
callExpressionsLength,
language,
);
}
}
Expand All @@ -79,14 +77,9 @@ function throwIfUnusedModuleInterfaceParserError(
nativeModuleName: string,
moduleSpec: $FlowFixMe,
callExpressions: $FlowFixMe,
language: ParserType,
) {
if (callExpressions.length === 0) {
throw new UnusedModuleInterfaceParserError(
nativeModuleName,
moduleSpec,
language,
);
throw new UnusedModuleInterfaceParserError(nativeModuleName, moduleSpec);
}
}

Expand All @@ -95,15 +88,13 @@ function throwIfWrongNumberOfCallExpressionArgs(
flowCallExpression: $FlowFixMe,
methodName: string,
numberOfCallExpressionArgs: number,
language: ParserType,
) {
if (numberOfCallExpressionArgs !== 1) {
throw new IncorrectModuleRegistryCallArityParserError(
nativeModuleName,
flowCallExpression,
methodName,
numberOfCallExpressionArgs,
language,
);
}
}
Expand All @@ -121,7 +112,6 @@ function throwIfIncorrectModuleRegistryCallTypeParameterParserError(
typeArguments,
methodName,
moduleName,
parser.language(),
);
}

Expand All @@ -134,7 +124,6 @@ function throwIfUnsupportedFunctionReturnTypeAnnotationParserError(
nativeModuleName: string,
returnTypeAnnotation: $FlowFixMe,
invalidReturnType: string,
language: ParserType,
cxxOnly: boolean,
returnType: string,
) {
Expand All @@ -143,7 +132,6 @@ function throwIfUnsupportedFunctionReturnTypeAnnotationParserError(
nativeModuleName,
returnTypeAnnotation.returnType,
'FunctionTypeAnnotation',
language,
);
}
}
Expand All @@ -154,15 +142,13 @@ function throwIfUntypedModule(
callExpression: $FlowFixMe,
methodName: string,
moduleName: string,
language: ParserType,
) {
if (typeArguments == null) {
throw new UntypedModuleRegistryCallParserError(
hasteModuleName,
callExpression,
methodName,
moduleName,
language,
);
}
}
Expand Down Expand Up @@ -208,7 +194,6 @@ function throwIfPropertyValueTypeIsUnsupported(
propertyValue: $FlowFixMe,
propertyKey: string,
type: string,
language: ParserType,
) {
const invalidPropertyValueType =
UnsupportedObjectPropertyTypeToInvalidPropertyValueTypeMap[type];
Expand All @@ -218,7 +203,6 @@ function throwIfPropertyValueTypeIsUnsupported(
propertyValue,
propertyKey,
invalidPropertyValueType,
language,
);
}

Expand Down Expand Up @@ -256,7 +240,6 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
flowElementType: $FlowFixMe,
flowArrayType: 'Array' | '$ReadOnlyArray' | 'ReadonlyArray',
type: string,
language: ParserType,
) {
const TypeMap = {
FunctionTypeAnnotation: 'FunctionTypeAnnotation',
Expand All @@ -273,7 +256,6 @@ function throwIfArrayElementTypeAnnotationIsUnsupported(
flowElementType,
flowArrayType,
TypeMap[type],
language,
);
}
}
Expand Down
Loading

0 comments on commit 3331238

Please sign in to comment.