* @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)
| 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 | |
| 885 | function 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 | } |
| 894 | function 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 | } |
| 902 | webpackContext.keys = function webpackContextKeys() { |
| 903 | return Object.keys(map); |
| 904 | }; |
| 905 | webpackContext.resolve = webpackContextResolve; |
| 906 | webpackContext.id = ${JSON.stringify(id)}; |
| 907 | module.exports = webpackContext;`; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * @param {Dependency[]} dependencies dependencies |
no test coverage detected