metro-bundler: ModuleGraph: nit: reduce code nesting

Reviewed By: davidaurelio

Differential Revision: D6324409

fbshipit-source-id: da7626772cb24b4f3749962e72e5952982b917d6
This commit is contained in:
Jean Lauliac 2017-11-15 06:08:37 -08:00 committed by Facebook Github Bot
parent c04393b397
commit f0a4418b5b
1 changed files with 32 additions and 31 deletions

View File

@ -68,7 +68,9 @@ const NULL_MODULE: Moduleish = {
const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
const map = Object.create(null);
files.forEach(filePath => {
if (!helpers.isNodeModulesDir(filePath)) {
if (helpers.isNodeModulesDir(filePath)) {
return;
}
let id;
let module;
if (filePath.endsWith(PACKAGE_JSON)) {
@ -79,13 +81,14 @@ const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
id = module.name;
}
if (id && module && module.isHaste()) {
if (!(id && module && module.isHaste())) {
return;
}
if (!map[id]) {
map[id] = Object.create(null);
}
const platform =
parsePlatformFilePath(filePath, platforms).platform ||
GENERIC_PLATFORM;
parsePlatformFilePath(filePath, platforms).platform || GENERIC_PLATFORM;
const existingModule = map[id][platform];
// 0 = Module, 1 = Package in jest-haste-map
@ -101,8 +104,6 @@ const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
'with the same name across two different files.',
);
}
}
}
});
return map;
};