| 
									
										
										
										
											2018-07-17 22:41:07 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | const ExportsInfo = require("./ExportsInfo"); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | const ModuleGraphConnection = require("./ModuleGraphConnection"); | 
					
						
							| 
									
										
										
										
											2025-08-04 22:38:42 +08:00
										 |  |  | const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency"); | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | const WeakTupleMap = require("./util/WeakTupleMap"); | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | const { sortWithSourceOrder } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-04 21:38:51 +08:00
										 |  |  | /** @typedef {import("./Compilation").ModuleMemCaches} ModuleMemCaches */ | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | /** @typedef {import("./DependenciesBlock")} DependenciesBlock */ | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | /** @typedef {import("./Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */ | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | /** @typedef {import("./ExportsInfo").ExportInfoName} ExportInfoName */ | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | /** @typedef {import("./ModuleProfile")} ModuleProfile */ | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | /** @typedef {import("./dependencies/HarmonyImportSideEffectDependency")} HarmonyImportSideEffectDependency */ | 
					
						
							|  |  |  | /** @typedef {import("./dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */ | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | /** @typedef {import("./util/comparators").DependencySourceOrder} DependencySourceOrder */ | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @callback OptimizationBailoutFunction | 
					
						
							|  |  |  |  * @param {RequestShortener} requestShortener | 
					
						
							|  |  |  |  * @returns {string} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-27 19:58:13 +08:00
										 |  |  | const EMPTY_SET = new Set(); | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  |  * @template {Module | null | undefined} T | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  |  * @param {SortableSet<ModuleGraphConnection>} set input | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  |  * @param {(connection: ModuleGraphConnection) => T} getKey function to extract key from connection | 
					
						
							| 
									
										
										
										
											2025-09-10 19:38:19 +08:00
										 |  |  |  * @returns {ReadonlyMap<T, ReadonlyArray<ModuleGraphConnection>>} mapped by key | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | const getConnectionsByKey = (set, getKey) => { | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 	const map = new Map(); | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | 	/** @type {T | 0} */ | 
					
						
							|  |  |  | 	let lastKey = 0; | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	/** @type {ModuleGraphConnection[] | undefined} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 06:15:03 +08:00
										 |  |  | 	let lastList; | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 	for (const connection of set) { | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | 		const key = getKey(connection); | 
					
						
							|  |  |  | 		if (lastKey === key) { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 			/** @type {ModuleGraphConnection[]} */ | 
					
						
							|  |  |  | 			(lastList).push(connection); | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | 			lastKey = key; | 
					
						
							|  |  |  | 			const list = map.get(key); | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 			if (list !== undefined) { | 
					
						
							|  |  |  | 				lastList = list; | 
					
						
							|  |  |  | 				list.push(connection); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const list = [connection]; | 
					
						
							|  |  |  | 				lastList = list; | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | 				map.set(key, list); | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return map; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {SortableSet<ModuleGraphConnection>} set input | 
					
						
							| 
									
										
										
										
											2025-09-10 19:38:19 +08:00
										 |  |  |  * @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} mapped by origin module | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const getConnectionsByOriginModule = (set) => | 
					
						
							|  |  |  | 	getConnectionsByKey(set, (connection) => connection.originModule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {SortableSet<ModuleGraphConnection>} set input | 
					
						
							| 
									
										
										
										
											2025-09-10 19:38:19 +08:00
										 |  |  |  * @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>>} mapped by module | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-08-04 22:40:33 +08:00
										 |  |  | const getConnectionsByModule = (set) => | 
					
						
							|  |  |  | 	getConnectionsByKey(set, (connection) => connection.module); | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | /** @typedef {SortableSet<ModuleGraphConnection>} IncomingConnections */ | 
					
						
							|  |  |  | /** @typedef {SortableSet<ModuleGraphConnection>} OutgoingConnections */ | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | /** @typedef {Module | null | undefined} Issuer */ | 
					
						
							|  |  |  | /** @typedef {(string | OptimizationBailoutFunction)[]} OptimizationBailouts */ | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | class ModuleGraphModule { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {IncomingConnections} */ | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 		this.incomingConnections = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {OutgoingConnections | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 		this.outgoingConnections = undefined; | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 		/** @type {Issuer} */ | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		this.issuer = undefined; | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 		/** @type {OptimizationBailouts} */ | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		this.optimizationBailout = []; | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 		/** @type {ExportsInfo} */ | 
					
						
							|  |  |  | 		this.exports = new ExportsInfo(); | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		/** @type {number | null} */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		this.preOrderIndex = null; | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		/** @type {number | null} */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		this.postOrderIndex = null; | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		/** @type {number | null} */ | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 		this.depth = null; | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 		/** @type {ModuleProfile | undefined} */ | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 		this.profile = undefined; | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							|  |  |  | 		this.async = false; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {ModuleGraphConnection[] | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		this._unassignedConnections = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  | /** @typedef {(moduleGraphConnection: ModuleGraphConnection) => boolean} FilterConnection */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | /** @typedef {EXPECTED_OBJECT} MetaKey */ | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("./dependencies/CommonJsExportRequireDependency").idsSymbol} CommonJsExportRequireDependencyIDsSymbol */ | 
					
						
							|  |  |  | /** @typedef {import("./dependencies/HarmonyImportSpecifierDependency").idsSymbol} HarmonyImportSpecifierDependencyIDsSymbol */ | 
					
						
							|  |  |  | /** @typedef {import("./dependencies/HarmonyExportImportedSpecifierDependency").idsSymbol} HarmonyExportImportedSpecifierDependencyIDsSymbol */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} KnownMeta | 
					
						
							|  |  |  |  * @property {Map<Module, string>=} importVarMap | 
					
						
							|  |  |  |  * @property {Map<Module, string>=} deferredImportVarMap | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {KnownMeta & Record<CommonJsExportRequireDependencyIDsSymbol | HarmonyImportSpecifierDependencyIDsSymbol | HarmonyExportImportedSpecifierDependencyIDsSymbol, string[]> & Record<string, EXPECTED_ANY>} Meta */ | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 22:41:07 +08:00
										 |  |  | class ModuleGraph { | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	constructor() { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @type {WeakMap<Dependency, ModuleGraphConnection | null>} | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:56 +08:00
										 |  |  | 		this._dependencyMap = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @type {Map<Module, ModuleGraphModule>} | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		this._moduleMap = new Map(); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 		 * @type {WeakMap<MetaKey, Meta>} | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:56 +08:00
										 |  |  | 		this._metaMap = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 		 * @type {WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY> | undefined} | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 		this._cache = undefined; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  | 		 * @type {ModuleMemCaches | undefined} | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 		this._moduleMemCaches = undefined; | 
					
						
							| 
									
										
										
										
											2023-03-15 09:20:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @type {string | undefined} | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2023-03-15 09:20:10 +08:00
										 |  |  | 		this._cacheStage = undefined; | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 		 * @type {WeakMap<Dependency, DependencySourceOrder>} | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 		 * @private | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		this._dependencySourceOrderMap = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {ModuleGraphModule} the internal module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getModuleGraphModule(module) { | 
					
						
							|  |  |  | 		let mgm = this._moduleMap.get(module); | 
					
						
							|  |  |  | 		if (mgm === undefined) { | 
					
						
							|  |  |  | 			mgm = new ModuleGraphModule(); | 
					
						
							|  |  |  | 			this._moduleMap.set(module, mgm); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		return mgm; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							|  |  |  | 	 * @param {DependenciesBlock} block parent block | 
					
						
							|  |  |  | 	 * @param {Module} module parent module | 
					
						
							| 
									
										
										
										
											2021-10-05 23:25:33 +08:00
										 |  |  | 	 * @param {number=} indexInBlock position in block | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-10-05 23:25:33 +08:00
										 |  |  | 	setParents(dependency, block, module, indexInBlock = -1) { | 
					
						
							|  |  |  | 		dependency._parentDependenciesBlockIndex = indexInBlock; | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		dependency._parentDependenciesBlock = block; | 
					
						
							|  |  |  | 		dependency._parentModule = module; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							|  |  |  | 	 * @param {number} index the index | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setParentDependenciesBlockIndex(dependency, index) { | 
					
						
							|  |  |  | 		dependency._parentDependenciesBlockIndex = index; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 	 * @returns {Module | undefined} parent module | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getParentModule(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		return dependency._parentModule; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 	 * @returns {DependenciesBlock | undefined} parent block | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getParentBlock(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		return dependency._parentDependenciesBlock; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 23:25:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							|  |  |  | 	 * @returns {number} index | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getParentBlockIndex(dependency) { | 
					
						
							|  |  |  | 		return dependency._parentDependenciesBlockIndex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2024-03-18 01:15:44 +08:00
										 |  |  | 	 * @param {Module | null} originModule the referencing module | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 * @param {Dependency} dependency the referencing dependency | 
					
						
							|  |  |  | 	 * @param {Module} module the referenced module | 
					
						
							| 
									
										
										
										
											2019-10-30 05:57:03 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-30 07:11:26 +08:00
										 |  |  | 	setResolvedModule(originModule, dependency, module) { | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		const connection = new ModuleGraphConnection( | 
					
						
							|  |  |  | 			originModule, | 
					
						
							|  |  |  | 			dependency, | 
					
						
							| 
									
										
										
										
											2019-10-29 18:04:50 +08:00
										 |  |  | 			module, | 
					
						
							|  |  |  | 			undefined, | 
					
						
							| 
									
										
										
										
											2019-10-30 07:11:26 +08:00
										 |  |  | 			dependency.weak, | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 			dependency.getCondition(this) | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const connections = this._getModuleGraphModule(module).incomingConnections; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		connections.add(connection); | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		if (originModule) { | 
					
						
							|  |  |  | 			const mgm = this._getModuleGraphModule(originModule); | 
					
						
							|  |  |  | 			if (mgm._unassignedConnections === undefined) { | 
					
						
							|  |  |  | 				mgm._unassignedConnections = []; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			mgm._unassignedConnections.push(connection); | 
					
						
							|  |  |  | 			if (mgm.outgoingConnections === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 				mgm.outgoingConnections = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			mgm.outgoingConnections.add(connection); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this._dependencyMap.set(dependency, connection); | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the referencing dependency | 
					
						
							|  |  |  | 	 * @param {Module} module the referenced module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	updateModule(dependency, module) { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		const connection = | 
					
						
							|  |  |  | 			/** @type {ModuleGraphConnection} */ | 
					
						
							|  |  |  | 			(this.getConnection(dependency)); | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		if (connection.module === module) return; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		const newConnection = connection.clone(); | 
					
						
							|  |  |  | 		newConnection.module = module; | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		this._dependencyMap.set(dependency, newConnection); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		connection.setActive(false); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		const originMgm = this._getModuleGraphModule( | 
					
						
							|  |  |  | 			/** @type {Module} */ (connection.originModule) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		/** @type {OutgoingConnections} */ | 
					
						
							|  |  |  | 		(originMgm.outgoingConnections).add(newConnection); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		const targetMgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		targetMgm.incomingConnections.add(newConnection); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the need update dependency | 
					
						
							|  |  |  | 	 * @param {ModuleGraphConnection=} connection the target connection | 
					
						
							|  |  |  | 	 * @param {Module=} parentModule the parent module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	updateParent(dependency, connection, parentModule) { | 
					
						
							|  |  |  | 		if (this._dependencySourceOrderMap.has(dependency)) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!connection || !parentModule) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const originDependency = connection.dependency; | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 		// src/index.js
 | 
					
						
							|  |  |  | 		// import { c } from "lib/c" -> c = 0
 | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 		// import { a, b } from "lib" -> a and b have the same source order -> a = b = 1
 | 
					
						
							|  |  |  | 		// import { d } from "lib/d" -> d = 2
 | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 		const currentSourceOrder = | 
					
						
							|  |  |  | 			/** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ ( | 
					
						
							|  |  |  | 				dependency | 
					
						
							|  |  |  | 			).sourceOrder; | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// lib/index.js (reexport)
 | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 		// import { a } from "lib/a" -> a = 0
 | 
					
						
							|  |  |  | 		// import { b } from "lib/b" -> b = 1
 | 
					
						
							|  |  |  | 		const originSourceOrder = | 
					
						
							|  |  |  | 			/** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ ( | 
					
						
							|  |  |  | 				originDependency | 
					
						
							|  |  |  | 			).sourceOrder; | 
					
						
							|  |  |  | 		if ( | 
					
						
							|  |  |  | 			typeof currentSourceOrder === "number" && | 
					
						
							|  |  |  | 			typeof originSourceOrder === "number" | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			// src/index.js
 | 
					
						
							|  |  |  | 			// import { c } from "lib/c" -> c = 0
 | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 			// import { a } from "lib/a" -> a = 1.0 = 1(main) + 0.0(sub)
 | 
					
						
							|  |  |  | 			// import { b } from "lib/b" -> b = 1.1 = 1(main) + 0.1(sub)
 | 
					
						
							|  |  |  | 			// import { d } from "lib/d" -> d = 2
 | 
					
						
							|  |  |  | 			this._dependencySourceOrderMap.set(dependency, { | 
					
						
							|  |  |  | 				main: currentSourceOrder, | 
					
						
							|  |  |  | 				sub: originSourceOrder | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder,
 | 
					
						
							|  |  |  | 			// we sort based on it; otherwise, we preserve the original order.
 | 
					
						
							| 
									
										
										
										
											2025-07-15 00:49:34 +08:00
										 |  |  | 			sortWithSourceOrder( | 
					
						
							|  |  |  | 				parentModule.dependencies, | 
					
						
							|  |  |  | 				this._dependencySourceOrderMap | 
					
						
							| 
									
										
										
										
											2025-07-14 18:56:27 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (const [index, dep] of parentModule.dependencies.entries()) { | 
					
						
							|  |  |  | 				this.setParentDependenciesBlockIndex(dep, index); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the referencing dependency | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	removeConnection(dependency) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		const connection = | 
					
						
							|  |  |  | 			/** @type {ModuleGraphConnection} */ | 
					
						
							|  |  |  | 			(this.getConnection(dependency)); | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 		const targetMgm = this._getModuleGraphModule(connection.module); | 
					
						
							|  |  |  | 		targetMgm.incomingConnections.delete(connection); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		const originMgm = this._getModuleGraphModule( | 
					
						
							|  |  |  | 			/** @type {Module} */ (connection.originModule) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		/** @type {OutgoingConnections} */ | 
					
						
							|  |  |  | 		(originMgm.outgoingConnections).delete(connection); | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		this._dependencyMap.set(dependency, null); | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the referencing dependency | 
					
						
							|  |  |  | 	 * @param {string} explanation an explanation | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	addExplanation(dependency, explanation) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		const connection = | 
					
						
							|  |  |  | 			/** @type {ModuleGraphConnection} */ | 
					
						
							|  |  |  | 			(this.getConnection(dependency)); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		connection.addExplanation(explanation); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-09-03 19:49:00 +08:00
										 |  |  | 	 * @param {Module} sourceModule the source module | 
					
						
							|  |  |  | 	 * @param {Module} targetModule the target module | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-03 19:49:00 +08:00
										 |  |  | 	cloneModuleAttributes(sourceModule, targetModule) { | 
					
						
							|  |  |  | 		const oldMgm = this._getModuleGraphModule(sourceModule); | 
					
						
							|  |  |  | 		const newMgm = this._getModuleGraphModule(targetModule); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		newMgm.postOrderIndex = oldMgm.postOrderIndex; | 
					
						
							|  |  |  | 		newMgm.preOrderIndex = oldMgm.preOrderIndex; | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 		newMgm.depth = oldMgm.depth; | 
					
						
							| 
									
										
										
										
											2019-01-28 17:40:32 +08:00
										 |  |  | 		newMgm.exports = oldMgm.exports; | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 		newMgm.async = oldMgm.async; | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	removeModuleAttributes(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.postOrderIndex = null; | 
					
						
							|  |  |  | 		mgm.preOrderIndex = null; | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 		mgm.depth = null; | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 		mgm.async = false; | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	removeAllModuleAttributes() { | 
					
						
							|  |  |  | 		for (const mgm of this._moduleMap.values()) { | 
					
						
							|  |  |  | 			mgm.postOrderIndex = null; | 
					
						
							|  |  |  | 			mgm.preOrderIndex = null; | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 			mgm.depth = null; | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 			mgm.async = false; | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} oldModule the old referencing module | 
					
						
							|  |  |  | 	 * @param {Module} newModule the new referencing module | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  | 	 * @param {FilterConnection} filterConnection filter predicate for replacement | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	moveModuleConnections(oldModule, newModule, filterConnection) { | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		if (oldModule === newModule) return; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const oldMgm = this._getModuleGraphModule(oldModule); | 
					
						
							|  |  |  | 		const newMgm = this._getModuleGraphModule(newModule); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		// Outgoing connections
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const oldConnections = oldMgm.outgoingConnections; | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 		if (oldConnections !== undefined) { | 
					
						
							|  |  |  | 			if (newMgm.outgoingConnections === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 				newMgm.outgoingConnections = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			const newConnections = newMgm.outgoingConnections; | 
					
						
							|  |  |  | 			for (const connection of oldConnections) { | 
					
						
							|  |  |  | 				if (filterConnection(connection)) { | 
					
						
							|  |  |  | 					connection.originModule = newModule; | 
					
						
							|  |  |  | 					newConnections.add(connection); | 
					
						
							|  |  |  | 					oldConnections.delete(connection); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-07-27 21:57:44 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		// Incoming connections
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const oldConnections2 = oldMgm.incomingConnections; | 
					
						
							|  |  |  | 		const newConnections2 = newMgm.incomingConnections; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		for (const connection of oldConnections2) { | 
					
						
							| 
									
										
										
										
											2018-07-27 21:57:44 +08:00
										 |  |  | 			if (filterConnection(connection)) { | 
					
						
							|  |  |  | 				connection.module = newModule; | 
					
						
							|  |  |  | 				newConnections2.add(connection); | 
					
						
							|  |  |  | 				oldConnections2.delete(connection); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} oldModule the old referencing module | 
					
						
							|  |  |  | 	 * @param {Module} newModule the new referencing module | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  | 	 * @param {FilterConnection} filterConnection filter predicate for replacement | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	copyOutgoingModuleConnections(oldModule, newModule, filterConnection) { | 
					
						
							|  |  |  | 		if (oldModule === newModule) return; | 
					
						
							|  |  |  | 		const oldMgm = this._getModuleGraphModule(oldModule); | 
					
						
							|  |  |  | 		const newMgm = this._getModuleGraphModule(newModule); | 
					
						
							|  |  |  | 		// Outgoing connections
 | 
					
						
							|  |  |  | 		const oldConnections = oldMgm.outgoingConnections; | 
					
						
							|  |  |  | 		if (oldConnections !== undefined) { | 
					
						
							|  |  |  | 			if (newMgm.outgoingConnections === undefined) { | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 				newMgm.outgoingConnections = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			const newConnections = newMgm.outgoingConnections; | 
					
						
							|  |  |  | 			for (const connection of oldConnections) { | 
					
						
							|  |  |  | 				if (filterConnection(connection)) { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 					const newConnection = connection.clone(); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 					newConnection.originModule = newModule; | 
					
						
							|  |  |  | 					newConnections.add(newConnection); | 
					
						
							|  |  |  | 					if (newConnection.module !== undefined) { | 
					
						
							|  |  |  | 						const otherMgm = this._getModuleGraphModule(newConnection.module); | 
					
						
							|  |  |  | 						otherMgm.incomingConnections.add(newConnection); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the referenced module | 
					
						
							|  |  |  | 	 * @param {string} explanation an explanation why it's referenced | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	addExtraReason(module, explanation) { | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const connections = this._getModuleGraphModule(module).incomingConnections; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		connections.add(new ModuleGraphConnection(null, null, module, explanation)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referenced module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {Module | null} the referenced module | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getResolvedModule(dependency) { | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		const connection = this.getConnection(dependency); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		return connection !== undefined ? connection.resolvedModule : null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referenced module | 
					
						
							|  |  |  | 	 * @returns {ModuleGraphConnection | undefined} the connection | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getConnection(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(dependency); | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		if (connection === undefined) { | 
					
						
							|  |  |  | 			const module = this.getParentModule(dependency); | 
					
						
							|  |  |  | 			if (module !== undefined) { | 
					
						
							|  |  |  | 				const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 				if ( | 
					
						
							|  |  |  | 					mgm._unassignedConnections && | 
					
						
							|  |  |  | 					mgm._unassignedConnections.length !== 0 | 
					
						
							|  |  |  | 				) { | 
					
						
							|  |  |  | 					let foundConnection; | 
					
						
							|  |  |  | 					for (const connection of mgm._unassignedConnections) { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 						this._dependencyMap.set( | 
					
						
							|  |  |  | 							/** @type {Dependency} */ (connection.dependency), | 
					
						
							|  |  |  | 							connection | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 						if (connection.dependency === dependency) { | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 							foundConnection = connection; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					mgm._unassignedConnections.length = 0; | 
					
						
							|  |  |  | 					if (foundConnection !== undefined) { | 
					
						
							|  |  |  | 						return foundConnection; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			this._dependencyMap.set(dependency, null); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return connection === null ? undefined : connection; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referenced module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {Module | null} the referenced module | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getModule(dependency) { | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		const connection = this.getConnection(dependency); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		return connection !== undefined ? connection.module : null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referencing module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {Module | null} the referencing module | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrigin(dependency) { | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		const connection = this.getConnection(dependency); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		return connection !== undefined ? connection.originModule : null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referencing module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {Module | null} the original referencing module | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getResolvedOrigin(dependency) { | 
					
						
							| 
									
										
										
										
											2021-09-28 21:33:04 +08:00
										 |  |  | 		const connection = this.getConnection(dependency); | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 		return connection !== undefined ? connection.resolvedOriginModule : null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2019-11-08 05:12:31 +08:00
										 |  |  | 	 * @returns {Iterable<ModuleGraphConnection>} reasons why a module is included | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getIncomingConnections(module) { | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const connections = this._getModuleGraphModule(module).incomingConnections; | 
					
						
							| 
									
										
										
										
											2019-11-08 05:12:31 +08:00
										 |  |  | 		return connections; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2019-11-08 05:12:31 +08:00
										 |  |  | 	 * @returns {Iterable<ModuleGraphConnection>} list of outgoing connections | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 	getOutgoingConnections(module) { | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const connections = this._getModuleGraphModule(module).outgoingConnections; | 
					
						
							| 
									
										
										
										
											2021-04-27 19:58:13 +08:00
										 |  |  | 		return connections === undefined ? EMPTY_SET : connections; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-10 19:38:19 +08:00
										 |  |  | 	 * @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} reasons why a module is included, in a map by source module | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getIncomingConnectionsByOriginModule(module) { | 
					
						
							|  |  |  | 		const connections = this._getModuleGraphModule(module).incomingConnections; | 
					
						
							|  |  |  | 		return connections.getFromUnorderedCache(getConnectionsByOriginModule); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-10 19:38:19 +08:00
										 |  |  | 	 * @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>> | undefined} connections to modules, in a map by module | 
					
						
							| 
									
										
										
										
											2021-10-05 19:08:21 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getOutgoingConnectionsByModule(module) { | 
					
						
							|  |  |  | 		const connections = this._getModuleGraphModule(module).outgoingConnections; | 
					
						
							|  |  |  | 		return connections === undefined | 
					
						
							|  |  |  | 			? undefined | 
					
						
							|  |  |  | 			: connections.getFromUnorderedCache(getConnectionsByModule); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 	 * @returns {ModuleProfile | undefined} the module profile | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getProfile(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.profile; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2024-03-14 02:23:33 +08:00
										 |  |  | 	 * @param {ModuleProfile | undefined} profile the module profile | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setProfile(module, profile) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.profile = profile; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 	 * @returns {Issuer} the issuer module | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getIssuer(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.issuer; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {Module | null} issuer the issuer module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setIssuer(module, issuer) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.issuer = issuer; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-07 17:56:26 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {Module | null} issuer the issuer module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setIssuerIfUnset(module, issuer) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		if (mgm.issuer === undefined) mgm.issuer = issuer; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 	 * @returns {OptimizationBailouts} optimization bailouts | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getOptimizationBailout(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.optimizationBailout; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 	 * @returns {null | true | ExportInfoName[]} the provided exports | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getProvidedExports(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 		return mgm.exports.getProvidedExports(); | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-09-11 08:10:10 +08:00
										 |  |  | 	 * @param {ExportInfoName | ExportInfoName[]} exportName a name of an export | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 	 * @returns {boolean | null} true, if the export is provided by the module. | 
					
						
							| 
									
										
										
										
											2020-03-03 20:37:18 +08:00
										 |  |  | 	 * null, if it's unknown. | 
					
						
							|  |  |  | 	 * false, if it's not provided. | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 	isExportProvided(module, exportName) { | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 		const result = mgm.exports.isExportProvided(exportName); | 
					
						
							|  |  |  | 		return result === undefined ? null : result; | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 19:51:35 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 	 * @returns {ExportsInfo} info about the exports | 
					
						
							| 
									
										
										
										
											2018-12-31 19:51:35 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 	getExportsInfo(module) { | 
					
						
							| 
									
										
										
										
											2018-12-31 19:51:35 +08:00
										 |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 		return mgm.exports; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {string} exportName the export | 
					
						
							|  |  |  | 	 * @returns {ExportInfo} info about the export | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getExportInfo(module, exportName) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.exports.getExportInfo(exportName); | 
					
						
							| 
									
										
										
										
											2018-12-31 19:51:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 17:40:32 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {string} exportName the export | 
					
						
							|  |  |  | 	 * @returns {ExportInfo} info about the export (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getReadOnlyExportInfo(module, exportName) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.exports.getReadOnlyExportInfo(exportName); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	 * @returns {false | true | SortableSet<string> | null} the used exports | 
					
						
							|  |  |  | 	 * false: module is not used at all. | 
					
						
							|  |  |  | 	 * true: the module namespace/object export is used. | 
					
						
							|  |  |  | 	 * SortableSet<string>: these export names are used. | 
					
						
							|  |  |  | 	 * empty SortableSet<string>: module is used but no export. | 
					
						
							|  |  |  | 	 * null: unknown, worst case should be assumed. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	getUsedExports(module, runtime) { | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		return mgm.exports.getUsedExports(runtime); | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {number | null} the index of the module | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getPreOrderIndex(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.preOrderIndex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {number | null} the index of the module | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getPostOrderIndex(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.postOrderIndex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} index the index of the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setPreOrderIndex(module, index) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.preOrderIndex = index; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} index the index of the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the index was set | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setPreOrderIndexIfUnset(module, index) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		if (mgm.preOrderIndex === null) { | 
					
						
							|  |  |  | 			mgm.preOrderIndex = index; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} index the index of the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setPostOrderIndex(module, index) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.postOrderIndex = index; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} index the index of the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the index was set | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setPostOrderIndexIfUnset(module, index) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		if (mgm.postOrderIndex === null) { | 
					
						
							|  |  |  | 			mgm.postOrderIndex = index; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @returns {number | null} the depth of the module | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getDepth(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.depth; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} depth the depth of the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setDepth(module, depth) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.depth = depth; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {number} depth the depth of the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the depth was set | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setDepthIfLower(module, depth) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		if (mgm.depth === null || mgm.depth > depth) { | 
					
						
							|  |  |  | 			mgm.depth = depth; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the module is async | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isAsync(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.async; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2025-07-02 20:02:03 +08:00
										 |  |  | 	 * @returns {boolean} true, if the module is used as a deferred module at least once | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isDeferred(module) { | 
					
						
							|  |  |  | 		if (this.isAsync(module)) return false; | 
					
						
							|  |  |  | 		const connections = this.getIncomingConnections(module); | 
					
						
							|  |  |  | 		for (const connection of connections) { | 
					
						
							|  |  |  | 			if ( | 
					
						
							|  |  |  | 				!connection.dependency || | 
					
						
							| 
									
										
										
										
											2025-08-04 22:38:42 +08:00
										 |  |  | 				!(connection.dependency instanceof HarmonyImportDependency) | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:02:03 +08:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-07-02 20:02:03 +08:00
										 |  |  | 			if (connection.dependency.defer) return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setAsync(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.async = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 	 * @param {MetaKey} thing any thing | 
					
						
							|  |  |  | 	 * @returns {Meta} metadata | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getMeta(thing) { | 
					
						
							|  |  |  | 		let meta = this._metaMap.get(thing); | 
					
						
							|  |  |  | 		if (meta === undefined) { | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 			meta = /** @type {Meta} */ (Object.create(null)); | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 			this._metaMap.set(thing, meta); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 		return meta; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:19:37 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-04-03 00:02:22 +08:00
										 |  |  | 	 * @param {MetaKey} thing any thing | 
					
						
							|  |  |  | 	 * @returns {Meta | undefined} metadata | 
					
						
							| 
									
										
										
										
											2021-01-27 20:19:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getMetaIfExisting(thing) { | 
					
						
							|  |  |  | 		return this._metaMap.get(thing); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string=} cacheStage a persistent stage name for caching | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	freeze(cacheStage) { | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 		this._cache = new WeakTupleMap(); | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 		this._cacheStage = cacheStage; | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unfreeze() { | 
					
						
							|  |  |  | 		this._cache = undefined; | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 		this._cacheStage = undefined; | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 	 * @template {EXPECTED_ANY[]} T | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 	 * @template R | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 	 * @param {(moduleGraph: ModuleGraph, ...args: T) => R} fn computer | 
					
						
							|  |  |  | 	 * @param {T} args arguments | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 	 * @returns {R} computed value or cached | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	cached(fn, ...args) { | 
					
						
							|  |  |  | 		if (this._cache === undefined) return fn(this, ...args); | 
					
						
							|  |  |  | 		return this._cache.provide(fn, ...args, () => fn(this, ...args)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  | 	 * @param {ModuleMemCaches} moduleMemCaches mem caches for modules for better caching | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	setModuleMemCaches(moduleMemCaches) { | 
					
						
							|  |  |  | 		this._moduleMemCaches = moduleMemCaches; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 	 * @template {Dependency} D | 
					
						
							|  |  |  | 	 * @template {EXPECTED_ANY[]} ARGS | 
					
						
							|  |  |  | 	 * @template R | 
					
						
							|  |  |  | 	 * @param {D} dependency dependency | 
					
						
							|  |  |  | 	 * @param {[...ARGS, (moduleGraph: ModuleGraph, dependency: D, ...args: ARGS) => R]} args arguments, last argument is a function called with moduleGraph, dependency, ...args | 
					
						
							|  |  |  | 	 * @returns {R} computed value or cached | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	dependencyCacheProvide(dependency, ...args) { | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 		const fn = | 
					
						
							|  |  |  | 			/** @type {(moduleGraph: ModuleGraph, dependency: D, ...args: EXPECTED_ANY[]) => R} */ | 
					
						
							|  |  |  | 			(args.pop()); | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 		if (this._moduleMemCaches && this._cacheStage) { | 
					
						
							|  |  |  | 			const memCache = this._moduleMemCaches.get( | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 				/** @type {Module} */ | 
					
						
							|  |  |  | 				(this.getParentModule(dependency)) | 
					
						
							| 
									
										
										
										
											2021-09-27 23:21:09 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 			if (memCache !== undefined) { | 
					
						
							|  |  |  | 				return memCache.provide(dependency, this._cacheStage, ...args, () => | 
					
						
							|  |  |  | 					fn(this, dependency, ...args) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (this._cache === undefined) return fn(this, dependency, ...args); | 
					
						
							|  |  |  | 		return this._cache.provide(dependency, ...args, () => | 
					
						
							|  |  |  | 			fn(this, dependency, ...args) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {string} deprecateMessage message for the deprecation message | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	 * @param {string} deprecationCode code for the deprecation | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	 * @returns {ModuleGraph} the module graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	static getModuleGraphForModule(module, deprecateMessage, deprecationCode) { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		const fn = deprecateMap.get(deprecateMessage); | 
					
						
							|  |  |  | 		if (fn) return fn(module); | 
					
						
							|  |  |  | 		const newFn = util.deprecate( | 
					
						
							|  |  |  | 			/** | 
					
						
							|  |  |  | 			 * @param {Module} module the module | 
					
						
							|  |  |  | 			 * @returns {ModuleGraph} the module graph | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			(module) => { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 				const moduleGraph = moduleGraphForModuleMap.get(module); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 				if (!moduleGraph) { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 					throw new Error( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 						`${ | 
					
						
							|  |  |  | 							deprecateMessage | 
					
						
							|  |  |  | 						}There was no ModuleGraph assigned to the Module for backward-compat (Use the new API)`
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 				return moduleGraph; | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			`${deprecateMessage}: Use new ModuleGraph API`, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			deprecationCode | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		deprecateMap.set(deprecateMessage, newFn); | 
					
						
							|  |  |  | 		return newFn(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static setModuleGraphForModule(module, moduleGraph) { | 
					
						
							|  |  |  | 		moduleGraphForModuleMap.set(module, moduleGraph); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static clearModuleGraphForModule(module) { | 
					
						
							|  |  |  | 		moduleGraphForModuleMap.delete(module); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-17 22:41:07 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {WeakMap<Module, ModuleGraph>} */ | 
					
						
							|  |  |  | const moduleGraphForModuleMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {Map<string, (module: Module) => ModuleGraph>} */ | 
					
						
							|  |  |  | const deprecateMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 22:41:07 +08:00
										 |  |  | module.exports = ModuleGraph; | 
					
						
							| 
									
										
										
										
											2020-07-28 01:36:06 +08:00
										 |  |  | module.exports.ModuleGraphConnection = ModuleGraphConnection; |