Add support for stringish in codegen for modules

Summary: Currently codegen for components supposts stringish. I add it also for components. It fallbacks to StringTypeAnnotation (like in codegen for components).

Reviewed By: rickhanlonii

Differential Revision: D16284381

fbshipit-source-id: 8f03cb79d7e2e1dabbdf4f9353d18dd1daf739fd
This commit is contained in:
Michał Osadnik 2019-07-17 06:13:28 -07:00 коммит произвёл Facebook Github Bot
Родитель d1931344b0
Коммит a70a8d0e75
3 изменённых файлов: 41 добавлений и 3 удалений

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

@ -122,6 +122,7 @@ export interface Spec extends TurboModule {
+passBool?: (arg: boolean) => void;
+passNumber: (arg: number) => void;
+passString: (arg: string) => void;
+passStringish: (arg: Stringish) => void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');

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

@ -177,6 +177,25 @@ Object {
"type": "FunctionTypeAnnotation",
},
},
Object {
"name": "passStringish",
"typeAnnotation": Object {
"optional": false,
"params": Array [
Object {
"name": "arg",
"nullable": false,
"typeAnnotation": Object {
"type": "StringTypeAnnotation",
},
},
],
"returnTypeAnnotation": Object {
"type": "VoidTypeAnnotation",
},
"type": "FunctionTypeAnnotation",
},
},
],
},
},

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

@ -97,10 +97,14 @@ function getElementTypeForArrayOrObject(
};
case 'NumberTypeAnnotation':
case 'BooleanTypeAnnotation':
case 'StringTypeAnnotation':
return {
type,
};
case 'StringTypeAnnotation':
case 'Stringish':
return {
type: 'StringTypeAnnotation',
};
case 'Int32':
return {
type: 'Int32TypeAnnotation',
@ -201,7 +205,6 @@ function getTypeAnnotationForParam(
};
case 'NumberTypeAnnotation':
case 'BooleanTypeAnnotation':
case 'StringTypeAnnotation':
return {
nullable,
name: paramName,
@ -209,6 +212,16 @@ function getTypeAnnotationForParam(
type,
},
};
case 'StringTypeAnnotation':
case 'Stringish':
return {
nullable,
name: paramName,
typeAnnotation: {
type: 'StringTypeAnnotation',
},
};
case 'Int32':
return {
nullable,
@ -298,11 +311,16 @@ function getReturnTypeAnnotation(
case 'BooleanTypeAnnotation':
case 'NumberTypeAnnotation':
case 'StringTypeAnnotation':
case 'VoidTypeAnnotation':
return {
type,
};
case 'StringTypeAnnotation':
case 'Stringish':
return {
type: 'StringTypeAnnotation',
};
case 'Int32':
return {
type: 'Int32TypeAnnotation',