feat: refactoring project
This commit is contained in:
39
node_modules/webpack/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js
generated
vendored
39
node_modules/webpack/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js
generated
vendored
@@ -13,6 +13,7 @@ const WebAssemblyUtils = require("./WebAssemblyUtils");
|
||||
/** @typedef {import("@webassemblyjs/ast").Signature} Signature */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
||||
@@ -89,7 +90,8 @@ const generateImportObject = (
|
||||
const instanceVar = `m${waitForInstances.size}`;
|
||||
waitForInstances.set(
|
||||
instanceVar,
|
||||
chunkGraph.getModuleId(/** @type {Module} */ (importedModule))
|
||||
/** @type {ModuleId} */
|
||||
(chunkGraph.getModuleId(/** @type {Module} */ (importedModule)))
|
||||
);
|
||||
properties.push({
|
||||
module,
|
||||
@@ -100,7 +102,7 @@ const generateImportObject = (
|
||||
const params =
|
||||
/** @type {Signature} */
|
||||
(description.signature).params.map(
|
||||
(param, k) => "p" + k + param.valtype
|
||||
(param, k) => `p${k}${param.valtype}`
|
||||
);
|
||||
|
||||
const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
|
||||
@@ -121,7 +123,7 @@ const generateImportObject = (
|
||||
module,
|
||||
name,
|
||||
value: Template.asString([
|
||||
modCode + `function(${params}) {`,
|
||||
`${modCode}function(${params}) {`,
|
||||
Template.indent([
|
||||
`if(${cache} === undefined) ${cache} = ${modExports};`,
|
||||
`return ${cache}[${JSON.stringify(usedName)}](${params});`
|
||||
@@ -154,15 +156,15 @@ const generateImportObject = (
|
||||
importObject = [
|
||||
"return {",
|
||||
Template.indent([
|
||||
Array.from(propertiesByModule, ([module, list]) => {
|
||||
return Template.asString([
|
||||
Array.from(propertiesByModule, ([module, list]) =>
|
||||
Template.asString([
|
||||
`${JSON.stringify(module)}: {`,
|
||||
Template.indent([
|
||||
list.map(p => `${JSON.stringify(p.name)}: ${p.value}`).join(",\n")
|
||||
]),
|
||||
"}"
|
||||
]);
|
||||
}).join(",\n")
|
||||
])
|
||||
).join(",\n")
|
||||
]),
|
||||
"};"
|
||||
];
|
||||
@@ -200,13 +202,12 @@ const generateImportObject = (
|
||||
]),
|
||||
"},"
|
||||
]);
|
||||
} else {
|
||||
return Template.asString([
|
||||
`${moduleIdStringified}: function() {`,
|
||||
Template.indent(importObject),
|
||||
"},"
|
||||
]);
|
||||
}
|
||||
return Template.asString([
|
||||
`${moduleIdStringified}: function() {`,
|
||||
Template.indent(importObject),
|
||||
"},"
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -250,15 +251,15 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
const { mangleImports } = this;
|
||||
/** @type {string[]} */
|
||||
const declarations = [];
|
||||
const importObjects = wasmModules.map(module => {
|
||||
return generateImportObject(
|
||||
const importObjects = wasmModules.map(module =>
|
||||
generateImportObject(
|
||||
chunkGraph,
|
||||
module,
|
||||
mangleImports,
|
||||
declarations,
|
||||
chunk.runtime
|
||||
);
|
||||
});
|
||||
)
|
||||
);
|
||||
const chunkModuleIdMap = chunkGraph.getChunkModuleIdMap(chunk, m =>
|
||||
m.type.startsWith("webassembly")
|
||||
);
|
||||
@@ -331,7 +332,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
`${fn}.wasm = function(chunkId, promises) {`,
|
||||
Template.indent([
|
||||
"",
|
||||
`var wasmModules = wasmModuleMap[chunkId] || [];`,
|
||||
"var wasmModules = wasmModuleMap[chunkId] || [];",
|
||||
"",
|
||||
"wasmModules.forEach(function(wasmModuleId, idx) {",
|
||||
Template.indent([
|
||||
@@ -342,7 +343,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
||||
Template.indent(["promises.push(installedWasmModuleData);"]),
|
||||
"else {",
|
||||
Template.indent([
|
||||
`var importObject = wasmImportObjects[wasmModuleId]();`,
|
||||
"var importObject = wasmImportObjects[wasmModuleId]();",
|
||||
`var req = ${this.generateLoadBinaryCode(wasmModuleSrcPath)};`,
|
||||
"var promise;",
|
||||
this.supportsStreaming
|
||||
|
||||
Reference in New Issue
Block a user