mirror of
https://github.com/status-im/metro.git
synced 2025-01-28 03:44:54 +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) {
|
(function (global) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
global.require = _require;
|
global.require = metroRequire;
|
||||||
global.__d = define;
|
global.__d = define;
|
||||||
var modules = Object.create(null);
|
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 moduleIdReallyIsNumber = moduleId;
|
||||||
var module = modules[moduleIdReallyIsNumber];
|
var module = modules[moduleIdReallyIsNumber];
|
||||||
return module && module.isInitialized ? module.exports : guardedLoadModule(moduleIdReallyIsNumber, module);
|
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) {
|
function packModuleId(value) {
|
||||||
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
||||||
}
|
}
|
||||||
|
|
||||||
_require.packModuleId = packModuleId;
|
metroRequire.packModuleId = packModuleId;
|
||||||
|
|
||||||
function loadModuleImplementation(moduleId, module) {
|
function loadModuleImplementation(moduleId, module) {
|
||||||
var nativeRequire = global.nativeRequire;
|
var nativeRequire = global.nativeRequire;
|
||||||
@ -99,7 +99,7 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
|
|||||||
var _moduleObject = {
|
var _moduleObject = {
|
||||||
exports: exports
|
exports: exports
|
||||||
};
|
};
|
||||||
factory(global, _require, _moduleObject, exports, dependencyMap);
|
factory(global, metroRequire, _moduleObject, exports, dependencyMap);
|
||||||
{
|
{
|
||||||
module.factory = undefined;
|
module.factory = undefined;
|
||||||
module.dependencyMap = undefined;
|
module.dependencyMap = undefined;
|
||||||
@ -193,7 +193,7 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
|||||||
(function (global) {
|
(function (global) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
global.require = _require;
|
global.require = metroRequire;
|
||||||
global.__d = define;
|
global.__d = define;
|
||||||
var modules = Object.create(null);
|
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 moduleIdReallyIsNumber = moduleId;
|
||||||
var module = modules[moduleIdReallyIsNumber];
|
var module = modules[moduleIdReallyIsNumber];
|
||||||
return module && module.isInitialized ? module.exports : guardedLoadModule(moduleIdReallyIsNumber, module);
|
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) {
|
function packModuleId(value) {
|
||||||
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
return value.segmentId << ID_MASK_SHIFT + value.localId;
|
||||||
}
|
}
|
||||||
|
|
||||||
_require.packModuleId = packModuleId;
|
metroRequire.packModuleId = packModuleId;
|
||||||
|
|
||||||
function loadModuleImplementation(moduleId, module) {
|
function loadModuleImplementation(moduleId, module) {
|
||||||
var nativeRequire = global.nativeRequire;
|
var nativeRequire = global.nativeRequire;
|
||||||
@ -287,7 +287,7 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
|
|||||||
var _moduleObject = {
|
var _moduleObject = {
|
||||||
exports: exports
|
exports: exports
|
||||||
};
|
};
|
||||||
factory(global, _require, _moduleObject, exports, dependencyMap);
|
factory(global, metroRequire, _moduleObject, exports, dependencyMap);
|
||||||
{
|
{
|
||||||
module.factory = undefined;
|
module.factory = undefined;
|
||||||
module.dependencyMap = undefined;
|
module.dependencyMap = undefined;
|
||||||
|
@ -51,7 +51,7 @@ type PatchedModules = {[ModuleID]: boolean};
|
|||||||
type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
|
type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
|
||||||
type VerboseModuleNameForDev = string;
|
type VerboseModuleNameForDev = string;
|
||||||
|
|
||||||
global.require = require;
|
global.require = metroRequire;
|
||||||
global.__d = define;
|
global.__d = define;
|
||||||
|
|
||||||
const modules: ModuleMap = Object.create(null);
|
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') {
|
if (__DEV__ && typeof moduleId === 'string') {
|
||||||
const verboseName = moduleId;
|
const verboseName = moduleId;
|
||||||
moduleId = verboseNamesToModuleIds[verboseName];
|
moduleId = verboseNamesToModuleIds[verboseName];
|
||||||
@ -159,12 +159,12 @@ function unpackModuleId(
|
|||||||
const localId = moduleId & LOCAL_ID_MASK;
|
const localId = moduleId & LOCAL_ID_MASK;
|
||||||
return {segmentId, localId};
|
return {segmentId, localId};
|
||||||
}
|
}
|
||||||
require.unpackModuleId = unpackModuleId;
|
metroRequire.unpackModuleId = unpackModuleId;
|
||||||
|
|
||||||
function packModuleId(value: {segmentId: number, localId: number}): ModuleID {
|
function packModuleId(value: {segmentId: number, localId: number}): ModuleID {
|
||||||
return value.segmentId << (ID_MASK_SHIFT + value.localId);
|
return value.segmentId << (ID_MASK_SHIFT + value.localId);
|
||||||
}
|
}
|
||||||
require.packModuleId = packModuleId;
|
metroRequire.packModuleId = packModuleId;
|
||||||
|
|
||||||
function loadModuleImplementation(moduleId, module) {
|
function loadModuleImplementation(moduleId, module) {
|
||||||
const nativeRequire = global.nativeRequire;
|
const nativeRequire = global.nativeRequire;
|
||||||
@ -182,13 +182,13 @@ function loadModuleImplementation(moduleId, module) {
|
|||||||
throw moduleThrewError(moduleId, module.error);
|
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.
|
// 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.
|
// it can be used here.
|
||||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
var {Systrace} = require;
|
var {Systrace} = metroRequire;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must optimistically mark module as initialized before running the
|
// 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
|
// keep args in sync with with defineModuleCode in
|
||||||
// metro/src/Resolver/index.js
|
// metro/src/Resolver/index.js
|
||||||
// and metro/src/ModuleGraph/worker.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
|
// avoid removing factory in DEV mode as it breaks HMR
|
||||||
if (!__DEV__) {
|
if (!__DEV__) {
|
||||||
@ -255,9 +255,9 @@ function moduleThrewError(id, error: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
require.Systrace = {beginEvent: () => {}, endEvent: () => {}};
|
metroRequire.Systrace = {beginEvent: () => {}, endEvent: () => {}};
|
||||||
|
|
||||||
require.getModules = () => {
|
metroRequire.getModules = () => {
|
||||||
return modules;
|
return modules;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ if (__DEV__) {
|
|||||||
}
|
}
|
||||||
mod.hasError = false;
|
mod.hasError = false;
|
||||||
mod.isInitialized = false;
|
mod.isInitialized = false;
|
||||||
require(id);
|
metroRequire(id);
|
||||||
|
|
||||||
if (hot.acceptCallback) {
|
if (hot.acceptCallback) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user