fallback not understandable types from methods to object

Summary:
We don't want to make our codegen breaking if type is not existing. In order to it we can always fallback to Object. That's how it currently works in old codegen

#Facebook
Thare're few places in our internal code where we use `Map` or tuple in these cases

Reviewed By: RSNara

Differential Revision: D16687360

fbshipit-source-id: bf8aafd3254fc7e18ad0d58ad1a29e2beeb15bf0
This commit is contained in:
Michał Osadnik 2019-08-08 11:09:30 -07:00 коммит произвёл Facebook Github Bot
Родитель 35f81f62c2
Коммит 52c86a96b8
3 изменённых файлов: 14 добавлений и 81 удалений

Просмотреть файл

@ -10,30 +10,6 @@
'use strict';
const NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_PARAM = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {TurboModule} from '../RCTExport';
import * as TurboModuleRegistry from '../TurboModuleRegistry';
export interface Spec extends TurboModule {
getString: (arg: NotString) => string;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
@ -106,30 +82,6 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
const NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_RETURN = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {TurboModule} from '../RCTExport';
import * as TurboModuleRegistry from '../TurboModuleRegistry';
export interface Spec extends TurboModule {
getString: (arg: NotString) => string;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;
const NATIVE_MODULES_WITH_NOT_ONLY_METHODS = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
@ -238,8 +190,6 @@ module.exports = {
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM,
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT,
TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT,
NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_PARAM,
NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_RETURN,
NATIVE_MODULES_WITH_NOT_ONLY_METHODS,
TWO_NATIVE_EXTENDING_TURBO_MODULE,
};

Просмотреть файл

@ -4,10 +4,6 @@ exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARR
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM 1`] = `"Unsupported type for getString, param: \\"arg\\": expected to find annotation for type of array contents"`;
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_PARAM 1`] = `"Unsupported param type for method \\"getString\\", param \\"arg\\". Found NotString"`;
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_NOT_EXISTING_TYPE_AS_RETURN 1`] = `"Unsupported param type for method \\"getString\\", param \\"arg\\". Found NotString"`;
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_NOT_ONLY_METHODS 1`] = `"Only methods are supported as module properties. Found BooleanTypeAnnotation in sampleBool"`;
exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE 1`] = `"Unsupported return promise type for getBool: expected to find annotation for type of promise content"`;

Просмотреть файл

@ -83,10 +83,6 @@ function getElementTypeForArrayOrObject(
`Unsupported type for ${name}, param: "${paramName}": expected to find annotation for type of nested array contents`,
);
}
case 'Object':
return {
type: 'GenericObjectTypeAnnotation',
};
case 'ObjectTypeAnnotation':
return {
type: 'ObjectTypeAnnotation',
@ -137,9 +133,9 @@ function getElementTypeForArrayOrObject(
case 'UnionTypeAnnotation':
return undefined;
default:
throw new Error(
`Unsupported param type for method "${name}", param "${paramName}". Found ${type}`,
);
return {
type: 'GenericObjectTypeAnnotation',
};
}
}
@ -163,14 +159,6 @@ function getTypeAnnotationForParam(
: typeAnnotation.type;
switch (type) {
case 'Object':
return {
nullable,
name: paramName,
typeAnnotation: {
type: 'GenericObjectTypeAnnotation',
},
};
case 'Array':
case '$ReadOnlyArray':
if (
@ -276,9 +264,13 @@ function getTypeAnnotationForParam(
},
};
default:
throw new Error(
`Unsupported param type for method "${name}", param "${paramName}". Found ${type}`,
);
return {
nullable,
name: paramName,
typeAnnotation: {
type: 'GenericObjectTypeAnnotation',
},
};
}
}
@ -299,11 +291,6 @@ function getReturnTypeAnnotation(
: typeAnnotation.type;
switch (type) {
case 'Object':
return {
type: 'GenericObjectTypeAnnotation',
nullable,
};
case 'Promise':
if (
typeAnnotation.typeParameters &&
@ -395,10 +382,10 @@ function getReturnTypeAnnotation(
type: 'FloatTypeAnnotation',
};
default:
(type: empty);
throw new Error(
`Unsupported return type for method "${methodName}", Found ${type}`,
);
return {
type: 'GenericObjectTypeAnnotation',
nullable,
};
}
}