MCPcopy
hub / github.com/webpack/webpack / getSyncSource

Method getSyncSource

lib/ContextModule.js:840–867  ·  view source on GitHub ↗

* @param {Dependency[]} dependencies dependencies * @param {ModuleId} id module id * @param {ChunkGraph} chunkGraph the chunk graph * @param {RuntimeTemplate=} runtimeTemplate the runtime template * @returns {string} source code

(dependencies, id, chunkGraph, runtimeTemplate)

Source from the content-addressed store, hash-verified

838 * @returns {string} source code
839 */
840 getSyncSource(dependencies, id, chunkGraph, runtimeTemplate) {
841 const map = this.getUserRequestMap(dependencies, chunkGraph);
842 const fakeMap = this.getFakeMap(dependencies, chunkGraph);
843 const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
844 const cst = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
845
846 return `${cst} map = ${JSON.stringify(map, null, "\t")};
847${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
848
849function webpackContext(req) {
850 ${cst} id = webpackContextResolve(req);
851 return ${returnModuleObject};
852}
853function webpackContextResolve(req) {
854 if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
855 ${cst} e = new Error("Cannot find module '" + req + "'");
856 e.code = 'MODULE_NOT_FOUND';
857 throw e;
858 }
859 return map[req];
860}
861webpackContext.keys = function webpackContextKeys() {
862 return Object.keys(map);
863};
864webpackContext.resolve = webpackContextResolve;
865module.exports = webpackContext;
866webpackContext.id = ${JSON.stringify(id)};`;
867 }
868
869 /**
870 * @param {Dependency[]} dependencies dependencies

Callers 1

getSourceStringMethod · 0.95

Calls 5

getUserRequestMapMethod · 0.95
getFakeMapMethod · 0.95
renderConstMethod · 0.80

Tested by

no test coverage detected