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/APIPlugin.js |  110 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 94 insertions(+), 16 deletions(-)

diff --git a/node_modules/webpack/lib/APIPlugin.js b/node_modules/webpack/lib/APIPlugin.js
index 0eb124a..357d7ac 100644
--- a/node_modules/webpack/lib/APIPlugin.js
+++ b/node_modules/webpack/lib/APIPlugin.js
@@ -16,6 +16,8 @@
 const RuntimeGlobals = require("./RuntimeGlobals");
 const WebpackError = require("./WebpackError");
 const ConstDependency = require("./dependencies/ConstDependency");
+const ModuleInitFragmentDependency = require("./dependencies/ModuleInitFragmentDependency");
+const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
 const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
 const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
 const {
@@ -32,11 +34,18 @@
 /** @typedef {import("./javascript/JavascriptParser").Range} Range */
 
 /**
- * @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements
+ * Returns the replacement definitions used for webpack API identifiers.
+ * @returns {Record<string, { expr: string, req: string[] | null, type?: string, assign: boolean }>} replacements
  */
 function getReplacements() {
 	return {
 		__webpack_require__: {
+			expr: RuntimeGlobals.require,
+			req: [RuntimeGlobals.require],
+			type: "function",
+			assign: false
+		},
+		__webpack_global__: {
 			expr: RuntimeGlobals.require,
 			req: [RuntimeGlobals.require],
 			type: "function",
@@ -132,7 +141,7 @@
 
 class APIPlugin {
 	/**
-	 * Apply the plugin
+	 * Applies the plugin by registering its hooks on the compiler.
 	 * @param {Compiler} compiler the compiler instance
 	 * @returns {void}
 	 */
@@ -153,6 +162,10 @@
 				compilation.dependencyTemplates.set(
 					ConstDependency,
 					new ConstDependency.Template()
+				);
+				compilation.dependencyTemplates.set(
+					ModuleInitFragmentDependency,
+					new ModuleInitFragmentDependency.Template()
 				);
 
 				compilation.hooks.runtimeRequirementInTree
@@ -192,9 +205,44 @@
 				);
 
 				/**
+				 * Handles the hook callback for this code path.
 				 * @param {JavascriptParser} parser the parser
 				 */
 				const handler = (parser) => {
+					parser.hooks.preDeclarator.tap(PLUGIN_NAME, (declarator) => {
+						if (
+							parser.scope.topLevelScope === true &&
+							declarator.id.type === "Identifier" &&
+							declarator.id.name === "module"
+						) {
+							/** @type {BuildInfo} */
+							(parser.state.module.buildInfo).moduleArgument =
+								"__webpack_module__";
+						}
+					});
+
+					parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
+						if (parser.scope.topLevelScope === true) {
+							if (
+								statement.type === "FunctionDeclaration" &&
+								statement.id &&
+								statement.id.name === "module"
+							) {
+								/** @type {BuildInfo} */
+								(parser.state.module.buildInfo).moduleArgument =
+									"__webpack_module__";
+							} else if (
+								statement.type === "ClassDeclaration" &&
+								statement.id &&
+								statement.id.name === "module"
+							) {
+								/** @type {BuildInfo} */
+								(parser.state.module.buildInfo).moduleArgument =
+									"__webpack_module__";
+							}
+						}
+					});
+
 					for (const key of Object.keys(REPLACEMENTS)) {
 						const info = REPLACEMENTS[key];
 						parser.hooks.expression.for(key).tap(PLUGIN_NAME, (expression) => {
@@ -269,13 +317,28 @@
 							/** @type {BuildInfo} */
 							(parser.state.module.buildInfo).moduleConcatenationBailout =
 								"__webpack_module__.id";
-							const dep = new ConstDependency(
-								`${parser.state.module.moduleArgument}.id`,
-								/** @type {Range} */ (expr.range),
-								[RuntimeGlobals.moduleId]
-							);
-							dep.loc = /** @type {DependencyLocation} */ (expr.loc);
-							parser.state.module.addPresentationalDependency(dep);
+							const moduleArgument = parser.state.module.moduleArgument;
+							if (moduleArgument === "__webpack_module__") {
+								const dep = new RuntimeRequirementsDependency([
+									RuntimeGlobals.moduleId
+								]);
+								dep.loc = /** @type {DependencyLocation} */ (expr.loc);
+								parser.state.module.addPresentationalDependency(dep);
+							} else {
+								const initDep = new ModuleInitFragmentDependency(
+									`var __webpack_internal_module_id__ = ${moduleArgument}.id;\n`,
+									[RuntimeGlobals.moduleId],
+									"__webpack_internal_module_id__"
+								);
+								parser.state.module.addPresentationalDependency(initDep);
+								const dep = new ConstDependency(
+									"__webpack_internal_module_id__",
+									/** @type {Range} */ (expr.range),
+									[]
+								);
+								dep.loc = /** @type {DependencyLocation} */ (expr.loc);
+								parser.state.module.addPresentationalDependency(dep);
+							}
 							return true;
 						});
 
@@ -285,13 +348,28 @@
 							/** @type {BuildInfo} */
 							(parser.state.module.buildInfo).moduleConcatenationBailout =
 								"__webpack_module__";
-							const dep = new ConstDependency(
-								parser.state.module.moduleArgument,
-								/** @type {Range} */ (expr.range),
-								[RuntimeGlobals.module]
-							);
-							dep.loc = /** @type {DependencyLocation} */ (expr.loc);
-							parser.state.module.addPresentationalDependency(dep);
+							const moduleArgument = parser.state.module.moduleArgument;
+							if (moduleArgument === "__webpack_module__") {
+								const dep = new RuntimeRequirementsDependency([
+									RuntimeGlobals.module
+								]);
+								dep.loc = /** @type {DependencyLocation} */ (expr.loc);
+								parser.state.module.addPresentationalDependency(dep);
+							} else {
+								const initDep = new ModuleInitFragmentDependency(
+									`var __webpack_internal_module__ = ${moduleArgument};\n`,
+									[RuntimeGlobals.module],
+									"__webpack_internal_module__"
+								);
+								parser.state.module.addPresentationalDependency(initDep);
+								const dep = new ConstDependency(
+									"__webpack_internal_module__",
+									/** @type {Range} */ (expr.range),
+									[]
+								);
+								dep.loc = /** @type {DependencyLocation} */ (expr.loc);
+								parser.state.module.addPresentationalDependency(dep);
+							}
 							return true;
 						});
 					parser.hooks.evaluateTypeof

--
Gitblit v1.9.3