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/dependencies/HarmonyImportDependency.js |   81 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 70 insertions(+), 11 deletions(-)

diff --git a/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js b/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js
index 0afa15a..667dc0f 100644
--- a/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js
+++ b/node_modules/webpack/lib/dependencies/HarmonyImportDependency.js
@@ -12,10 +12,11 @@
 const Template = require("../Template");
 const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
 const { filterRuntime, mergeRuntime } = require("../util/runtime");
-const { ImportPhaseUtils } = require("./ImportPhase");
+const { ImportPhase, ImportPhaseUtils } = require("./ImportPhase");
 const ModuleDependency = require("./ModuleDependency");
 
 /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
+/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
 /** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
 /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
 /** @typedef {import("../ExportsInfo")} ExportsInfo */
@@ -29,7 +30,7 @@
 /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
 /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
 
-/** @typedef {0 | 1 | 2 | 3 | false} ExportPresenceMode */
+/** @typedef {0 | 1 | 2 | 3} ExportPresenceMode */
 
 const ExportPresenceModes = {
 	NONE: /** @type {ExportPresenceMode} */ (0),
@@ -37,6 +38,7 @@
 	AUTO: /** @type {ExportPresenceMode} */ (2),
 	ERROR: /** @type {ExportPresenceMode} */ (3),
 	/**
+	 * Returns result.
 	 * @param {string | false} str param
 	 * @returns {ExportPresenceMode} result
 	 */
@@ -53,19 +55,54 @@
 			default:
 				throw new Error(`Invalid export presence value ${str}`);
 		}
+	},
+	/**
+	 * Resolve export presence mode from parser options with a specific key and shared fallbacks.
+	 * @param {string | false | undefined} specificValue the type-specific option value (e.g. importExportsPresence or reexportExportsPresence)
+	 * @param {JavascriptParserOptions} options parser options
+	 * @returns {ExportPresenceMode} resolved mode
+	 */
+	resolveFromOptions(specificValue, options) {
+		if (specificValue !== undefined) {
+			return ExportPresenceModes.fromUserOption(specificValue);
+		}
+		if (options.exportsPresence !== undefined) {
+			return ExportPresenceModes.fromUserOption(options.exportsPresence);
+		}
+		return options.strictExportPresence
+			? ExportPresenceModes.ERROR
+			: ExportPresenceModes.AUTO;
 	}
