| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {SortableSet<ModuleGraphConnection>} set input | 
					
						
							|  |  |  |  * @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} mapped by origin module | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getConnectionsByOriginModule = set => { | 
					
						
							|  |  |  | 	const map = new Map(); | 
					
						
							|  |  |  | 	/** @type {Module | 0} */ | 
					
						
							|  |  |  | 	let lastModule = 0; | 
					
						
							|  |  |  | 	/** @type {ModuleGraphConnection[]} */ | 
					
						
							|  |  |  | 	let lastList = undefined; | 
					
						
							|  |  |  | 	for (const connection of set) { | 
					
						
							|  |  |  | 		const { originModule } = connection; | 
					
						
							|  |  |  | 		if (lastModule === originModule) { | 
					
						
							|  |  |  | 			lastList.push(connection); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			lastModule = originModule; | 
					
						
							|  |  |  | 			const list = map.get(originModule); | 
					
						
							|  |  |  | 			if (list !== undefined) { | 
					
						
							|  |  |  | 				lastList = list; | 
					
						
							|  |  |  | 				list.push(connection); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const list = [connection]; | 
					
						
							|  |  |  | 				lastList = list; | 
					
						
							|  |  |  | 				map.set(originModule, list); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return map; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | class ModuleGraphModule { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 		/** @type {SortableSet<ModuleGraphConnection>} */ | 
					
						
							|  |  |  | 		this.incomingConnections = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 		/** @type {Set<ModuleGraphConnection> | undefined} */ | 
					
						
							|  |  |  | 		this.outgoingConnections = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		/** @type {Module | null} */ | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		this.issuer = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		/** @type {(string | OptimizationBailoutFunction)[]} */ | 
					
						
							|  |  |  | 		this.optimizationBailout = []; | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 		/** @type {ExportsInfo} */ | 
					
						
							|  |  |  | 		this.exports = new ExportsInfo(); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:12:00 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							|  |  |  | 		this.preOrderIndex = null; | 
					
						
							|  |  |  | 		/** @type {number} */ | 
					
						
							|  |  |  | 		this.postOrderIndex = null; | 
					
						
							| 
									
										
										
										
											2018-08-22 01:16:02 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							|  |  |  | 		this.depth = null; | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 		/** @type {ModuleProfile} */ | 
					
						
							|  |  |  | 		this.profile = undefined; | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							|  |  |  | 		this.async = false; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 22:41:07 +08:00
										 |  |  | class ModuleGraph { | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	constructor() { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		/** @type {Map<Dependency, ModuleGraphConnection>} */ | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		this._dependencyMap = new Map(); | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		/** @type {Map<Module, ModuleGraphModule>} */ | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		this._moduleMap = new Map(); | 
					
						
							|  |  |  | 		/** @type {Map<Module, Set<ModuleGraphConnection>>} */ | 
					
						
							|  |  |  | 		this._originMap = new Map(); | 
					
						
							|  |  |  | 		/** @type {Map<any, Object>} */ | 
					
						
							|  |  |  | 		this._metaMap = new Map(); | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Caching
 | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleKey1 = undefined; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleValue1 = undefined; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleKey2 = undefined; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleValue2 = undefined; | 
					
						
							|  |  |  | 		this._cacheModuleGraphDependencyKey = undefined; | 
					
						
							|  |  |  | 		this._cacheModuleGraphDependencyValue = undefined; | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** @type {WeakTupleMap<any[], any>} */ | 
					
						
							|  |  |  | 		this._cache = undefined; | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:18 +08:00
										 |  |  | 		if (this._cacheModuleGraphModuleKey1 === module) | 
					
						
							|  |  |  | 			return this._cacheModuleGraphModuleValue1; | 
					
						
							|  |  |  | 		if (this._cacheModuleGraphModuleKey2 === module) | 
					
						
							|  |  |  | 			return this._cacheModuleGraphModuleValue2; | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		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
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:18 +08:00
										 |  |  | 		this._cacheModuleGraphModuleKey2 = this._cacheModuleGraphModuleKey1; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleValue2 = this._cacheModuleGraphModuleValue1; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleKey1 = module; | 
					
						
							|  |  |  | 		this._cacheModuleGraphModuleValue1 = mgm; | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setParents(dependency, block, module) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		dependency._parentDependenciesBlock = block; | 
					
						
							|  |  |  | 		dependency._parentModule = module; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency | 
					
						
							|  |  |  | 	 * @returns {Module} parent module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	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 | 
					
						
							|  |  |  | 	 * @returns {DependenciesBlock} parent block | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getParentBlock(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		return dependency._parentDependenciesBlock; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} originModule the referencing module | 
					
						
							|  |  |  | 	 * @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
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		this._dependencyMap.set(dependency, connection); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2019-11-08 20:07:17 +08:00
										 |  |  | 		const mgm = this._getModuleGraphModule(originModule); | 
					
						
							|  |  |  | 		if (mgm.outgoingConnections === undefined) { | 
					
						
							|  |  |  | 			mgm.outgoingConnections = new Set(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		mgm.outgoingConnections.add(connection); | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(dependency); | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 		const originMgm = this._getModuleGraphModule(connection.originModule); | 
					
						
							|  |  |  | 		originMgm.outgoingConnections.add(newConnection); | 
					
						
							|  |  |  | 		const targetMgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		targetMgm.incomingConnections.add(newConnection); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the referencing dependency | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	removeConnection(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(dependency); | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 		const targetMgm = this._getModuleGraphModule(connection.module); | 
					
						
							|  |  |  | 		targetMgm.incomingConnections.delete(connection); | 
					
						
							|  |  |  | 		const originMgm = this._getModuleGraphModule(connection.originModule); | 
					
						
							|  |  |  | 		originMgm.outgoingConnections.delete(connection); | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		this._dependencyMap.delete(dependency); | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(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 | 
					
						
							| 
									
										
										
										
											2018-07-27 21:57:44 +08:00
										 |  |  | 	 * @param {function(ModuleGraphConnection): boolean} 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) { | 
					
						
							|  |  |  | 				newMgm.outgoingConnections = new Set(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			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 | 
					
						
							|  |  |  | 	 * @param {function(ModuleGraphConnection): boolean} filterConnection filter predicate for replacement | 
					
						
							|  |  |  | 	 * @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) { | 
					
						
							|  |  |  | 				newMgm.outgoingConnections = new Set(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			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 | 
					
						
							|  |  |  | 	 * @returns {Module} the referenced module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getResolvedModule(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(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); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		return connection; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency to look for a referenced module | 
					
						
							|  |  |  | 	 * @returns {Module} the referenced module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModule(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(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 | 
					
						
							|  |  |  | 	 * @returns {Module} the referencing module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrigin(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(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 | 
					
						
							|  |  |  | 	 * @returns {Module} the original referencing module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getResolvedOrigin(dependency) { | 
					
						
							| 
									
										
										
										
											2021-04-18 03:12:50 +08:00
										 |  |  | 		const connection = this._dependencyMap.get(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 | 
					
						
							|  |  |  | 	 * @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getIncomingConnectionsByOriginModule(module) { | 
					
						
							|  |  |  | 		const connections = this._getModuleGraphModule(module).incomingConnections; | 
					
						
							|  |  |  | 		return connections.getFromUnorderedCache(getConnectionsByOriginModule); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 20:54:28 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {ModuleProfile | null} the module profile | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getProfile(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.profile; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {ModuleProfile | null} profile the module profile | 
					
						
							|  |  |  | 	 * @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 | 
					
						
							|  |  |  | 	 * @returns {Module | null} the issuer module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	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 | 
					
						
							|  |  |  | 	 * @returns {(string | OptimizationBailoutFunction)[]} optimization bailouts | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOptimizationBailout(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.optimizationBailout; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2018-12-31 19:43:03 +08:00
										 |  |  | 	 * @returns {true | string[] | null} 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 | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 	 * @param {string | string[]} 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 | 
					
						
							|  |  |  | 	 * @returns {number} the index of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getPreOrderIndex(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		return mgm.preOrderIndex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {number} the index of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	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 | 
					
						
							|  |  |  | 	 * @returns {number} the depth of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	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 | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setAsync(module) { | 
					
						
							|  |  |  | 		const mgm = this._getModuleGraphModule(module); | 
					
						
							|  |  |  | 		mgm.async = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {any} thing any thing | 
					
						
							|  |  |  | 	 * @returns {Object} metadata | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getMeta(thing) { | 
					
						
							|  |  |  | 		let meta = this._metaMap.get(thing); | 
					
						
							|  |  |  | 		if (meta === undefined) { | 
					
						
							|  |  |  | 			meta = Object.create(null); | 
					
						
							|  |  |  | 			this._metaMap.set(thing, meta); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return meta; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:19:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {any} thing any thing | 
					
						
							|  |  |  | 	 * @returns {Object} metadata | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getMetaIfExisting(thing) { | 
					
						
							|  |  |  | 		return this._metaMap.get(thing); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 	freeze() { | 
					
						
							|  |  |  | 		this._cache = new WeakTupleMap(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unfreeze() { | 
					
						
							|  |  |  | 		this._cache = undefined; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @template {any[]} T | 
					
						
							|  |  |  | 	 * @template V | 
					
						
							|  |  |  | 	 * @param {(moduleGraph: ModuleGraph, ...args: T) => V} fn computer | 
					
						
							|  |  |  | 	 * @param {T} args arguments | 
					
						
							|  |  |  | 	 * @returns {V} computed value or cached | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	cached(fn, ...args) { | 
					
						
							|  |  |  | 		if (this._cache === undefined) return fn(this, ...args); | 
					
						
							|  |  |  | 		return this._cache.provide(fn, ...args, () => fn(this, ...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 | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			module => { | 
					
						
							|  |  |  | 				const moduleGraph = moduleGraphForModuleMap.get(module); | 
					
						
							|  |  |  | 				if (!moduleGraph) | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						deprecateMessage + | 
					
						
							|  |  |  | 							"There was no ModuleGraph assigned to the Module for backward-compat (Use the new API)" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				return moduleGraph; | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-14 22:01:25 +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; |