mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-25 14:47:21 +08:00
Reviewed By: @vjeux Differential Revision: D2544415 fb-gh-sync-id: ab48b5fba169c43c68dd24dc95ea1d0322ed67c4
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
/* eslint strict:0 */
|
|
(function(global) {
|
|
var modules = Object.create(null);
|
|
var inGuard = false;
|
|
|
|
function define(id, factory) {
|
|
modules[id] = {
|
|
factory,
|
|
module: {exports: {}},
|
|
isInitialized: false,
|
|
hasError: false,
|
|
};
|
|
}
|
|
|
|
function require(id) {
|
|
var mod = modules[id];
|
|
if (mod && mod.isInitialized) {
|
|
return mod.module.exports;
|
|
}
|
|
|
|
return requireImpl(id);
|
|
}
|
|
|
|
function requireImpl(id) {
|
|
if (global.ErrorUtils && !inGuard) {
|
|
inGuard = true;
|
|
var returnValue;
|
|
try {
|
|
returnValue = requireImpl.apply(this, arguments);
|
|
} catch (e) {
|
|
global.ErrorUtils.reportFatalError(e);
|
|
}
|
|
inGuard = false;
|
|
return returnValue;
|
|
}
|
|
|
|
var mod = modules[id];
|
|
if (!mod) {
|
|
var msg = 'Requiring unknown module "' + id + '"';
|
|
if (__DEV__) {
|
|
msg += '. If you are sure the module is there, try restarting the packager.';
|
|
}
|
|
throw new Error(msg);
|
|
}
|
|
|
|
if (mod.hasError) {
|
|
throw new Error(
|
|
'Requiring module "' + id + '" which threw an exception'
|
|
);
|
|
}
|
|
|
|
try {
|
|
// keep args in sync with with defineModuleCode in
|
|
// packager/react-packager/src/DependencyResolver/index.js
|
|
mod.factory.call(global, global, require, mod.module, mod.module.exports);
|
|
mod.isInitialized = true;
|
|
} catch (e) {
|
|
mod.hasError = true;
|
|
throw e;
|
|
}
|
|
|
|
return mod.module.exports;
|
|
}
|
|
|
|
global.__d = define;
|
|
global.require = require;
|
|
})(this);
|