Summary: This diff adds ObjectTypeAnnotation to the codegen schema, throwing for the missing implementation sites added in the next diffs for easier review-ability. Also adds a schema fixture that is flow checked for review, but does not export it because the tests would fail

Reviewed By: TheSavior

Differential Revision: D16759109

fbshipit-source-id: 75c93623e8c1ae2003c7cc638e8e3447f0e7aa38
This commit is contained in:
Rick Hanlon 2019-08-12 13:48:09 -07:00 коммит произвёл Facebook Github Bot
Родитель e6debfe1dd
Коммит 06259a7575
6 изменённых файлов: 146 добавлений и 0 удалений

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

@ -101,6 +101,10 @@ type PropTypeTypeAnnotation =
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive',
|}>
| $ReadOnly<{|
type: 'ObjectTypeAnnotation',
properties: ?$ReadOnlyArray<PropTypeShape>,
|}>
| $ReadOnly<{|
type: 'ArrayTypeAnnotation',
elementType:

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

@ -173,6 +173,9 @@ function getNativeTypeFromAnnotation(componentName: string, prop): string {
});
return `std::vector<${itemAnnotation}>`;
}
case 'ObjectTypeAnnotation': {
throw new Error('Object type is not implemented');
}
case 'StringEnumTypeAnnotation':
return getEnumName(componentName, prop.name);
default:
@ -228,6 +231,9 @@ function convertDefaultTypeToString(componentName: string, prop): string {
return '';
}
}
case 'ObjectTypeAnnotation': {
throw new Error('Object type is not implemented');
}
case 'StringEnumTypeAnnotation':
return `${getEnumName(componentName, prop.name)}::${toSafeCppString(
typeAnnotation.default,

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

@ -89,6 +89,9 @@ function getJavaValueForProp(
case 'ArrayTypeAnnotation': {
return '(ReadableArray) value';
}
case 'ObjectTypeAnnotation': {
throw new Error('Object type is not implemented');
}
case 'StringEnumTypeAnnotation':
return '(String) value';
default:

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

@ -68,6 +68,9 @@ function getJavaValueForProp(prop: PropTypeShape, imports): string {
addNullable(imports);
return '@Nullable ReadableArray value';
}
case 'ObjectTypeAnnotation': {
throw new Error('Object type is not implemented');
}
case 'StringEnumTypeAnnotation':
addNullable(imports);
return '@Nullable String value';

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

@ -80,6 +80,8 @@ function getReactDiffProcessValue(typeAnnotation) {
}
}
return j.literal(true);
case 'ObjectTypeAnnotation':
throw new Error('Object type is not implemented');
default:
(typeAnnotation: empty);
throw new Error(

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

@ -523,6 +523,133 @@ const ARRAY_PROPS: SchemaType = {
},
};
const OBJECT_PROPS: SchemaType = {
modules: {
ObjectPropsNativeComponent: {
components: {
ObjectProps: {
extendsProps: [
{
type: 'ReactNativeBuiltInType',
knownTypeName: 'ReactNativeCoreViewProps',
},
],
events: [],
props: [
{
name: 'objectProp',
optional: true,
typeAnnotation: {
type: 'ObjectTypeAnnotation',
properties: [
{
name: 'stringProp',
optional: true,
typeAnnotation: {
type: 'StringTypeAnnotation',
default: '',
},
},
{
name: 'booleanProp',
optional: true,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
default: false,
},
},
{
name: 'floatProp',
optional: true,
typeAnnotation: {
type: 'FloatTypeAnnotation',
default: 0.0,
},
},
{
name: 'intProp',
optional: true,
typeAnnotation: {
type: 'Int32TypeAnnotation',
default: 0,
},
},
{
name: 'stringEnumProp',
optional: true,
typeAnnotation: {
type: 'StringEnumTypeAnnotation',
default: 'option1',
options: [
{
name: 'option1',
},
],
},
},
{
name: 'objectArrayProp',
optional: false,
typeAnnotation: {
type: 'ObjectTypeAnnotation',
properties: [
{
name: 'array',
optional: true,
typeAnnotation: {
type: 'ArrayTypeAnnotation',
elementType: {
type: 'StringTypeAnnotation',
},
},
},
],
},
},
{
name: 'objectPrimitiveRequiredProp',
optional: false,
typeAnnotation: {
type: 'ObjectTypeAnnotation',
properties: [
{
name: 'image',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ImageSourcePrimitive',
},
},
{
name: 'color',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive',
},
},
{
name: 'point',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'PointPrimitive',
},
},
],
},
},
],
},
},
],
commands: [],
},
},
},
},
};
const MULTI_NATIVE_PROP: SchemaType = {
modules: {
Slider: {
@ -1025,6 +1152,7 @@ module.exports = {
IMAGE_PROP,
POINT_PROP,
ARRAY_PROPS,
// OBJECT_PROPS,
MULTI_NATIVE_PROP,
ENUM_PROP,
EVENT_PROPS,