| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | Author Tobias Koppers @sokra | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 15:47:43 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2017-06-18 11:57:11 +08:00
										 |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:15 +08:00
										 |  |  | const intersect = require("./util/SetHelpers").intersect; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | const GraphHelpers = require("./GraphHelpers"); | 
					
						
							| 
									
										
										
										
											2018-07-13 09:00:44 +08:00
										 |  |  | const Entrypoint = require("./Entrypoint"); | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | let debugId = 1000; | 
					
						
							| 
									
										
										
										
											2018-02-17 19:09:35 +08:00
										 |  |  | const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()"; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const ERR_CHUNK_INITIAL = | 
					
						
							|  |  |  | 	"Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 20:48:28 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup")} ChunkGroup */ | 
					
						
							| 
									
										
										
										
											2018-07-09 20:48:28 +08:00
										 |  |  | /** @typedef {import("./ModuleReason")} ModuleReason */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-06-25 22:01:57 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  |  *  @typedef {Object} WithId an object who has an id property * | 
					
						
							| 
									
										
										
										
											2018-06-06 12:11:24 +08:00
										 |  |  |  *  @property {string | number} id the id of the object | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  |  * Compare two Modules based on their ids for sorting | 
					
						
							|  |  |  |  * @param {Module} a module | 
					
						
							|  |  |  |  * @param {Module} b module | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {-1|0|1} sort value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | // TODO use @callback
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */ | 
					
						
							|  |  |  | /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */ | 
					
						
							|  |  |  | /** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */ | 
					
						
							| 
									
										
										
										
											2018-06-21 19:38:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | const sortModuleById = (a, b) => { | 
					
						
							|  |  |  | 	if (a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if (b.id < a.id) return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  |  * Compare two ChunkGroups based on their ids for sorting | 
					
						
							|  |  |  |  * @param {ChunkGroup} a chunk group | 
					
						
							|  |  |  |  * @param {ChunkGroup} b chunk group | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {-1|0|1} sort value | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | const sortChunkGroupById = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if (b.id < a.id) return 1; | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-06 12:11:24 +08:00
										 |  |  |  * Compare two Identifiables , based on their ids for sorting | 
					
						
							|  |  |  |  * @param {Module} a first object with ident fn | 
					
						
							|  |  |  |  * @param {Module} b second object with ident fn | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {-1|0|1} The order number of the sort | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | const sortByIdentifier = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.identifier() > b.identifier()) return 1; | 
					
						
							|  |  |  | 	if (a.identifier() < b.identifier()) return -1; | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-06-18 11:57:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @returns {string} a concatenation of module identifiers sorted | 
					
						
							|  |  |  |  * @param {SortableSet} set to pull module identifiers from | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | const getModulesIdent = set => { | 
					
						
							|  |  |  | 	set.sort(); | 
					
						
							|  |  |  | 	let str = ""; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for (const m of set) { | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | 		str += m.identifier() + "#"; | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | 	return str; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-05 05:22:20 +08:00
										 |  |  |  * @template T | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  |  * @param {SortableSet<T>} set the sortable set to convert to array | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {Array<T>} the array returned from Array.from(set) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | const getArray = set => Array.from(set); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  |  * @param {SortableSet<Module>} set the sortable Set to get the count/size of | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {number} the size of the modules | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | const getModulesSize = set => { | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	let size = 0; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for (const module of set) { | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		size += module.size(); | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	return size; | 
					
						
							| 
									
										
										
										
											2017-11-03 17:17:08 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * A Chunk is a unit of encapsulation for Modules. | 
					
						
							|  |  |  |  * Chunks are "rendered" into bundles that get emitted when the build completes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | class Chunk { | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string=} name of chunk being created, is optional (for subclasses) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	constructor(name) { | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {number | null} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.id = null; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {number[] | null} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.ids = null; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.debugId = debugId++; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.name = name; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2018-04-26 01:45:53 +08:00
										 |  |  | 		this.preventIntegration = false; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {Module=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.entryModule = undefined; | 
					
						
							| 
									
										
										
										
											2018-06-06 12:11:24 +08:00
										 |  |  | 		/** @private @type {SortableSet<Module>} */ | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 		this._modules = new SortableSet(undefined, sortByIdentifier); | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | 		/** @type {string?} */ | 
					
						
							|  |  |  | 		this.filenameTemplate = undefined; | 
					
						
							| 
									
										
										
										
											2018-07-12 10:00:17 +08:00
										 |  |  | 		/** @private @type {SortableSet<ChunkGroup>} */ | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | 		this._groups = new SortableSet(undefined, sortChunkGroupById); | 
					
						
							| 
									
										
										
										
											2018-06-21 19:38:17 +08:00
										 |  |  | 		/** @type {string[]} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.files = []; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.rendered = false; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.hash = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {Object} */ | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 		this.contentHash = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.renderedHash = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.chunkReason = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.extraAsync = false; | 
					
						
							| 
									
										
										
										
											2018-04-21 07:51:40 +08:00
										 |  |  | 		this.removedModules = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead | 
					
						
							|  |  |  | 	 * @returns {never} Throws an error trying to access this property | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	get entry() { | 
					
						
							| 
									
										
										
										
											2018-02-17 19:09:35 +08:00
										 |  |  | 		throw new Error(ERR_CHUNK_ENTRY); | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @deprecated .entry has been deprecated. Please use .hasRuntime() instead | 
					
						
							|  |  |  | 	 * @param {never} data The data that was attempting to be set | 
					
						
							|  |  |  | 	 * @returns {never} Throws an error trying to access this property | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	set entry(data) { | 
					
						
							| 
									
										
										
										
											2018-02-17 19:09:35 +08:00
										 |  |  | 		throw new Error(ERR_CHUNK_ENTRY); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial() | 
					
						
							|  |  |  | 	 * @returns {never} Throws an error trying to access this property | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	get initial() { | 
					
						
							| 
									
										
										
										
											2018-02-17 19:09:35 +08:00
										 |  |  | 		throw new Error(ERR_CHUNK_INITIAL); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial() | 
					
						
							|  |  |  | 	 * @param {never} data The data attempting to be set | 
					
						
							|  |  |  | 	 * @returns {never} Throws an error trying to access this property | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	set initial(data) { | 
					
						
							| 
									
										
										
										
											2018-02-17 19:09:35 +08:00
										 |  |  | 		throw new Error(ERR_CHUNK_INITIAL); | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether or not the Chunk will have a runtime | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	hasRuntime() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-10-19 18:06:15 +08:00
										 |  |  | 			if ( | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 				chunkGroup.isInitial() && | 
					
						
							| 
									
										
										
										
											2018-07-13 09:00:44 +08:00
										 |  |  | 				chunkGroup instanceof Entrypoint && | 
					
						
							|  |  |  | 				chunkGroup.getRuntimeChunk() === this | 
					
						
							| 
									
										
										
										
											2018-10-19 18:06:15 +08:00
										 |  |  | 			) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether or not this chunk can be an initial chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	canBeInitial() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							|  |  |  | 			if (chunkGroup.isInitial()) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether this chunk can only be an initial chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	isOnlyInitial() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._groups.size <= 0) return false; | 
					
						
							|  |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							|  |  |  | 			if (!chunkGroup.isInitial()) return false; | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} if this chunk contains the entry module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	hasEntryModule() { | 
					
						
							|  |  |  | 		return !!this.entryModule; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module that will be added to this chunk. | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if the chunk doesn't have the module and it was added | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 13:55:20 +08:00
										 |  |  | 	addModule(module) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this._modules.has(module)) { | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 			this._modules.add(module); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-26 13:55:20 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module that will be removed from this chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk exists and is successfully deleted | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	removeModule(module) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._modules.delete(module)) { | 
					
						
							| 
									
										
										
										
											2017-02-13 18:26:25 +08:00
										 |  |  | 			module.removeChunk(this); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module[]} modules the new modules to be set | 
					
						
							|  |  |  | 	 * @returns {void} set new modules to this chunk and return nothing | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	setModules(modules) { | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 		this._modules = new SortableSet(modules, sortByIdentifier); | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the amount of modules in chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	getNumberOfModules() { | 
					
						
							|  |  |  | 		return this._modules.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {SortableSet} return the modules SortableSet for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	get modulesIterable() { | 
					
						
							|  |  |  | 		return this._modules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	addGroup(chunkGroup) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._groups.has(chunkGroup)) return false; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._groups.add(chunkGroup); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	removeGroup(chunkGroup) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this._groups.has(chunkGroup)) return false; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._groups.delete(chunkGroup); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup to check | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	isInGroup(chunkGroup) { | 
					
						
							|  |  |  | 		return this._groups.has(chunkGroup); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the amount of groups said chunk is in | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	getNumberOfGroups() { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:47:08 +08:00
										 |  |  | 		return this._groups.size; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 	 * @returns {SortableSet<ChunkGroup>} the chunkGroups that said chunk is referenced in | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get groupsIterable() { | 
					
						
							|  |  |  | 		return this._groups; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the chunk to compare itself with | 
					
						
							|  |  |  | 	 * @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	compareTo(otherChunk) { | 
					
						
							| 
									
										
										
										
											2018-10-19 18:20:33 +08:00
										 |  |  | 		if (this.name && !otherChunk.name) return -1; | 
					
						
							|  |  |  | 		if (!this.name && otherChunk.name) return 1; | 
					
						
							|  |  |  | 		if (this.name < otherChunk.name) return -1; | 
					
						
							|  |  |  | 		if (this.name > otherChunk.name) return 1; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._modules.size > otherChunk._modules.size) return -1; | 
					
						
							|  |  |  | 		if (this._modules.size < otherChunk._modules.size) return 1; | 
					
						
							| 
									
										
										
										
											2018-08-13 06:08:30 +08:00
										 |  |  | 		this._modules.sort(); | 
					
						
							|  |  |  | 		otherChunk._modules.sort(); | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 		const a = this._modules[Symbol.iterator](); | 
					
						
							|  |  |  | 		const b = otherChunk._modules[Symbol.iterator](); | 
					
						
							| 
									
										
										
										
											2018-06-27 19:48:13 +08:00
										 |  |  | 		// eslint-disable-next-line no-constant-condition
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (true) { | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 			const aItem = a.next(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (aItem.done) return 0; | 
					
						
							| 
									
										
										
										
											2018-08-13 06:08:30 +08:00
										 |  |  | 			const bItem = b.next(); | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 			const aModuleIdentifier = aItem.value.identifier(); | 
					
						
							|  |  |  | 			const bModuleIdentifier = bItem.value.identifier(); | 
					
						
							| 
									
										
										
										
											2018-04-17 15:35:57 +08:00
										 |  |  | 			if (aModuleIdentifier < bModuleIdentifier) return -1; | 
					
						
							|  |  |  | 			if (aModuleIdentifier > bModuleIdentifier) return 1; | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module Module to check | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if module does exist in this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	containsModule(module) { | 
					
						
							|  |  |  | 		return this._modules.has(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-11 19:16:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Module[]} an array of modules (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	getModules() { | 
					
						
							| 
									
										
										
										
											2017-11-06 19:15:23 +08:00
										 |  |  | 		return this._modules.getFromCache(getArray); | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 22:10:27 +08:00
										 |  |  | 	getModulesIdent() { | 
					
						
							| 
									
										
										
										
											2017-11-06 19:15:23 +08:00
										 |  |  | 		return this._modules.getFromUnorderedCache(getModulesIdent); | 
					
						
							| 
									
										
										
										
											2017-06-01 22:10:27 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 21:52:54 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string=} reason reason why chunk is removed | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	remove(reason) { | 
					
						
							| 
									
										
										
										
											2017-01-26 12:47:31 +08:00
										 |  |  | 		// cleanup modules
 | 
					
						
							| 
									
										
										
										
											2017-05-20 20:46:21 +08:00
										 |  |  | 		// Array.from is used here to create a clone, because removeChunk modifies this._modules
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const module of Array.from(this._modules)) { | 
					
						
							| 
									
										
										
										
											2017-01-26 12:42:23 +08:00
										 |  |  | 			module.removeChunk(this); | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.removeChunk(this); | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {Module} module module to move | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk other chunk to move it to | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 14:08:35 +08:00
										 |  |  | 	moveModule(module, otherChunk) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		GraphHelpers.disconnectChunkAndModule(this, module); | 
					
						
							|  |  |  | 		GraphHelpers.connectChunkAndModule(otherChunk, module); | 
					
						
							| 
									
										
										
										
											2017-01-26 14:08:35 +08:00
										 |  |  | 		module.rewriteChunkInReasons(this, [otherChunk]); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the chunk to integrate with | 
					
						
							|  |  |  | 	 * @param {ModuleReason} reason reason why the module is being integrated | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true or false if integration succeeds or fails | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 15:43:39 +08:00
										 |  |  | 	integrate(otherChunk, reason) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.canBeIntegrated(otherChunk)) { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:09:41 +08:00
										 |  |  | 		// Pick a new name for the integrated chunk
 | 
					
						
							|  |  |  | 		if (this.name && otherChunk.name) { | 
					
						
							| 
									
										
										
										
											2018-10-24 16:02:12 +08:00
										 |  |  | 			if (this.hasEntryModule() === otherChunk.hasEntryModule()) { | 
					
						
							| 
									
										
										
										
											2018-10-09 19:09:41 +08:00
										 |  |  | 				// When both chunks have entry modules or none have one, use
 | 
					
						
							|  |  |  | 				// shortest name
 | 
					
						
							|  |  |  | 				if (this.name.length !== otherChunk.name.length) { | 
					
						
							|  |  |  | 					this.name = | 
					
						
							|  |  |  | 						this.name.length < otherChunk.name.length | 
					
						
							|  |  |  | 							? this.name | 
					
						
							|  |  |  | 							: otherChunk.name; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.name = this.name < otherChunk.name ? this.name : otherChunk.name; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-10-24 16:02:12 +08:00
										 |  |  | 			} else if (otherChunk.hasEntryModule()) { | 
					
						
							| 
									
										
										
										
											2018-10-09 19:09:41 +08:00
										 |  |  | 				// Pick the name of the chunk with the entry module
 | 
					
						
							| 
									
										
										
										
											2018-10-04 20:10:36 +08:00
										 |  |  | 				this.name = otherChunk.name; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-19 18:06:15 +08:00
										 |  |  | 		} else if (otherChunk.name) { | 
					
						
							|  |  |  | 			this.name = otherChunk.name; | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-26 15:08:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-24 16:02:12 +08:00
										 |  |  | 		// Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
 | 
					
						
							|  |  |  | 		for (const module of Array.from(otherChunk._modules)) { | 
					
						
							|  |  |  | 			otherChunk.moveModule(module, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		otherChunk._modules.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (otherChunk.entryModule) { | 
					
						
							|  |  |  | 			this.entryModule = otherChunk.entryModule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of otherChunk._groups) { | 
					
						
							|  |  |  | 			chunkGroup.replaceChunk(otherChunk, this); | 
					
						
							|  |  |  | 			this.addGroup(chunkGroup); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		otherChunk._groups.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-11-08 05:07:51 +08:00
										 |  |  | 	 * @param {Chunk} newChunk the new chunk that will be split out of the current chunk | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	split(newChunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.insertChunk(newChunk, this); | 
					
						
							|  |  |  | 			newChunk.addGroup(chunkGroup); | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	isEmpty() { | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 		return this._modules.size === 0; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateHash(hash) { | 
					
						
							|  |  |  | 		hash.update(`${this.id} `); | 
					
						
							|  |  |  | 		hash.update(this.ids ? this.ids.join(",") : ""); | 
					
						
							|  |  |  | 		hash.update(`${this.name || ""} `); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const m of this._modules) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			hash.update(m.hash); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 15:47:45 +08:00
										 |  |  | 	canBeIntegrated(otherChunk) { | 
					
						
							| 
									
										
										
										
											2018-11-30 07:59:26 +08:00
										 |  |  | 		if (this.preventIntegration || otherChunk.preventIntegration) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const isAvailable = (a, b) => { | 
					
						
							|  |  |  | 			const queue = new Set(b.groupsIterable); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 				if (a.isInGroup(chunkGroup)) continue; | 
					
						
							|  |  |  | 				if (chunkGroup.isInitial()) return false; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				for (const parent of chunkGroup.parentsIterable) { | 
					
						
							|  |  |  | 					queue.add(parent); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-04-24 06:30:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 07:59:26 +08:00
										 |  |  | 		const selfHasRuntime = this.hasRuntime(); | 
					
						
							|  |  |  | 		const otherChunkHasRuntime = otherChunk.hasRuntime(); | 
					
						
							| 
									
										
										
										
											2018-04-24 06:30:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 07:59:26 +08:00
										 |  |  | 		if (selfHasRuntime !== otherChunkHasRuntime) { | 
					
						
							|  |  |  | 			if (selfHasRuntime) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				return isAvailable(this, otherChunk); | 
					
						
							| 
									
										
										
										
											2018-11-30 07:59:26 +08:00
										 |  |  | 			} else if (otherChunkHasRuntime) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				return isAvailable(otherChunk, this); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (this.hasEntryModule() || otherChunk.hasEntryModule()) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {number} size the size | 
					
						
							|  |  |  | 	 * @param {Object} options the options passed in | 
					
						
							|  |  |  | 	 * @returns {number} the multiplier returned | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 15:41:51 +08:00
										 |  |  | 	addMultiplierAndOverhead(size, options) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const overhead = | 
					
						
							|  |  |  | 			typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000; | 
					
						
							|  |  |  | 		const multiplicator = this.canBeInitial() | 
					
						
							|  |  |  | 			? options.entryChunkMultiplicator || 10 | 
					
						
							|  |  |  | 			: 1; | 
					
						
							| 
									
										
										
										
											2017-01-26 15:41:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return size * multiplicator + overhead; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the size of all modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 15:41:51 +08:00
										 |  |  | 	modulesSize() { | 
					
						
							| 
									
										
										
										
											2017-11-06 19:15:23 +08:00
										 |  |  | 		return this._modules.getFromUnorderedCache(getModulesSize); | 
					
						
							| 
									
										
										
										
											2017-01-26 15:41:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Object} options the size display options | 
					
						
							|  |  |  | 	 * @returns {number} the chunk size | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-02-20 22:23:32 +08:00
										 |  |  | 	size(options = {}) { | 
					
						
							| 
									
										
										
										
											2017-01-26 15:41:51 +08:00
										 |  |  | 		return this.addMultiplierAndOverhead(this.modulesSize(), options); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the other chunk | 
					
						
							|  |  |  | 	 * @param {TODO} options the options for this function | 
					
						
							|  |  |  | 	 * @returns {number | false} the size, or false if it can't be integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-26 15:47:45 +08:00
										 |  |  | 	integratedSize(otherChunk, options) { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		// Chunk if it's possible to integrate this chunk
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.canBeIntegrated(otherChunk)) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 21:24:33 +08:00
										 |  |  | 		let integratedModulesSize = this.modulesSize(); | 
					
						
							|  |  |  | 		// only count modules that do not exist in this chunk!
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const otherModule of otherChunk._modules) { | 
					
						
							|  |  |  | 			if (!this._modules.has(otherModule)) { | 
					
						
							| 
									
										
										
										
											2017-01-26 21:24:33 +08:00
										 |  |  | 				integratedModulesSize += otherModule.size(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this.addMultiplierAndOverhead(integratedModulesSize, options); | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  | 	 * @param {function(Module, Module): -1|0|1=} sortByFn a predicate function used to sort modules | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	sortModules(sortByFn) { | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | 		this._modules.sortWith(sortByFn || sortModuleById); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  | 	sortItems() { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.sortModules(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<Chunk>} a set of all the async chunks | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	getAllAsyncChunks() { | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:15 +08:00
										 |  |  | 		const queue = new Set(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const chunks = new Set(); | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:15 +08:00
										 |  |  | 		const initialChunks = intersect( | 
					
						
							|  |  |  | 			Array.from(this.groupsIterable, g => new Set(g.chunks)) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of this.groupsIterable) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!initialChunks.has(chunk)) { | 
					
						
							|  |  |  | 					chunks.add(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		return chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 	 * @typedef {Object} ChunkMaps | 
					
						
							|  |  |  | 	 * @property {Record<string|number, string>} hash | 
					
						
							|  |  |  | 	 * @property {Record<string|number, Record<string, string>>} contentHash | 
					
						
							|  |  |  | 	 * @property {Record<string|number, string>} name | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {boolean} realHash should the full hash or the rendered hash be used | 
					
						
							|  |  |  | 	 * @returns {ChunkMaps} the chunk map information | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	getChunkMaps(realHash) { | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		const chunkHashMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {Record<string|number, Record<string, string>>} */ | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 		const chunkContentHashMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		const chunkNameMap = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunk of this.getAllAsyncChunks()) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash; | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 			for (const key of Object.keys(chunk.contentHash)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!chunkContentHashMap[key]) { | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 					chunkContentHashMap[key] = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 				chunkContentHashMap[key][chunk.id] = chunk.contentHash[key]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (chunk.name) { | 
					
						
							|  |  |  | 				chunkNameMap[chunk.id] = chunk.name; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			hash: chunkHashMap, | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 			contentHash: chunkContentHashMap, | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 			name: chunkNameMap | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 	 * @returns {Record<string, Set<TODO>[]>} a record object of names to lists of child ids(?) | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 	getChildIdsByOrders() { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const lists = new Map(); | 
					
						
							|  |  |  | 		for (const group of this.groupsIterable) { | 
					
						
							|  |  |  | 			if (group.chunks[group.chunks.length - 1] === this) { | 
					
						
							|  |  |  | 				for (const childGroup of group.childrenIterable) { | 
					
						
							|  |  |  | 					// TODO webpack 5 remove this check for options
 | 
					
						
							|  |  |  | 					if (typeof childGroup.options === "object") { | 
					
						
							|  |  |  | 						for (const key of Object.keys(childGroup.options)) { | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 							if (key.endsWith("Order")) { | 
					
						
							|  |  |  | 								const name = key.substr(0, key.length - "Order".length); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 								let list = lists.get(name); | 
					
						
							|  |  |  | 								if (list === undefined) lists.set(name, (list = [])); | 
					
						
							|  |  |  | 								list.push({ | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 									order: childGroup.options[key], | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 									group: childGroup | 
					
						
							|  |  |  | 								}); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const result = Object.create(null); | 
					
						
							|  |  |  | 		for (const [name, list] of lists) { | 
					
						
							|  |  |  | 			list.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 				const cmp = b.order - a.order; | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				if (cmp !== 0) return cmp; | 
					
						
							| 
									
										
										
										
											2018-07-10 04:48:12 +08:00
										 |  |  | 				// TODO webpack 5 remove this check of compareTo
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (a.group.compareTo) { | 
					
						
							|  |  |  | 					return a.group.compareTo(b.group); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				return 0; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			result[name] = Array.from( | 
					
						
							|  |  |  | 				list.reduce((set, item) => { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					for (const chunk of item.group.chunks) { | 
					
						
							|  |  |  | 						set.add(chunk.id); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					return set; | 
					
						
							|  |  |  | 				}, new Set()) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 	getChildIdsByOrdersMap(includeDirectChildren) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const chunkMaps = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 		const addChildIdsByOrdersToMap = chunk => { | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 			const data = chunk.getChildIdsByOrders(); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			for (const key of Object.keys(data)) { | 
					
						
							|  |  |  | 				let chunkMap = chunkMaps[key]; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (chunkMap === undefined) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					chunkMaps[key] = chunkMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				chunkMap[chunk.id] = data[key]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (includeDirectChildren) { | 
					
						
							| 
									
										
										
										
											2019-05-11 05:04:29 +08:00
										 |  |  | 			const chunks = new Set(); | 
					
						
							|  |  |  | 			for (const chunkGroup of this.groupsIterable) { | 
					
						
							|  |  |  | 				for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 					chunks.add(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const chunk of chunks) { | 
					
						
							|  |  |  | 				addChildIdsByOrdersToMap(chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunk of this.getAllAsyncChunks()) { | 
					
						
							|  |  |  | 			addChildIdsByOrdersToMap(chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		return chunkMaps; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @typedef {Object} ChunkModuleMaps | 
					
						
							|  |  |  | 	 * @property {Record<string|number, (string|number)[]>} id | 
					
						
							|  |  |  | 	 * @property {Record<string|number, string>} hash | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 	 * @param {ModuleFilterPredicate} filterFn function used to filter modules | 
					
						
							|  |  |  | 	 * @returns {ChunkModuleMaps} module map information | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	getChunkModuleMaps(filterFn) { | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {Record<string|number, (string|number)[]>} */ | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		const chunkModuleIdMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		const chunkModuleHashMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunk of this.getAllAsyncChunks()) { | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 			/** @type {(string|number)[]} */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			let array; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const module of chunk.modulesIterable) { | 
					
						
							|  |  |  | 				if (filterFn(module)) { | 
					
						
							|  |  |  | 					if (array === undefined) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 						array = []; | 
					
						
							|  |  |  | 						chunkModuleIdMap[chunk.id] = array; | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					array.push(module.id); | 
					
						
							|  |  |  | 					chunkModuleHashMap[module.id] = module.renderedHash; | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (array !== undefined) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				array.sort(); | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			id: chunkModuleIdMap, | 
					
						
							|  |  |  | 			hash: chunkModuleHashMap | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  | 	 * @param {function(Module): boolean} filterFn predicate function used to filter modules | 
					
						
							|  |  |  | 	 * @param {function(Chunk): boolean} filterChunkFn predicate function used to filter chunks | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 * @returns {boolean} return true if module exists in graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	hasModuleInGraph(filterFn, filterChunkFn) { | 
					
						
							|  |  |  | 		const queue = new Set(this.groupsIterable); | 
					
						
							| 
									
										
										
										
											2017-11-21 19:57:40 +08:00
										 |  |  | 		const chunksProcessed = new Set(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				if (!chunksProcessed.has(chunk)) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					chunksProcessed.add(chunk); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (!filterChunkFn || filterChunkFn(chunk)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 						for (const module of chunk.modulesIterable) { | 
					
						
							|  |  |  | 							if (filterFn(module)) { | 
					
						
							|  |  |  | 								return true; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-11-21 19:57:40 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-21 19:57:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	toString() { | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 		return `Chunk[${Array.from(this._modules).join()}]`; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							|  |  |  | Object.defineProperty(Chunk.prototype, "forEachModule", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 	value: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @this {Chunk} | 
					
						
							|  |  |  | 		 * @typedef {function(any, any, Set<any>): void} ForEachModuleCallback | 
					
						
							|  |  |  | 		 * @param {ForEachModuleCallback} fn Callback function | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function(fn) { | 
					
						
							|  |  |  | 			this._modules.forEach(fn); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead" | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 5
 | 
					
						
							|  |  |  | Object.defineProperty(Chunk.prototype, "mapModules", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 	value: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @this {Chunk} | 
					
						
							|  |  |  | 		 * @typedef {function(any, number): any} MapModulesCallback | 
					
						
							|  |  |  | 		 * @param {MapModulesCallback} fn Callback function | 
					
						
							|  |  |  | 		 * @returns {TODO[]} result of mapped modules | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function(fn) { | 
					
						
							|  |  |  | 			return Array.from(this._modules, fn); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead" | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-06-24 09:03:48 +08:00
										 |  |  | Object.defineProperty(Chunk.prototype, "chunks", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead"); | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-06-24 09:03:48 +08:00
										 |  |  | 	set() { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead"); | 
					
						
							| 
									
										
										
										
											2017-06-24 09:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | Object.defineProperty(Chunk.prototype, "parents", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead"); | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | Object.defineProperty(Chunk.prototype, "blocks", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead"); | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | Object.defineProperty(Chunk.prototype, "entrypoints", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-01-20 18:28:45 +08:00
										 |  |  | 	get() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		throw new Error( | 
					
						
							|  |  |  | 			"Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-01-20 18:28:45 +08:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	set() { | 
					
						
							|  |  |  | 		throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | module.exports = Chunk; |