mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: In our Codegen generators, we were using `codegenModuleName` to refer to the name of the spec file. Calling this `hasteModuleName` makes it more clear what this name refers to (i.e: the name of the spec file). This diff performs that rename. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D24386282 fbshipit-source-id: fe2beda9a0abf63a5cf88fa0664f83416c9f1aa2
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (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.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {
|
|
SchemaType,
|
|
NativeModuleAliasMap,
|
|
NativeModuleObjectTypeAnnotation,
|
|
NativeModuleSchema,
|
|
} from '../../CodegenSchema';
|
|
|
|
const invariant = require('invariant');
|
|
|
|
export type AliasResolver = (
|
|
aliasName: string,
|
|
) => NativeModuleObjectTypeAnnotation;
|
|
|
|
function createAliasResolver(aliasMap: NativeModuleAliasMap): AliasResolver {
|
|
return (aliasName: string) => {
|
|
const alias = aliasMap[aliasName];
|
|
invariant(alias != null, `Unable to resolve type alias '${aliasName}'.`);
|
|
return alias;
|
|
};
|
|
}
|
|
|
|
function getModules(
|
|
schema: SchemaType,
|
|
): $ReadOnly<{|[hasteModuleName: string]: NativeModuleSchema|}> {
|
|
return Object.keys(schema.modules).reduce<{|[string]: NativeModuleSchema|}>(
|
|
(modules, hasteModuleName: string) => {
|
|
const module = schema.modules[hasteModuleName];
|
|
if (module == null || module.type === 'Component') {
|
|
return modules;
|
|
}
|
|
modules[hasteModuleName] = module;
|
|
return modules;
|
|
},
|
|
{},
|
|
);
|
|
}
|
|
|
|
module.exports = {
|
|
createAliasResolver,
|
|
getModules,
|
|
};
|