mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix GenerateModuleH
Summary: Just updated the generator to work with the new RN Codegen Flow Parser types. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D23667252 fbshipit-source-id: 34404a478ddd67446d82b5f98e1051300064e95c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c0408b56fc
commit
4ab7cc236a
@@ -10,15 +10,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {
|
||||
SchemaType,
|
||||
FunctionTypeAnnotationParamTypeAnnotation,
|
||||
FunctionTypeAnnotationReturn,
|
||||
TypeAliasTypeAnnotation,
|
||||
ObjectTypeAliasTypeShape,
|
||||
} from '../../CodegenSchema';
|
||||
import type {SchemaType, NativeModuleTypeAnnotation} from '../../CodegenSchema';
|
||||
|
||||
const {getTypeAliasTypeAnnotation} = require('./Utils');
|
||||
import type {AliasResolver} from './Utils';
|
||||
const {createAliasResolver, getModules} = require('./Utils');
|
||||
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
@@ -32,8 +27,9 @@ public:
|
||||
|
||||
};`;
|
||||
|
||||
const template = `/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
const template = `
|
||||
/**
|
||||
* ${'C'}opyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
@@ -54,17 +50,15 @@ namespace react {
|
||||
`;
|
||||
|
||||
function translatePrimitiveJSTypeToCpp(
|
||||
typeAnnotation:
|
||||
| FunctionTypeAnnotationParamTypeAnnotation
|
||||
| FunctionTypeAnnotationReturn
|
||||
| TypeAliasTypeAnnotation,
|
||||
typeAnnotation: NativeModuleTypeAnnotation,
|
||||
createErrorMessage: (typeName: string) => string,
|
||||
aliases: $ReadOnly<{[aliasName: string]: ObjectTypeAliasTypeShape, ...}>,
|
||||
resolveAlias: AliasResolver,
|
||||
) {
|
||||
const realTypeAnnotation =
|
||||
typeAnnotation.type === 'TypeAliasTypeAnnotation'
|
||||
? getTypeAliasTypeAnnotation(typeAnnotation.name, aliases)
|
||||
: typeAnnotation;
|
||||
let realTypeAnnotation = typeAnnotation;
|
||||
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
||||
}
|
||||
|
||||
switch (realTypeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (realTypeAnnotation.name) {
|
||||
@@ -79,6 +73,9 @@ function translatePrimitiveJSTypeToCpp(
|
||||
case 'StringTypeAnnotation':
|
||||
return 'jsi::String';
|
||||
case 'NumberTypeAnnotation':
|
||||
return 'double';
|
||||
case 'DoubleTypeAnnotation':
|
||||
return 'double';
|
||||
case 'FloatTypeAnnotation':
|
||||
return 'double';
|
||||
case 'Int32TypeAnnotation':
|
||||
@@ -86,6 +83,7 @@ function translatePrimitiveJSTypeToCpp(
|
||||
case 'BooleanTypeAnnotation':
|
||||
return 'bool';
|
||||
case 'GenericObjectTypeAnnotation':
|
||||
return 'jsi::Object';
|
||||
case 'ObjectTypeAnnotation':
|
||||
return 'jsi::Object';
|
||||
case 'ArrayTypeAnnotation':
|
||||
@@ -95,8 +93,7 @@ function translatePrimitiveJSTypeToCpp(
|
||||
case 'PromiseTypeAnnotation':
|
||||
return 'jsi::Value';
|
||||
default:
|
||||
// TODO (T65847278): Figure out why this does not work.
|
||||
// (type: empty);
|
||||
(realTypeAnnotation.type: empty);
|
||||
throw new Error(createErrorMessage(realTypeAnnotation.type));
|
||||
}
|
||||
}
|
||||
@@ -110,21 +107,13 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
moduleSpecName: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = Object.keys(schema.modules)
|
||||
.map(moduleName => {
|
||||
const modules = schema.modules[moduleName].nativeModules;
|
||||
if (modules == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return modules;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.reduce((acc, components) => Object.assign(acc, components), {});
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
const modules = Object.keys(nativeModules)
|
||||
.map(name => {
|
||||
const {aliases, properties} = nativeModules[name];
|
||||
const resolveAlias = createAliasResolver(aliases);
|
||||
|
||||
const traversedProperties = properties
|
||||
.map(prop => {
|
||||
const traversedArgs = prop.typeAnnotation.params
|
||||
@@ -133,7 +122,7 @@ module.exports = {
|
||||
param.typeAnnotation,
|
||||
typeName =>
|
||||
`Unsupported type for param "${param.name}" in ${prop.name}. Found: ${typeName}`,
|
||||
aliases,
|
||||
resolveAlias,
|
||||
);
|
||||
const isObject = translatedParam.startsWith('jsi::');
|
||||
return (
|
||||
@@ -151,7 +140,7 @@ module.exports = {
|
||||
prop.typeAnnotation.returnTypeAnnotation,
|
||||
typeName =>
|
||||
`Unsupported return type for ${prop.name}. Found: ${typeName}`,
|
||||
aliases,
|
||||
resolveAlias,
|
||||
),
|
||||
)
|
||||
.replace(
|
||||
|
||||
Reference in New Issue
Block a user