Make H Generator handle NullableTypeAnnotation

Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027247

fbshipit-source-id: cc326f5db919de1f6c6b56603f420c87272da918
This commit is contained in:
Ramanpreet Nara 2020-10-01 19:26:14 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 1a90e1b471
Коммит d9dc9d5d0a
1 изменённых файлов: 11 добавлений и 4 удалений

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

@ -10,10 +10,15 @@
'use strict'; 'use strict';
import type {SchemaType, NativeModuleTypeAnnotation} from '../../CodegenSchema'; import type {
Nullable,
SchemaType,
NativeModuleTypeAnnotation,
} from '../../CodegenSchema';
import type {AliasResolver} from './Utils'; import type {AliasResolver} from './Utils';
const {createAliasResolver, getModules} = require('./Utils'); const {createAliasResolver, getModules} = require('./Utils');
const {unwrapNullable} = require('../../parsers/flow/modules/utils');
type FilesOutput = Map<string, string>; type FilesOutput = Map<string, string>;
@ -50,10 +55,11 @@ namespace react {
`; `;
function translatePrimitiveJSTypeToCpp( function translatePrimitiveJSTypeToCpp(
typeAnnotation: NativeModuleTypeAnnotation, nullableTypeAnnotation: Nullable<NativeModuleTypeAnnotation>,
createErrorMessage: (typeName: string) => string, createErrorMessage: (typeName: string) => string,
resolveAlias: AliasResolver, resolveAlias: AliasResolver,
) { ) {
const [typeAnnotation] = unwrapNullable(nullableTypeAnnotation);
let realTypeAnnotation = typeAnnotation; let realTypeAnnotation = typeAnnotation;
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') { if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
realTypeAnnotation = resolveAlias(realTypeAnnotation.name); realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
@ -116,7 +122,8 @@ module.exports = {
const traversedProperties = properties const traversedProperties = properties
.map(prop => { .map(prop => {
const traversedArgs = prop.typeAnnotation.params const [propTypeAnnotation] = unwrapNullable(prop.typeAnnotation);
const traversedArgs = propTypeAnnotation.params
.map(param => { .map(param => {
const translatedParam = translatePrimitiveJSTypeToCpp( const translatedParam = translatePrimitiveJSTypeToCpp(
param.typeAnnotation, param.typeAnnotation,
@ -137,7 +144,7 @@ module.exports = {
.replace( .replace(
'::_RETURN_VALUE_::', '::_RETURN_VALUE_::',
translatePrimitiveJSTypeToCpp( translatePrimitiveJSTypeToCpp(
prop.typeAnnotation.returnTypeAnnotation, propTypeAnnotation.returnTypeAnnotation,
typeName => typeName =>
`Unsupported return type for ${prop.name}. Found: ${typeName}`, `Unsupported return type for ${prop.name}. Found: ${typeName}`,
resolveAlias, resolveAlias,