Allow already loaded modules to be `require`’d by name string in dev mode

Summary:
The code to require modules by their name (rather than their numeric ID) was buggy, because it didn’t check whether the module factory was already executed and the module already existed.

This diff checks the already loaded modules, too, when loading modules by name.

Reviewed By: lexs

Differential Revision: D3281350

fbshipit-source-id: cef236e152fe5484f21c877d6cee37433fa11c76
This commit is contained in:
David Aurelio 2016-05-10 09:36:54 -07:00 committed by Facebook Github Bot 3
parent f9da45197f
commit 9dcdb156f0
1 changed files with 5 additions and 3 deletions

View File

@ -41,17 +41,19 @@ function define(moduleId, factory) {
}
function require(moduleId) {
const module = modules[moduleId];
const module = __DEV__
? modules[moduleId] || modules[verboseNamesToModuleIds[moduleId]]
: modules[moduleId];
return module && module.isInitialized
? module.exports
: guardedLoadModule(moduleId, module);
}
var inGuard = false;
let inGuard = false;
function guardedLoadModule(moduleId, module) {
if (!inGuard && global.ErrorUtils) {
inGuard = true;
var returnValue;
let returnValue;
try {
returnValue = loadModuleImplementation(moduleId, module);
} catch (e) {