MCPcopy
hub / github.com/webpack/webpack / generateImportObject

Function generateImportObject

lib/wasm-sync/WasmChunkLoadingRuntimeModule.js:61–220  ·  view source on GitHub ↗
(
	chunkGraph,
	module,
	mangle,
	declarations,
	runtime
)

Source from the content-addressed store, hash-verified

59 * @returns {string} source code
60 */
61const generateImportObject = (
62 chunkGraph,
63 module,
64 mangle,
65 declarations,
66 runtime
67) => {
68 const moduleGraph = chunkGraph.moduleGraph;
69 /** @type {Map<string, ModuleId>} */
70 const waitForInstances = new Map();
71 /** @type {{ module: string, name: string, value: string }[]} */
72 const properties = [];
73 const usedWasmDependencies = WebAssemblyUtils.getUsedDependencies(
74 moduleGraph,
75 module,
76 mangle
77 );
78 for (const usedDep of usedWasmDependencies) {
79 const dep = usedDep.dependency;
80 const importedModule = moduleGraph.getModule(dep);
81 const exportName = dep.name;
82 const usedName =
83 importedModule &&
84 moduleGraph
85 .getExportsInfo(importedModule)
86 .getUsedName(exportName, runtime);
87 const description = dep.description;
88 const direct = dep.onlyDirectImport;
89
90 const module = usedDep.module;
91 const name = usedDep.name;
92
93 if (direct) {
94 const instanceVar = `m${waitForInstances.size}`;
95 waitForInstances.set(
96 instanceVar,
97 /** @type {ModuleId} */
98 (chunkGraph.getModuleId(/** @type {Module} */ (importedModule)))
99 );
100 properties.push({
101 module,
102 name,
103 value: `${instanceVar}[${JSON.stringify(usedName)}]`
104 });
105 } else {
106 const params =
107 /** @type {Signature} */
108 (description.signature).params.map(
109 (param, k) => `p${k}${param.valtype}`
110 );
111
112 const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
113 chunkGraph.getModuleId(/** @type {Module} */ (importedModule))
114 )}]`;
115 const modExports = `${mod}.exports`;
116
117 const cache = `wasmImportedFuncCache${declarations.length}`;
118 declarations.push(`var ${cache};`);

Callers 1

generateMethod · 0.85

Calls 11

getExportsInfoMethod · 0.80
getModuleIdMethod · 0.80
indentMethod · 0.80
keysMethod · 0.65
getModuleMethod · 0.45
getUsedNameMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
asStringMethod · 0.45
getMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected