mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Update Module Generators to follow new NativeModuleSchema
Summary: NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack). ## Changes 1. NativeModule generators now use the new RN Codegen NativeModule schema. 2. Tangential: We're no longer removing the `Native` prefix from the NativeModule filename, assuming that that's the module name (problem: wrong), and prefixing again with Native (problem: redundant), when we're generating code. Instead, like the internal codegen, we simply pass the filename to the Codegen output. Our linters enforce that all NativeModule specs are contained with files that start off with `Native`. 3. `GenerateModuleCpp` was fixed to use the actual module name as opposed to the spec name. I added a comment inline. Changelog: [Internal] (Note: this ignores all push blocking failures!) Reviewed By: PeteTheHeat Differential Revision: D24236405 fbshipit-source-id: ccd6b5674d252c350be0ec8a86e7ca5f2f614778
This commit is contained in:
1 parent
ee177f6cba
commit
c4f23354fd
21 files changed
+434
-729
No files matched your search
Vendored
+10
-9
@@ -60,7 +60,7 @@ export type MethodSerializationOutput = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
function serializeMethod(
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
property: NativeModulePropertySchema,
|
||||
structCollector: StructCollector,
|
||||
resolveAlias: AliasResolver,
|
||||
@@ -71,7 +71,7 @@ function serializeMethod(
|
||||
|
||||
if (methodName === 'getConstants') {
|
||||
return serializeConstantsProtocolMethods(
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
property,
|
||||
structCollector,
|
||||
resolveAlias,
|
||||
@@ -84,7 +84,7 @@ function serializeMethod(
|
||||
params.forEach((param, index) => {
|
||||
const structName = getParamStructName(methodName, param);
|
||||
const {objCType, isStruct} = getParamObjCType(
|
||||
moduleName,
|
||||
codegenModuleName,
|
||||
methodName,
|
||||
param,
|
||||
structName,
|
||||
@@ -177,7 +177,7 @@ function getParamStructName(
|
||||
}
|
||||
|
||||
function getParamObjCType(
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
methodName: string,
|
||||
param: NativeModuleMethodParamSchema,
|
||||
structName: string,
|
||||
@@ -242,7 +242,8 @@ function getParamObjCType(
|
||||
* TODO(T73943261): Support nullable object literals and aliases?
|
||||
*/
|
||||
return isStruct(
|
||||
getNamespacedStructName(moduleName, structTypeAnnotation.name) + ' &',
|
||||
getNamespacedStructName(codegenModuleName, structTypeAnnotation.name) +
|
||||
' &',
|
||||
);
|
||||
}
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
@@ -382,7 +383,7 @@ function getReturnJSType(
|
||||
}
|
||||
|
||||
function serializeConstantsProtocolMethods(
|
||||
moduleName: string,
|
||||
codegenModuleName: string,
|
||||
property: NativeModulePropertySchema,
|
||||
structCollector: StructCollector,
|
||||
resolveAlias: AliasResolver,
|
||||
@@ -390,14 +391,14 @@ function serializeConstantsProtocolMethods(
|
||||
const [propertyTypeAnnotation] = unwrapNullable(property.typeAnnotation);
|
||||
if (propertyTypeAnnotation.params.length !== 0) {
|
||||
throw new Error(
|
||||
`${moduleName}.getConstants() may only accept 0 arguments.`,
|
||||
`${codegenModuleName}.getConstants() may only accept 0 arguments.`,
|
||||
);
|
||||
}
|
||||
|
||||
const {returnTypeAnnotation} = propertyTypeAnnotation;
|
||||
if (returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
|
||||
throw new Error(
|
||||
`${moduleName}.getConstants() may only return an object literal: {|...|}.`,
|
||||
`${codegenModuleName}.getConstants() may only return an object literal: {|...|}.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -417,7 +418,7 @@ function serializeConstantsProtocolMethods(
|
||||
"Unable to generate C++ struct from module's getConstants() method return type.",
|
||||
);
|
||||
|
||||
const returnObjCType = `facebook::react::ModuleConstants<JS::Native${moduleName}::Constants::Builder>`;
|
||||
const returnObjCType = `facebook::react::ModuleConstants<JS::${codegenModuleName}::Constants::Builder>`;
|
||||
|
||||
return ['constantsToExport', 'getConstants'].map<MethodSerializationOutput>(
|
||||
methodName => {
|
||||
|
||||
Reference in new issue
Block a user