From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送

---
 node_modules/webpack/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js |  121 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js b/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js
index afd8e27..9d20f74 100644
--- a/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js
+++ b/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js
@@ -10,8 +10,10 @@
 const Generator = require("../Generator");
 const { tryRunOrWebpackError } = require("../HookWebpackError");
 const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
+const NormalModule = require("../NormalModule");
 const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
-const { compareModulesByIdOrIdentifier } = require("../util/comparators");
+const { compareModulesByFullName } = require("../util/comparators");
+const makeSerializable = require("../util/makeSerializable");
 const memoize = require("../util/memoize");
 
 /** @typedef {import("webpack-sources").Source} Source */
@@ -21,9 +23,13 @@
 /** @typedef {import("../Compiler")} Compiler */
 /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
 /** @typedef {import("../Module")} Module */
+/** @typedef {import("../dependencies/ImportPhase").ImportPhaseName} ImportPhaseName */
+/** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
 /** @typedef {import("../ModuleGraph")} ModuleGraph */
 /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
 /** @typedef {import("../WebpackError")} WebpackError */
+/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
+/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
 
 const getAsyncWebAssemblyGenerator = memoize(() =>
 	require("./AsyncWebAssemblyGenerator")
@@ -35,7 +41,98 @@
 	require("./AsyncWebAssemblyParser")
 );
 
+/** @typedef {NormalModule & { phase: ImportPhaseName | undefined }} AsyncWasmModuleClass */
+
+class AsyncWasmModule extends NormalModule {
+	/**
+	 * @param {NormalModuleCreateData & { phase: ImportPhaseName | undefined }} options options object
+	 */
+	constructor(options) {
+		super(options);
+		this.phase = options.phase;
+	}
+
+	/**
+	 * Returns the unique identifier used to reference this module.
+	 * @returns {string} a unique identifier of the module
+	 */
+	identifier() {
+		let str = super.identifier();
+
+		if (this.phase) {
+			str = `${str}|${this.phase}`;
+		}
+
+		return str;
+	}
+
+	/**
+	 * Assuming this module is in the cache. Update the (cached) module with
+	 * the fresh module from the factory. Usually updates internal references
+	 * and properties.
+	 * @param {Module} module fresh module
+	 * @returns {void}
+	 */
+	updateCacheModule(module) {
+		super.updateCacheModule(module);
+		const m = /** @type {AsyncWasmModule} */ (module);
+		this.phase = m.phase;
+	}
+
+	/**
+	 * Serializes this instance into the provided serializer context.
+	 * @param {ObjectSerializerContext} context context
+	 */
+	serialize(context) {
+		const { write } = context;
+		write(this.phase);
+		super.serialize(context);
+	}
+
+	/**
+	 * @param {ObjectDeserializerContext} context context
+	 * @returns {AsyncWasmModule} the deserialized object
+	 */
+	static deserialize(context) {
+		const obj = new AsyncWasmModule({
+			// will be deserialized by Module
+			layer: /** @type {EXPECTED_ANY} */ (null),
+			type: "",
+			// will be filled by updateCacheModule
+			resource: "",
+			context: "",
+			request: /** @type {EXPECTED_ANY} */ (null),
+			userRequest: /** @type {EXPECTED_ANY} */ (null),
+			rawRequest: /** @type {EXPECTED_ANY} */ (null),
+			loaders: /** @type {EXPECTED_ANY} */ (null),
+			matchResource: /** @type {EXPECTED_ANY} */ (null),
+			parser: /** @type {EXPECTED_ANY} */ (null),
+			parserOptions: /** @type {EXPECTED_ANY} */ (null),
+			generator: /** @type {EXPECTED_ANY} */ (null),
+			generatorOptions: /** @type {EXPECTED_ANY} */ (null),
+			resolveOptions: /** @type {EXPECTED_ANY} */ (null),
+			extractSourceMap: /** @type {EXPECTED_ANY} */ (null),
+			phase: /** @type {EXPECTED_ANY} */ (null)
+		});
+		obj.deserialize(context);
+		return obj;
+	}
+
+	/**
+	 * Restores this instance from the provided deserializer context.
+	 * @param {ObjectDeserializerContext} context context
+	 */
+	deserialize(context) {
+		const { read } = context;
+		this.phase = read();
+		super.deserialize(context);
+	}
+}
+
+makeSerializable(AsyncWasmModule, "webpack/lib/wasm-async/AsyncWasmModule");
+
 /**
+ * Defines the web assembly render context type used by this module.
  * @typedef {object} WebAssemblyRenderContext
  * @property {Chunk} chunk the chunk
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -46,11 +143,13 @@
  */
 
 /**
+ * Defines the compilation hooks type used by this module.
  * @typedef {object} CompilationHooks
  * @property {SyncWaterfallHook<[Source, Module, WebAssemblyRenderContext]>} renderModuleContent
  */
 
 /**
+ * Defines the async web assembly modules plugin options type used by this module.
  * @typedef {object} AsyncWebAssemblyModulesPluginOptions
  * @property {boolean=} mangleImports mangle imports
  */
@@ -62,6 +161,7 @@
 
 class AsyncWebAssemblyModulesPlugin {
 	/**
+	 * Returns the attached hooks.
 	 * @param {Compilation} compilation the compilation
 	 * @returns {CompilationHooks} the attached hooks
 	 */
@@ -86,14 +186,16 @@
 	}
 
 	/**
+	 * Creates an instance of AsyncWebAssemblyModulesPlugin.
 	 * @param {AsyncWebAssemblyModulesPluginOptions} options options
 	 */
 	constructor(options) {
+		/** @type {AsyncWebAssemblyModulesPluginOptions} */
 		this.options = options;
 	}
 
 	/**
-	 * Apply the plugin
+	 * Applies the plugin by registering its hooks on the compiler.
 	 * @param {Compiler} compiler the compiler instance
 	 * @returns {void}
 	 */
@@ -107,6 +209,18 @@
 					WebAssemblyImportDependency,
 					normalModuleFactory
 				);
+
+				normalModuleFactory.hooks.createModuleClass
+					.for(WEBASSEMBLY_MODULE_TYPE_ASYNC)
+					.tap(
+						PLUGIN_NAME,
+						(createData, resolveData) =>
+							new AsyncWasmModule({
+								.../** @type {NormalModuleCreateData & { type: string }} */
+								(createData),
+								phase: resolveData.phase
+							})
+					);
 
 				normalModuleFactory.hooks.createParser
 					.for(WEBASSEMBLY_MODULE_TYPE_ASYNC)
@@ -139,7 +253,7 @@
 
 					for (const module of chunkGraph.getOrderedChunkModulesIterable(
 						chunk,
-						compareModulesByIdOrIdentifier(chunkGraph)
+						compareModulesByFullName(compiler)
 					)) {
 						if (module.type === WEBASSEMBLY_MODULE_TYPE_ASYNC) {
 							const filenameTemplate = outputOptions.webassemblyModuleFilename;
@@ -180,6 +294,7 @@
 	}
 
 	/**
+	 * Renders the newly generated source from rendering.
 	 * @param {Module} module the rendered module
 	 * @param {WebAssemblyRenderContext} renderContext options object
 	 * @param {CompilationHooks} hooks hooks

--
Gitblit v1.9.3