MCPcopy
hub / github.com/webpack/webpack / getWeakSyncSource

Method getWeakSyncSource

lib/ContextModule.js:876–908  ·  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

874 * @returns {string} source code
875 */
876 getWeakSyncSource(dependencies, id, chunkGraph, runtimeTemplate) {
877 const map = this.getUserRequestMap(dependencies, chunkGraph);
878 const fakeMap = this.getFakeMap(dependencies, chunkGraph);
879 const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
880 const cst = runtimeTemplate ? runtimeTemplate.renderConst() : "var";
881
882 return `${cst} map = ${JSON.stringify(map, null, "\t")};
883${this.getFakeMapInitStatement(fakeMap, runtimeTemplate)}
884
885function webpackContext(req) {
886 ${cst} id = webpackContextResolve(req);
887 if(!${RuntimeGlobals.moduleFactories}[id]) {
888 ${cst} e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
889 e.code = 'MODULE_NOT_FOUND';
890 throw e;
891 }
892 return ${returnModuleObject};
893}
894function webpackContextResolve(req) {
895 if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
896 ${cst} e = new Error("Cannot find module '" + req + "'");
897 e.code = 'MODULE_NOT_FOUND';
898 throw e;
899 }
900 return map[req];
901}
902webpackContext.keys = function webpackContextKeys() {
903 return Object.keys(map);
904};
905webpackContext.resolve = webpackContextResolve;
906webpackContext.id = ${JSON.stringify(id)};
907module.exports = webpackContext;`;
908 }
909
910 /**
911 * @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