+};
+
+/**
+ * Get the non-optional leading part of a member chain.
+ * @param {string[]} members members
+ * @param {boolean[]} membersOptionals optionality for each member
+ * @returns {string[]} the non-optional prefix
+ */
+const getNonOptionalPart = (members, membersOptionals) => {
+	let i = 0;
+	while (i < members.length && membersOptionals[i] === false) i++;
+	return i !== members.length ? members.slice(0, i) : members;
 };
 
 /** @typedef {string[]} Ids */
 
 class HarmonyImportDependency extends ModuleDependency {
 	/**
+	 * Creates an instance of HarmonyImportDependency.
 	 * @param {string} request request string
 	 * @param {number} sourceOrder source order
-	 * @param {ImportPhaseType} phase import phase
+	 * @param {ImportPhaseType=} phase import phase
 	 * @param {ImportAttributes=} attributes import attributes
 	 */
-	constructor(request, sourceOrder, phase, attributes) {
+	constructor(
+		request,
+		sourceOrder,
+		phase = ImportPhase.Evaluation,
+		attributes = undefined
+	) {
 		super(request, sourceOrder);
 		this.phase = phase;
 		this.attributes = attributes;
@@ -76,15 +113,17 @@
 	}
 
 	/**
+	 * Returns an identifier to merge equal requests.
 	 * @returns {string | null} an identifier to merge equal requests
 	 */
 	getResourceIdentifier() {
 		let str = super.getResourceIdentifier();
-		if (ImportPhaseUtils.isDefer(this.phase)) {
-			str += "|defer";
+		// We specifically use this check to avoid writing the default (`evaluation` or `0`) value and save memory
+		if (this.phase) {
+			str += `|phase${ImportPhaseUtils.stringify(this.phase)}`;
 		}
 		if (this.attributes) {
-			str += `|importAttributes${JSON.stringify(this.attributes)}`;
+			str += `|attributes${JSON.stringify(this.attributes)}`;
 		}
 		return str;
 	}
@@ -100,6 +139,7 @@
 	}
 
 	/**
+	 * Returns name of the variable for the import.
 	 * @param {ModuleGraph} moduleGraph the module graph
 	 * @returns {string} name of the variable for the import
 	 */
@@ -122,14 +162,15 @@
 
 		let importVar = importVarMap.get(importedModule);
 		if (importVar) return importVar;
-		importVar = `${Template.toIdentifier(
-			`${this.userRequest}`
-		)}__WEBPACK_${isDeferred ? "DEFERRED_" : ""}IMPORTED_MODULE_${importVarMap.size}__`;
+		importVar = `${Template.toIdentifier(`${this.userRequest}`)}__WEBPACK_${
+			isDeferred ? "DEFERRED_" : ""
+		}IMPORTED_MODULE_${importVarMap.size}__`;
 		importVarMap.set(importedModule, importVar);
 		return importVar;
 	}
 
 	/**
+	 * Gets module exports.
 	 * @param {DependencyTemplateContext} context the template context
 	 * @returns {string} the expression
 	 */
@@ -148,6 +189,7 @@
 	}
 
 	/**
+	 * Gets import statement.
 	 * @param {boolean} update create new variables or update existing one
 	 * @param {DependencyTemplateContext} templateContext the template context
 	 * @returns {[string, string]} the import statement and the compat statement
@@ -170,12 +212,18 @@
 	}
 
 	/**
+	 * Gets linking errors.
 	 * @param {ModuleGraph} moduleGraph module graph
 	 * @param {Ids} ids imported ids
 	 * @param {string} additionalMessage extra info included in the error message
 	 * @returns {WebpackError[] | undefined} errors
 	 */
 	getLinkingErrors(moduleGraph, ids, additionalMessage) {
+		// Source phase imports don't have exports to check
+		if (ImportPhaseUtils.isSource(this.phase)) {
+			return;
+		}
+
 		const importedModule = moduleGraph.getModule(this);
 		// ignore errors for missing or failed modules
 		if (!importedModule || importedModule.getNumberOfErrors() > 0) {
@@ -283,6 +331,7 @@
 	}
 
 	/**
+	 * Serializes this instance into the provided serializer context.
 	 * @param {ObjectSerializerContext} context context
 	 */
 	serialize(context) {
@@ -293,6 +342,7 @@
 	}
 
 	/**
+	 * Restores this instance from the provided deserializer context.
 	 * @param {ObjectDeserializerContext} context context
 	 */
 	deserialize(context) {
@@ -312,6 +362,7 @@
 	ModuleDependency.Template
 ) {
 	/**
+	 * Applies the plugin by registering its hooks on the compiler.
 	 * @param {Dependency} dependency the dependency for which the template should be applied
 	 * @param {ReplaceSource} source the current replace source which can be modified
 	 * @param {DependencyTemplateContext} templateContext the context object
@@ -340,7 +391,13 @@
 		const moduleKey = referencedModule
 			? referencedModule.identifier()
 			: dep.request;
-		const key = `${ImportPhaseUtils.isDefer(dep.phase) ? "deferred " : ""}harmony import ${moduleKey}`;
+		const key = `${
+			ImportPhaseUtils.isDefer(dep.phase)
+				? "deferred "
+				: ImportPhaseUtils.isSource(dep.phase)
+					? "source "
+					: ""
+		}harmony import ${moduleKey}`;
 
 		const runtimeCondition = dep.weak
 			? false
@@ -410,6 +467,7 @@
 	}
 
 	/**
+	 * Gets import emitted runtime.
 	 * @param {Module} module the module
 	 * @param {Module} referencedModule the referenced module
 	 * @returns {RuntimeSpec | boolean} runtimeCondition in which this import has been emitted
@@ -422,3 +480,4 @@
 };
 
 module.exports.ExportPresenceModes = ExportPresenceModes;
+module.exports.getNonOptionalPart = getNonOptionalPart;

--
Gitblit v1.9.3