diff --git a/packages/react-native-codegen/src/parsers/flow/modules/errors.js b/packages/react-native-codegen/src/parsers/flow/modules/errors.js index 806a773397..5a382052e0 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/errors.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/errors.js @@ -133,6 +133,22 @@ class UnsupportedArrayElementTypeAnnotationParserError extends ParserError { */ class UnsupportedObjectPropertyTypeAnnotationParserError extends ParserError { + constructor( + hasteModuleName: string, + propertyAST: $FlowFixMe, + invalidPropertyType: string, + ) { + let message = `'ObjectTypeAnnotation' cannot contain '${invalidPropertyType}'.`; + + if (invalidPropertyType === 'ObjectTypeSpreadProperty') { + message = "Object spread isn't supported in 'ObjectTypeAnnotation's."; + } + + super(hasteModuleName, propertyAST, message); + } +} + +class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserError { constructor( hasteModuleName: string, propertyValueAST: $FlowFixMe, @@ -202,4 +218,5 @@ module.exports = { UnsupportedFunctionReturnTypeAnnotationParserError, UnsupportedModulePropertyParserError, UnsupportedObjectPropertyTypeAnnotationParserError, + UnsupportedObjectPropertyValueTypeAnnotationParserError, }; 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 c8af4f877e..9c71bd6704 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -40,6 +40,7 @@ const { UnsupportedFunctionReturnTypeAnnotationParserError, UnsupportedModulePropertyParserError, UnsupportedObjectPropertyTypeAnnotationParserError, + UnsupportedObjectPropertyValueTypeAnnotationParserError, } = require('./errors.js'); const invariant = require('invariant'); @@ -207,9 +208,17 @@ function translateTypeAnnotation( type: 'ObjectTypeAnnotation', properties: (typeAnnotation.properties: Array<$FlowFixMe>) .map(property => { - const {optional, key} = property; - return guard(() => { + if (property.type !== 'ObjectTypeProperty') { + throw new UnsupportedObjectPropertyTypeAnnotationParserError( + hasteModuleName, + property, + property.type, + ); + } + + const {optional, key} = property; + const [ propertyTypeAnnotation, isPropertyNullable, @@ -224,7 +233,7 @@ function translateTypeAnnotation( ); if (propertyTypeAnnotation.type === 'FunctionTypeAnnotation') { - throw new UnsupportedObjectPropertyTypeAnnotationParserError( + throw new UnsupportedObjectPropertyValueTypeAnnotationParserError( hasteModuleName, property.value, property.key, @@ -233,7 +242,7 @@ function translateTypeAnnotation( } if (propertyTypeAnnotation.type === 'VoidTypeAnnotation') { - throw new UnsupportedObjectPropertyTypeAnnotationParserError( + throw new UnsupportedObjectPropertyValueTypeAnnotationParserError( hasteModuleName, property.value, property.key, @@ -242,7 +251,7 @@ function translateTypeAnnotation( } if (propertyTypeAnnotation.type === 'PromiseTypeAnnotation') { - throw new UnsupportedObjectPropertyTypeAnnotationParserError( + throw new UnsupportedObjectPropertyValueTypeAnnotationParserError( hasteModuleName, property.value, property.key,