Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
throwIfMoreThanOneModuleInterfaceParserError,
throwIfModuleTypeIsUnsupported,
throwIfUntypedModule,
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
} = require('../error-utils');
const {
UnsupportedModulePropertyParserError,
Expand All @@ -34,6 +35,7 @@ const {
UnsupportedFunctionReturnTypeAnnotationParserError,
UntypedModuleRegistryCallParserError,
MoreThanOneModuleInterfaceParserError,
UnsupportedFunctionParamTypeAnnotationParserError,
} = require('../errors');

describe('throwIfModuleInterfaceIsMisnamed', () => {
Expand Down Expand Up @@ -633,3 +635,20 @@ describe('throwIfMoreThanOneModuleInterfaceParserError', () => {
}).toThrow(MoreThanOneModuleInterfaceParserError);
});
});

describe('throwIfUnsupportedFunctionParamTypeAnnotationParserError', () => {
const nativeModuleName = 'moduleName';
const languageParamTypeAnnotation = {type: 'VoidTypeAnnotation'};
const paramName = 'paramName';
it('throws an UnsupportedFunctionParamTypeAnnotationParserError', () => {
const paramTypeAnnotationType = 'VoidTypeAnnotation';
expect(() => {
throwIfUnsupportedFunctionParamTypeAnnotationParserError(
nativeModuleName,
languageParamTypeAnnotation,
paramName,
paramTypeAnnotationType,
);
}).toThrow(UnsupportedFunctionParamTypeAnnotationParserError);
});
});
17 changes: 17 additions & 0 deletions packages/react-native-codegen/src/parsers/error-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

'use strict';

import type {NativeModuleTypeAnnotation} from '../CodegenSchema';
import type {ParserType} from './errors';

const {
Expand All @@ -24,6 +25,7 @@ const {
UntypedModuleRegistryCallParserError,
UnsupportedModulePropertyParserError,
MoreThanOneModuleInterfaceParserError,
UnsupportedFunctionParamTypeAnnotationParserError,
} = require('./errors.js');

function throwIfModuleInterfaceIsMisnamed(
Expand Down Expand Up @@ -249,6 +251,20 @@ function throwIfMoreThanOneModuleInterfaceParserError(
}
}

function throwIfUnsupportedFunctionParamTypeAnnotationParserError(
nativeModuleName: string,
languageParamTypeAnnotation: $FlowFixMe,
paramName: string,
paramTypeAnnotationType: NativeModuleTypeAnnotation['type'],
) {
throw new UnsupportedFunctionParamTypeAnnotationParserError(
nativeModuleName,
languageParamTypeAnnotation,
paramName,
paramTypeAnnotationType,
);
}

module.exports = {
throwIfModuleInterfaceIsMisnamed,
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
Expand All @@ -261,4 +277,5 @@ module.exports = {
throwIfUntypedModule,
throwIfModuleTypeIsUnsupported,
throwIfMoreThanOneModuleInterfaceParserError,
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
};
1 change: 0 additions & 1 deletion packages/react-native-codegen/src/parsers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ class UnsupportedFunctionParamTypeAnnotationParserError extends ParserError {
flowParamTypeAnnotation: $FlowFixMe,
paramName: string,
invalidParamType: string,
language: ParserType,
) {
super(
nativeModuleName,
Expand Down
22 changes: 7 additions & 15 deletions packages/react-native-codegen/src/parsers/flow/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const {
UnsupportedArrayElementTypeAnnotationParserError,
UnsupportedGenericParserError,
UnsupportedTypeAnnotationParserError,
UnsupportedFunctionParamTypeAnnotationParserError,
UnsupportedEnumDeclarationParserError,
UnsupportedUnionTypeAnnotationParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
Expand All @@ -79,6 +78,7 @@ const {
throwIfUntypedModule,
throwIfModuleTypeIsUnsupported,
throwIfMoreThanOneModuleInterfaceParserError,
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
} = require('../../error-utils');

const language = 'Flow';
Expand Down Expand Up @@ -450,23 +450,15 @@ function translateFunctionTypeAnnotation(
),
);

if (paramTypeAnnotation.type === 'VoidTypeAnnotation') {
throw new UnsupportedFunctionParamTypeAnnotationParserError(
if (
paramTypeAnnotation.type === 'VoidTypeAnnotation' ||
paramTypeAnnotation.type === 'PromiseTypeAnnotation'
) {
return throwIfUnsupportedFunctionParamTypeAnnotationParserError(
hasteModuleName,
flowParam.typeAnnotation,
paramName,
'void',
language,
);
}

if (paramTypeAnnotation.type === 'PromiseTypeAnnotation') {
throw new UnsupportedFunctionParamTypeAnnotationParserError(
hasteModuleName,
flowParam.typeAnnotation,
paramName,
'Promise',
language,
paramTypeAnnotation.type,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
import type {NativeModuleTypeAnnotation} from '../../../CodegenSchema.js';
const {nullGuard} = require('../../parsers-utils');

const {throwIfMoreThanOneModuleRegistryCalls} = require('../../error-utils');
const {
throwIfMoreThanOneModuleRegistryCalls,
throwIfUnsupportedFunctionParamTypeAnnotationParserError,
} = require('../../error-utils');
const {visit} = require('../../utils');
const {
resolveTypeAnnotation,
Expand Down Expand Up @@ -58,7 +61,6 @@ const {
UnsupportedArrayElementTypeAnnotationParserError,
UnsupportedGenericParserError,
UnsupportedTypeAnnotationParserError,
UnsupportedFunctionParamTypeAnnotationParserError,
UnsupportedEnumDeclarationParserError,
UnsupportedUnionTypeAnnotationParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
Expand Down Expand Up @@ -465,23 +467,15 @@ function translateFunctionTypeAnnotation(
),
);

if (paramTypeAnnotation.type === 'VoidTypeAnnotation') {
throw new UnsupportedFunctionParamTypeAnnotationParserError(
hasteModuleName,
typeScriptParam.typeAnnotation,
paramName,
'void',
language,
);
}

if (paramTypeAnnotation.type === 'PromiseTypeAnnotation') {
throw new UnsupportedFunctionParamTypeAnnotationParserError(
if (
paramTypeAnnotation.type === 'VoidTypeAnnotation' ||
paramTypeAnnotation.type === 'PromiseTypeAnnotation'
) {
return throwIfUnsupportedFunctionParamTypeAnnotationParserError(
hasteModuleName,
typeScriptParam.typeAnnotation,
paramName,
'Promise',
language,
paramTypeAnnotation.type,
);
}

Expand Down