Make H Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal] Reviewed By: hramos Differential Revision: D24027247 fbshipit-source-id: cc326f5db919de1f6c6b56603f420c87272da918
This commit is contained in:
Родитель
1a90e1b471
Коммит
d9dc9d5d0a
|
@ -10,10 +10,15 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {SchemaType, NativeModuleTypeAnnotation} from '../../CodegenSchema';
|
||||
import type {
|
||||
Nullable,
|
||||
SchemaType,
|
||||
NativeModuleTypeAnnotation,
|
||||
} from '../../CodegenSchema';
|
||||
|
||||
import type {AliasResolver} from './Utils';
|
||||
const {createAliasResolver, getModules} = require('./Utils');
|
||||
const {unwrapNullable} = require('../../parsers/flow/modules/utils');
|
||||
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
|
@ -50,10 +55,11 @@ namespace react {
|
|||
`;
|
||||
|
||||
function translatePrimitiveJSTypeToCpp(
|
||||
typeAnnotation: NativeModuleTypeAnnotation,
|
||||
nullableTypeAnnotation: Nullable<NativeModuleTypeAnnotation>,
|
||||
createErrorMessage: (typeName: string) => string,
|
||||
resolveAlias: AliasResolver,
|
||||
) {
|
||||
const [typeAnnotation] = unwrapNullable(nullableTypeAnnotation);
|
||||
let realTypeAnnotation = typeAnnotation;
|
||||
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
||||
|
@ -116,7 +122,8 @@ module.exports = {
|
|||
|
||||
const traversedProperties = properties
|
||||
.map(prop => {
|
||||
const traversedArgs = prop.typeAnnotation.params
|
||||
const [propTypeAnnotation] = unwrapNullable(prop.typeAnnotation);
|
||||
const traversedArgs = propTypeAnnotation.params
|
||||
.map(param => {
|
||||
const translatedParam = translatePrimitiveJSTypeToCpp(
|
||||
param.typeAnnotation,
|
||||
|
@ -137,7 +144,7 @@ module.exports = {
|
|||
.replace(
|
||||
'::_RETURN_VALUE_::',
|
||||
translatePrimitiveJSTypeToCpp(
|
||||
prop.typeAnnotation.returnTypeAnnotation,
|
||||
propTypeAnnotation.returnTypeAnnotation,
|
||||
typeName =>
|
||||
`Unsupported return type for ${prop.name}. Found: ${typeName}`,
|
||||
resolveAlias,
|
||||
|
|
Загрузка…
Ссылка в новой задаче