mirror of
https://github.com/status-im/metro.git
synced 2025-01-13 12:35:57 +00:00
Rename the require
local var in the require "polyfill"
Reviewed By: mjesun Differential Revision: D7399735 fbshipit-source-id: 1daa1aee112f47bc87cc5b156a48919f8da8fa4f
This commit is contained in:
parent
a36195a0fd
commit
77a5cbdd33
@ -5,7 +5,7 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
global.require = _require;
|
||||
global.require = metroRequire;
|
||||
global.__d = define;
|
||||
var modules = Object.create(null);
|
||||
|
||||
@ -23,7 +23,7 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
|
||||
};
|
||||
}
|
||||
|
||||
function _require(moduleId) {
|
||||
function metroRequire(moduleId) {
|
||||
var moduleIdReallyIsNumber = moduleId;
|
||||
var module = modules[moduleIdReallyIsNumber];
|
||||
return module && module.isInitialized ? module.exports : guardedLoadModule(moduleIdReallyIsNumber, module);
|
||||
@ -61,13 +61,13 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
|
||||
};
|
||||
}
|
||||
|
||||
_require.unpackModuleId = unpackModuleId;
|
||||
metroRequire.unpackModuleId = unpackModuleId;
|
||||
|
||||
function packModuleId(value) {
|
||||
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
||||
}
|
||||
|
||||
_require.packModuleId = packModuleId;
|
||||
metroRequire.packModuleId = packModuleId;
|
||||
|
||||
function loadModuleImplementation(moduleId, module) {
|
||||
var nativeRequire = global.nativeRequire;
|
||||
@ -99,7 +99,7 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
|
||||
var _moduleObject = {
|
||||
exports: exports
|
||||
};
|
||||
factory(global, _require, _moduleObject, exports, dependencyMap);
|
||||
factory(global, metroRequire, _moduleObject, exports, dependencyMap);
|
||||
{
|
||||
module.factory = undefined;
|
||||
module.dependencyMap = undefined;
|
||||
@ -193,7 +193,7 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
global.require = _require;
|
||||
global.require = metroRequire;
|
||||
global.__d = define;
|
||||
var modules = Object.create(null);
|
||||
|
||||
@ -211,7 +211,7 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
||||
};
|
||||
}
|
||||
|
||||
function _require(moduleId) {
|
||||
function metroRequire(moduleId) {
|
||||
var moduleIdReallyIsNumber = moduleId;
|
||||
var module = modules[moduleIdReallyIsNumber];
|
||||
return module && module.isInitialized ? module.exports : guardedLoadModule(moduleIdReallyIsNumber, module);
|
||||
@ -249,13 +249,13 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
||||
};
|
||||
}
|
||||
|
||||
_require.unpackModuleId = unpackModuleId;
|
||||
metroRequire.unpackModuleId = unpackModuleId;
|
||||
|
||||
function packModuleId(value) {
|
||||
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
||||
}
|
||||
|
||||
_require.packModuleId = packModuleId;
|
||||
metroRequire.packModuleId = packModuleId;
|
||||
|
||||
function loadModuleImplementation(moduleId, module) {
|
||||
var nativeRequire = global.nativeRequire;
|
||||
@ -287,7 +287,7 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
||||
var _moduleObject = {
|
||||
exports: exports
|
||||
};
|
||||
factory(global, _require, _moduleObject, exports, dependencyMap);
|
||||
factory(global, metroRequire, _moduleObject, exports, dependencyMap);
|
||||
{
|
||||
module.factory = undefined;
|
||||
module.dependencyMap = undefined;
|
||||
|
@ -51,7 +51,7 @@ type PatchedModules = {[ModuleID]: boolean};
|
||||
type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
|
||||
type VerboseModuleNameForDev = string;
|
||||
|
||||
global.require = require;
|
||||
global.require = metroRequire;
|
||||
global.__d = define;
|
||||
|
||||
const modules: ModuleMap = Object.create(null);
|
||||
@ -110,7 +110,7 @@ function define(
|
||||
}
|
||||
}
|
||||
|
||||
function require(moduleId: ModuleID | VerboseModuleNameForDev) {
|
||||
function metroRequire(moduleId: ModuleID | VerboseModuleNameForDev) {
|
||||
if (__DEV__ && typeof moduleId === 'string') {
|
||||
const verboseName = moduleId;
|
||||
moduleId = verboseNamesToModuleIds[verboseName];
|
||||
@ -159,12 +159,12 @@ function unpackModuleId(
|
||||
const localId = moduleId & LOCAL_ID_MASK;
|
||||
return {segmentId, localId};
|
||||
}
|
||||
require.unpackModuleId = unpackModuleId;
|
||||
metroRequire.unpackModuleId = unpackModuleId;
|
||||
|
||||
function packModuleId(value: {segmentId: number, localId: number}): ModuleID {
|
||||
return value.segmentId << (ID_MASK_SHIFT + value.localId);
|
||||
}
|
||||
require.packModuleId = packModuleId;
|
||||
metroRequire.packModuleId = packModuleId;
|
||||
|
||||
function loadModuleImplementation(moduleId, module) {
|
||||
const nativeRequire = global.nativeRequire;
|
||||
@ -182,13 +182,13 @@ function loadModuleImplementation(moduleId, module) {
|
||||
throw moduleThrewError(moduleId, module.error);
|
||||
}
|
||||
|
||||
// `require` calls int the require polyfill itself are not analyzed and
|
||||
// `metroRequire` calls into the require polyfill itself are not analyzed and
|
||||
// replaced so that they use numeric module IDs.
|
||||
// The systrace module will expose itself on the require function so that
|
||||
// The systrace module will expose itself on the metroRequire function so that
|
||||
// it can be used here.
|
||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
||||
if (__DEV__) {
|
||||
var {Systrace} = require;
|
||||
var {Systrace} = metroRequire;
|
||||
}
|
||||
|
||||
// We must optimistically mark module as initialized before running the
|
||||
@ -211,7 +211,7 @@ function loadModuleImplementation(moduleId, module) {
|
||||
// keep args in sync with with defineModuleCode in
|
||||
// metro/src/Resolver/index.js
|
||||
// and metro/src/ModuleGraph/worker.js
|
||||
factory(global, require, moduleObject, exports, dependencyMap);
|
||||
factory(global, metroRequire, moduleObject, exports, dependencyMap);
|
||||
|
||||
// avoid removing factory in DEV mode as it breaks HMR
|
||||
if (!__DEV__) {
|
||||
@ -255,9 +255,9 @@ function moduleThrewError(id, error: any) {
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
require.Systrace = {beginEvent: () => {}, endEvent: () => {}};
|
||||
metroRequire.Systrace = {beginEvent: () => {}, endEvent: () => {}};
|
||||
|
||||
require.getModules = () => {
|
||||
metroRequire.getModules = () => {
|
||||
return modules;
|
||||
};
|
||||
|
||||
@ -358,7 +358,7 @@ if (__DEV__) {
|
||||
}
|
||||
mod.hasError = false;
|
||||
mod.isInitialized = false;
|
||||
require(id);
|
||||
metroRequire(id);
|
||||
|
||||
if (hot.acceptCallback) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user