* Module namespace promise. * @param {object} options options object * @param {ChunkGraph} options.chunkGraph the chunk graph * @param {AsyncDependenciesBlock=} options.block the current dependencies block * @param {Module} options.module the module * @param {string} options.request the re
({
chunkGraph,
block,
module,
request,
message,
strict,
weak,
dependency,
runtimeRequirements
})
| 808 | * @returns {string} the promise expression |
| 809 | */ |
| 810 | moduleNamespacePromise({ |
| 811 | chunkGraph, |
| 812 | block, |
| 813 | module, |
| 814 | request, |
| 815 | message, |
| 816 | strict, |
| 817 | weak, |
| 818 | dependency, |
| 819 | runtimeRequirements |
| 820 | }) { |
| 821 | if (!module) { |
| 822 | return this.missingModulePromise({ |
| 823 | request |
| 824 | }); |
| 825 | } |
| 826 | const moduleId = chunkGraph.getModuleId(module); |
| 827 | if (moduleId === null) { |
| 828 | if (weak) { |
| 829 | // only weak referenced modules don't get an id |
| 830 | // we can always emit an error emitting code here |
| 831 | return this.weakError({ |
| 832 | module, |
| 833 | chunkGraph, |
| 834 | request, |
| 835 | type: "promise" |
| 836 | }); |
| 837 | } |
| 838 | throw new Error( |
| 839 | `RuntimeTemplate.moduleNamespacePromise(): ${noModuleIdErrorMessage( |
| 840 | module, |
| 841 | chunkGraph |
| 842 | )}` |
| 843 | ); |
| 844 | } |
| 845 | const promise = this.blockPromise({ |
| 846 | chunkGraph, |
| 847 | block, |
| 848 | message, |
| 849 | runtimeRequirements |
| 850 | }); |
| 851 | |
| 852 | /** @type {string} */ |
| 853 | let appending; |
| 854 | let idExpr = JSON.stringify(chunkGraph.getModuleId(module)); |
| 855 | const comment = this.comment({ |
| 856 | request |
| 857 | }); |
| 858 | let header = ""; |
| 859 | if (weak) { |
| 860 | if (idExpr.length > 8) { |
| 861 | // 'var x="nnnnnn";x,"+x+",x' vs '"nnnnnn",nnnnnn,"nnnnnn"' |
| 862 | header += `${this.renderConst()} id = ${idExpr}; `; |
| 863 | idExpr = "id"; |
| 864 | } |
| 865 | runtimeRequirements.add(RuntimeGlobals.moduleFactories); |
| 866 | header += `if(!${ |
| 867 | RuntimeGlobals.moduleFactories |
no test coverage detected