| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2017-06-18 12:33:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | const DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | const ModuleReason = require("./ModuleReason"); | 
					
						
							| 
									
										
										
										
											2017-06-18 12:33:07 +08:00
										 |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | const Template = require("./Template"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** @typedef {import("./WebpackError")} WebpackError */ | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash */ | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | const EMPTY_RESOLVE_OPTIONS = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | let debugId = 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | const sortById = (a, b) => { | 
					
						
							|  |  |  | 	return a.id - b.id; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-06-18 12:33:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | const sortByDebugId = (a, b) => { | 
					
						
							|  |  |  | 	return a.debugId - b.debugId; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-06-18 12:33:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | /** @typedef {(requestShortener: RequestShortener) => string} OptimizationBailoutFunction */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | class Module extends DependenciesBlock { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 	constructor(type, context = null) { | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		this.type = type; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 		this.context = context; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Unique Id
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.debugId = debugId++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 18:07:23 +08:00
										 |  |  | 		// Hash
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-12-01 18:07:23 +08:00
										 |  |  | 		this.hash = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-12-01 18:07:23 +08:00
										 |  |  | 		this.renderedHash = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		// Info from Factory
 | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 		/** @type {TODO} */ | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolveOptions = EMPTY_RESOLVE_OPTIONS; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {object} */ | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.factoryMeta = {}; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Build
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {WebpackError[]} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.warnings = []; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {WebpackError[]} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.errors = []; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {object} */ | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildMeta = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {object} */ | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildInfo = undefined; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Graph (per Compilation)
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {ModuleReason[]} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.reasons = []; | 
					
						
							| 
									
										
										
										
											2018-06-06 12:11:24 +08:00
										 |  |  | 		/** @type {SortableSet<Chunk>} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this._chunks = new SortableSet(undefined, sortById); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Compilation (per Compilation)
 | 
					
						
							| 
									
										
										
										
											2018-04-21 07:51:40 +08:00
										 |  |  | 		/** @type {number|string} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.id = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.index = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.index2 = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.depth = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {Module} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.issuer = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {undefined | object} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.profile = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.prefetched = false; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.built = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Optimization (per Compilation)
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {null | boolean} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.used = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {false | true | string[]} */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.usedExports = null; | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {(string | OptimizationBailoutFunction)[]} */ | 
					
						
							| 
									
										
										
										
											2017-05-28 21:25:07 +08:00
										 |  |  | 		this.optimizationBailout = []; | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// delayed operations
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {undefined | {oldChunk: Chunk, newChunks: Chunk[]}[] } */ | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 		this._rewriteChunkInReasons = undefined; | 
					
						
							| 
									
										
										
										
											2018-03-28 13:49:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:18:53 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2018-03-28 13:49:10 +08:00
										 |  |  | 		this.useSourceMap = false; | 
					
						
							| 
									
										
										
										
											2018-05-01 12:00:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// info from build
 | 
					
						
							|  |  |  | 		this._source = null; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 	get exportsArgument() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return (this.buildInfo && this.buildInfo.exportsArgument) || "exports"; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get moduleArgument() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return (this.buildInfo && this.buildInfo.moduleArgument) || "module"; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	disconnect() { | 
					
						
							| 
									
										
										
										
											2017-12-01 18:07:23 +08:00
										 |  |  | 		this.hash = undefined; | 
					
						
							|  |  |  | 		this.renderedHash = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.reasons.length = 0; | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 		this._rewriteChunkInReasons = undefined; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this._chunks.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.id = null; | 
					
						
							|  |  |  | 		this.index = null; | 
					
						
							|  |  |  | 		this.index2 = null; | 
					
						
							|  |  |  | 		this.depth = null; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.issuer = null; | 
					
						
							|  |  |  | 		this.profile = undefined; | 
					
						
							|  |  |  | 		this.prefetched = false; | 
					
						
							|  |  |  | 		this.built = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.used = null; | 
					
						
							|  |  |  | 		this.usedExports = null; | 
					
						
							| 
									
										
										
										
											2017-08-24 05:16:54 +08:00
										 |  |  | 		this.optimizationBailout.length = 0; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		super.disconnect(); | 
					
						
							| 
									
										
										
										
											2017-02-13 18:26:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	unseal() { | 
					
						
							|  |  |  | 		this.id = null; | 
					
						
							|  |  |  | 		this.index = null; | 
					
						
							|  |  |  | 		this.index2 = null; | 
					
						
							|  |  |  | 		this.depth = null; | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | 		this._chunks.clear(); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		super.unseal(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-20 20:47:38 +08:00
										 |  |  | 	setChunks(chunks) { | 
					
						
							|  |  |  | 		this._chunks = new SortableSet(chunks, sortById); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	addChunk(chunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._chunks.has(chunk)) return false; | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | 		this._chunks.add(chunk); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	removeChunk(chunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._chunks.delete(chunk)) { | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 			chunk.removeModule(this); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | 	isInChunk(chunk) { | 
					
						
							|  |  |  | 		return this._chunks.has(chunk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	isEntryModule() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunk of this._chunks) { | 
					
						
							|  |  |  | 			if (chunk.entryModule === this) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 	get optional() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return ( | 
					
						
							|  |  |  | 			this.reasons.length > 0 && | 
					
						
							|  |  |  | 			this.reasons.every(r => r.dependency && r.dependency.optional) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Chunk[]} all chunks which contain the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 	getChunks() { | 
					
						
							|  |  |  | 		return Array.from(this._chunks); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | 	getNumberOfChunks() { | 
					
						
							|  |  |  | 		return this._chunks.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 20:13:09 +08:00
										 |  |  | 	get chunksIterable() { | 
					
						
							|  |  |  | 		return this._chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 	hasEqualsChunks(otherModule) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._chunks.size !== otherModule._chunks.size) return false; | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 		this._chunks.sortWith(sortByDebugId); | 
					
						
							|  |  |  | 		otherModule._chunks.sortWith(sortByDebugId); | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 		const a = this._chunks[Symbol.iterator](); | 
					
						
							|  |  |  | 		const b = otherModule._chunks[Symbol.iterator](); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:15:37 +08:00
										 |  |  | 		// eslint-disable-next-line no-constant-condition
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (true) { | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 			const aItem = a.next(); | 
					
						
							|  |  |  | 			const bItem = b.next(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (aItem.done) return true; | 
					
						
							|  |  |  | 			if (aItem.value !== bItem.value) return false; | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 01:52:35 +08:00
										 |  |  | 	addReason(module, dependency, explanation) { | 
					
						
							|  |  |  | 		this.reasons.push(new ModuleReason(module, dependency, explanation)); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	removeReason(module, dependency) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this.reasons.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 			let r = this.reasons[i]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (r.module === module && r.dependency === dependency) { | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 				this.reasons.splice(i, 1); | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	hasReasonForChunk(chunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._rewriteChunkInReasons) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const operation of this._rewriteChunkInReasons) { | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 				this._doRewriteChunkInReasons(operation.oldChunk, operation.newChunks); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 			this._rewriteChunkInReasons = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this.reasons.length; i++) { | 
					
						
							|  |  |  | 			if (this.reasons[i].hasChunk(chunk)) return true; | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-17 06:31:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 	hasReasons() { | 
					
						
							|  |  |  | 		return this.reasons.length > 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	rewriteChunkInReasons(oldChunk, newChunks) { | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 		// This is expensive. Delay operation until we really need the data
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this._rewriteChunkInReasons === undefined) { | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 			this._rewriteChunkInReasons = []; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-25 00:22:58 +08:00
										 |  |  | 		this._rewriteChunkInReasons.push({ | 
					
						
							|  |  |  | 			oldChunk, | 
					
						
							|  |  |  | 			newChunks | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_doRewriteChunkInReasons(oldChunk, newChunks) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this.reasons.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-06-14 00:58:14 +08:00
										 |  |  | 			this.reasons[i].rewriteChunks(oldChunk, newChunks); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-11 20:13:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string=} exportName the name of the export | 
					
						
							|  |  |  | 	 * @returns {boolean|string} false if the export isn't used, true if no exportName is provided and the module is used, or the name to access it if the export is used | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	isUsed(exportName) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!exportName) return this.used !== false; | 
					
						
							|  |  |  | 		if (this.used === null || this.usedExports === null) return exportName; | 
					
						
							|  |  |  | 		if (!this.used) return false; | 
					
						
							|  |  |  | 		if (!this.usedExports) return false; | 
					
						
							|  |  |  | 		if (this.usedExports === true) return exportName; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		let idx = this.usedExports.indexOf(exportName); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (idx < 0) return false; | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Mangle export name if possible
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.isProvided(exportName)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (this.buildMeta.exportsType === "namespace") { | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:20 +08:00
										 |  |  | 				return Template.numberToIdentifer(idx); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if ( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				this.buildMeta.exportsType === "named" && | 
					
						
							|  |  |  | 				!this.usedExports.includes("default") | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:20 +08:00
										 |  |  | 				return Template.numberToIdentifer(idx); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		return exportName; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	isProvided(exportName) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!Array.isArray(this.buildMeta.providedExports)) return null; | 
					
						
							| 
									
										
										
										
											2018-01-12 00:58:39 +08:00
										 |  |  | 		return this.buildMeta.providedExports.includes(exportName); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	toString() { | 
					
						
							|  |  |  | 		return `Module[${this.id || this.debugId}]`; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	needRebuild(fileTimestamps, contextTimestamps) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash used to track dependencies | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		hash.update(`${this.id}`); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		hash.update(JSON.stringify(this.usedExports)); | 
					
						
							|  |  |  | 		super.updateHash(hash); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 13:57:21 +08:00
										 |  |  | 	sortItems(sortChunks) { | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		super.sortItems(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (sortChunks) this._chunks.sort(); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.reasons.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (a.module === b.module) return 0; | 
					
						
							|  |  |  | 			if (!a.module) return -1; | 
					
						
							|  |  |  | 			if (!b.module) return 1; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			return sortById(a.module, b.module); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (Array.isArray(this.usedExports)) { | 
					
						
							| 
									
										
										
										
											2017-06-01 20:11:04 +08:00
										 |  |  | 			this.usedExports.sort(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unbuild() { | 
					
						
							| 
									
										
										
										
											2017-12-12 23:44:12 +08:00
										 |  |  | 		this.dependencies.length = 0; | 
					
						
							|  |  |  | 		this.blocks.length = 0; | 
					
						
							|  |  |  | 		this.variables.length = 0; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildMeta = undefined; | 
					
						
							|  |  |  | 		this.buildInfo = undefined; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 		this.disconnect(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	get arguments() { | 
					
						
							|  |  |  | 		throw new Error("Module.arguments was removed, there is no replacement."); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	set arguments(value) { | 
					
						
							|  |  |  | 		throw new Error("Module.arguments was removed, there is no replacement."); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							|  |  |  | Object.defineProperty(Module.prototype, "forEachChunk", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 	value: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @param {function(any, any, Set<any>): void} fn callback function | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 * @this {Module} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function(fn) { | 
					
						
							|  |  |  | 			this._chunks.forEach(fn); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead" | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 5
 | 
					
						
							|  |  |  | Object.defineProperty(Module.prototype, "mapChunks", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 	value: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @param {function(any, any): void} fn Mapper function | 
					
						
							|  |  |  | 		 * @returns {Array<TODO>} Array of chunks mapped | 
					
						
							|  |  |  | 		 * @this {Module} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function(fn) { | 
					
						
							|  |  |  | 			return Array.from(this._chunks, fn); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead" | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | Object.defineProperty(Module.prototype, "entry", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							|  |  |  | 	get() { | 
					
						
							|  |  |  | 		throw new Error("Module.entry was removed. Use Chunk.entryModule"); | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set() { | 
					
						
							|  |  |  | 		throw new Error("Module.entry was removed. Use Chunk.entryModule"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-04-19 04:30:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | Object.defineProperty(Module.prototype, "meta", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 	get: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 * @this {Module} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function() { | 
					
						
							|  |  |  | 			return this.buildMeta; | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Module.meta was renamed to Module.buildMeta" | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	set: util.deprecate( | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @deprecated | 
					
						
							|  |  |  | 		 * @param {TODO} value Value | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 * @this {Module} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		function(value) { | 
					
						
							|  |  |  | 			this.buildMeta = value; | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"Module.meta was renamed to Module.buildMeta" | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 22:37:23 +08:00
										 |  |  | /** @type {function(): string} */ | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.identifier = null; | 
					
						
							| 
									
										
										
										
											2018-06-06 22:37:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @type {function(RequestShortener): string} */ | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.readableIdentifier = null; | 
					
						
							| 
									
										
										
										
											2018-06-06 22:37:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.build = null; | 
					
						
							|  |  |  | Module.prototype.source = null; | 
					
						
							|  |  |  | Module.prototype.size = null; | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | Module.prototype.nameForCondition = null; | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | /** @type {null | function(Chunk): boolean} */ | 
					
						
							|  |  |  | Module.prototype.chunkCondition = null; | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | Module.prototype.updateCacheModule = null; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:22:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = Module; |