Allow for falsy module exports

Reviewed By: javache

Differential Revision: D3207353

fb-gh-sync-id: 3e23eb9cc9facea7993ce684f87ff4b7b0003a1c
fbshipit-source-id: 3e23eb9cc9facea7993ce684f87ff4b7b0003a1c
This commit is contained in:
David Aurelio 2016-04-21 06:48:27 -07:00 committed by Facebook Github Bot 4
parent ae9f74e68d
commit faa9adf2ab
1 changed files with 6 additions and 1 deletions

View File

@ -27,13 +27,16 @@ function define(moduleId, factory) {
modules[moduleId] = {
factory,
hasError: false,
isInitialized: false,
exports: undefined,
};
}
function require(moduleId) {
const module = modules[moduleId];
return module && module.exports || loadModule(moduleId, module);
return module && module.isInitialized
? module.exports
: loadModule(moduleId, module);
}
function guardedLoadModule(moduleId, module) {
@ -68,6 +71,7 @@ function loadModuleImplementation(moduleId, module) {
}
const exports = module.exports = {};
module.isInitialized = true;
const {factory} = module;
try {
if (__DEV__) {
@ -83,6 +87,7 @@ function loadModuleImplementation(moduleId, module) {
}
return (module.exports = moduleObject.exports);
} catch (e) {
module.isInitialized = false;
module.hasError = true;
module.exports = undefined;
}