diff --git a/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js b/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js index 59facf536401d9..5d72f33d01e2bc 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/error-utils-test.js @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -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); }); @@ -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, @@ -203,7 +190,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => { nativeModuleName, returnTypeAnnotation, invalidReturnType, - language, cxxOnly, returnType, ); @@ -219,7 +205,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => { nativeModuleName, returnTypeAnnotation, invalidReturnType, - language, cxxOnly, returnType, ); @@ -235,7 +220,6 @@ describe('throwIfUnsupportedFunctionReturnTypeAnnotationParserError', () => { nativeModuleName, returnTypeAnnotation, invalidReturnType, - language, cxxOnly, returnType, ); @@ -485,7 +469,6 @@ describe('throwIfUntypedModule', () => { it('should throw error if module does not have a type', () => { const typeArguments = null; - const language = 'Flow'; expect(() => throwIfUntypedModule( typeArguments, @@ -493,7 +476,6 @@ describe('throwIfUntypedModule', () => { callExpressions, methodName, moduleName, - language, ), ).toThrowError(UntypedModuleRegistryCallParserError); }); @@ -504,7 +486,6 @@ describe('throwIfUntypedModule', () => { params: [], }; - const language = 'TypeScript'; expect(() => throwIfUntypedModule( typeArguments, @@ -512,7 +493,6 @@ describe('throwIfUntypedModule', () => { callExpressions, methodName, moduleName, - language, ), ).not.toThrowError(UntypedModuleRegistryCallParserError); }); @@ -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(() => { @@ -653,7 +632,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => { undefined, 'Array', 'VoidTypeAnnotation', - language, ); }).toThrow(UnsupportedArrayElementTypeAnnotationParserError); }); @@ -665,7 +643,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => { undefined, 'Array', 'PromiseTypeAnnotation', - language, ); }).toThrow(UnsupportedArrayElementTypeAnnotationParserError); }); @@ -677,7 +654,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => { undefined, 'Array', 'FunctionTypeAnnotation', - language, ); }).toThrow(UnsupportedArrayElementTypeAnnotationParserError); }); @@ -689,7 +665,6 @@ describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => { undefined, 'Array', 'StringTypeAnnotation', - language, ); }).not.toThrow(UnsupportedArrayElementTypeAnnotationParserError); }); 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 acfead77c81b25..08dc3e5191edff 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 @@ -672,7 +672,6 @@ describe('emitUnion', () => { hasteModuleName, typeAnnotation, unionTypes, - flowParser.language(), ); expect(() => { @@ -687,7 +686,6 @@ describe('emitUnion', () => { hasteModuleName, typeAnnotation, unionTypes, - flowParser.language(), ); expect(() => { @@ -887,7 +885,6 @@ describe('emitUnion', () => { hasteModuleName, typeAnnotation, unionTypes, - typeScriptParser.language(), ); expect(() => { @@ -902,7 +899,6 @@ describe('emitUnion', () => { hasteModuleName, typeAnnotation, unionTypes, - typeScriptParser.language(), ); expect(() => { diff --git a/packages/react-native-codegen/src/parsers/error-utils.js b/packages/react-native-codegen/src/parsers/error-utils.js index 663d0f3cd90f5f..1645634745b70d 100644 --- a/packages/react-native-codegen/src/parsers/error-utils.js +++ b/packages/react-native-codegen/src/parsers/error-utils.js @@ -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, ); } } @@ -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); } } @@ -95,7 +88,6 @@ function throwIfWrongNumberOfCallExpressionArgs( flowCallExpression: $FlowFixMe, methodName: string, numberOfCallExpressionArgs: number, - language: ParserType, ) { if (numberOfCallExpressionArgs !== 1) { throw new IncorrectModuleRegistryCallArityParserError( @@ -103,7 +95,6 @@ function throwIfWrongNumberOfCallExpressionArgs( flowCallExpression, methodName, numberOfCallExpressionArgs, - language, ); } } @@ -121,7 +112,6 @@ function throwIfIncorrectModuleRegistryCallTypeParameterParserError( typeArguments, methodName, moduleName, - parser.language(), ); } @@ -134,7 +124,6 @@ function throwIfUnsupportedFunctionReturnTypeAnnotationParserError( nativeModuleName: string, returnTypeAnnotation: $FlowFixMe, invalidReturnType: string, - language: ParserType, cxxOnly: boolean, returnType: string, ) { @@ -143,7 +132,6 @@ function throwIfUnsupportedFunctionReturnTypeAnnotationParserError( nativeModuleName, returnTypeAnnotation.returnType, 'FunctionTypeAnnotation', - language, ); } } @@ -154,7 +142,6 @@ function throwIfUntypedModule( callExpression: $FlowFixMe, methodName: string, moduleName: string, - language: ParserType, ) { if (typeArguments == null) { throw new UntypedModuleRegistryCallParserError( @@ -162,7 +149,6 @@ function throwIfUntypedModule( callExpression, methodName, moduleName, - language, ); } } @@ -208,7 +194,6 @@ function throwIfPropertyValueTypeIsUnsupported( propertyValue: $FlowFixMe, propertyKey: string, type: string, - language: ParserType, ) { const invalidPropertyValueType = UnsupportedObjectPropertyTypeToInvalidPropertyValueTypeMap[type]; @@ -218,7 +203,6 @@ function throwIfPropertyValueTypeIsUnsupported( propertyValue, propertyKey, invalidPropertyValueType, - language, ); } @@ -256,7 +240,6 @@ function throwIfArrayElementTypeAnnotationIsUnsupported( flowElementType: $FlowFixMe, flowArrayType: 'Array' | '$ReadOnlyArray' | 'ReadonlyArray', type: string, - language: ParserType, ) { const TypeMap = { FunctionTypeAnnotation: 'FunctionTypeAnnotation', @@ -273,7 +256,6 @@ function throwIfArrayElementTypeAnnotationIsUnsupported( flowElementType, flowArrayType, TypeMap[type], - language, ); } } diff --git a/packages/react-native-codegen/src/parsers/errors.js b/packages/react-native-codegen/src/parsers/errors.js index 4576f23c0764b4..09e49be0fe9ccd 100644 --- a/packages/react-native-codegen/src/parsers/errors.js +++ b/packages/react-native-codegen/src/parsers/errors.js @@ -176,7 +176,6 @@ class UnsupportedArrayElementTypeAnnotationParserError extends ParserError { arrayElementTypeAST: $FlowFixMe, arrayType: 'Array' | '$ReadOnlyArray' | 'ReadonlyArray', invalidArrayElementType: string, - language: ParserType, ) { super( nativeModuleName, @@ -216,7 +215,6 @@ class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserErro propertyValueAST: $FlowFixMe, propertyName: string, invalidPropertyValueType: string, - language: ParserType, ) { super( nativeModuleName, @@ -231,11 +229,7 @@ class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserErro */ class UnnamedFunctionParamParserError extends ParserError { - constructor( - functionParam: $FlowFixMe, - nativeModuleName: string, - language: ParserType, - ) { + constructor(functionParam: $FlowFixMe, nativeModuleName: string) { super( nativeModuleName, functionParam, @@ -264,7 +258,6 @@ class UnsupportedFunctionReturnTypeAnnotationParserError extends ParserError { nativeModuleName: string, flowReturnTypeAnnotation: $FlowFixMe, invalidReturnType: string, - language: ParserType, ) { super( nativeModuleName, @@ -283,7 +276,6 @@ class UnsupportedEnumDeclarationParserError extends ParserError { nativeModuleName: string, arrayElementTypeAST: $FlowFixMe, memberType: string, - language: ParserType, ) { super( nativeModuleName, @@ -302,7 +294,6 @@ class UnsupportedUnionTypeAnnotationParserError extends ParserError { nativeModuleName: string, arrayElementTypeAST: $FlowFixMe, types: UnionTypeAnnotationMemberType[], - language: ParserType, ) { super( nativeModuleName, @@ -319,11 +310,7 @@ class UnsupportedUnionTypeAnnotationParserError extends ParserError { */ class UnusedModuleInterfaceParserError extends ParserError { - constructor( - nativeModuleName: string, - flowInterface: $FlowFixMe, - language: ParserType, - ) { + constructor(nativeModuleName: string, flowInterface: $FlowFixMe) { super( nativeModuleName, flowInterface, @@ -337,7 +324,6 @@ class MoreThanOneModuleRegistryCallsParserError extends ParserError { nativeModuleName: string, flowCallExpressions: $FlowFixMe, numCalls: number, - language: ParserType, ) { super( nativeModuleName, @@ -353,7 +339,6 @@ class UntypedModuleRegistryCallParserError extends ParserError { flowCallExpression: $FlowFixMe, methodName: string, moduleName: string, - language: ParserType, ) { super( nativeModuleName, @@ -369,7 +354,6 @@ class IncorrectModuleRegistryCallTypeParameterParserError extends ParserError { flowTypeArguments: $FlowFixMe, methodName: string, moduleName: string, - language: ParserType, ) { super( nativeModuleName, @@ -385,7 +369,6 @@ class IncorrectModuleRegistryCallArityParserError extends ParserError { flowCallExpression: $FlowFixMe, methodName: string, incorrectArity: number, - language: ParserType, ) { super( nativeModuleName, @@ -401,7 +384,6 @@ class IncorrectModuleRegistryCallArgumentTypeParserError extends ParserError { flowArgument: $FlowFixMe, methodName: string, type: string, - language: ParserType, ) { const a = /[aeiouy]/.test(type.toLowerCase()) ? 'an' : 'a'; super( 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 f43c8c3381b6e8..f89169c240be52 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -331,14 +331,12 @@ function buildModuleSchema( hasteModuleName, moduleSpec, callExpressions, - language, ); throwIfMoreThanOneModuleRegistryCalls( hasteModuleName, callExpressions, callExpressions.length, - language, ); const [callExpression] = callExpressions; @@ -350,7 +348,6 @@ function buildModuleSchema( callExpression, methodName, callExpression.arguments.length, - language, ); if (callExpression.arguments[0].type !== 'Literal') { @@ -360,7 +357,6 @@ function buildModuleSchema( callExpression.arguments[0], methodName, type, - language, ); } @@ -372,7 +368,6 @@ function buildModuleSchema( callExpression, methodName, $moduleName, - language, ); throwIfIncorrectModuleRegistryCallTypeParameterParserError( diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index a4492ac040451c..34ec824de1c319 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -166,7 +166,6 @@ function parseObjectProperty( languageTypeAnnotation, property.key, propertyTypeAnnotation.type, - language, ); } @@ -203,7 +202,6 @@ function translateDefault( hasteModuleName, typeAnnotation, memberType, - parser.language(), ); } } @@ -274,11 +272,7 @@ function translateFunctionTypeAnnotation( )) { const parsedParam = tryParse(() => { if (getFunctionNameFromParameter(param, parser.language()) == null) { - throw new UnnamedFunctionParamParserError( - param, - hasteModuleName, - parser.language(), - ); + throw new UnnamedFunctionParamParserError(param, hasteModuleName); } const paramName = getParameterName(param, parser.language()); @@ -340,7 +334,6 @@ function translateFunctionTypeAnnotation( hasteModuleName, typeAnnotation, 'FunctionTypeAnnotation', - parser.language(), cxxOnly, returnTypeAnnotation.type, ); diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index d29bac2b443fa8..60ee07bc9de83e 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -267,7 +267,6 @@ function emitUnion( hasteModuleName, typeAnnotation, unionTypes, - parser.language(), ); } @@ -319,7 +318,6 @@ function translateArrayTypeAnnotation( elementType, arrayType, _elementType.type, - parser.language(), ); return wrapNullable(nullable, { 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 03fe16f0d05f70..f3a182d71b8ea4 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -336,14 +336,12 @@ function buildModuleSchema( hasteModuleName, moduleSpec, callExpressions, - language, ); throwIfMoreThanOneModuleRegistryCalls( hasteModuleName, callExpressions, callExpressions.length, - language, ); const [callExpression] = callExpressions; @@ -355,7 +353,6 @@ function buildModuleSchema( callExpression, methodName, callExpression.arguments.length, - language, ); if (callExpression.arguments[0].type !== 'StringLiteral') { @@ -365,7 +362,6 @@ function buildModuleSchema( callExpression.arguments[0], methodName, type, - language, ); } @@ -377,7 +373,6 @@ function buildModuleSchema( callExpression, methodName, $moduleName, - language, ); throwIfIncorrectModuleRegistryCallTypeParameterParserError(