| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | const DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup")} ChunkGroup */ | 
					
						
							|  |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-06-25 16:43:59 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							| 
									
										
										
										
											2018-06-25 22:01:57 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash */ | 
					
						
							| 
									
										
										
										
											2018-05-15 18:20:17 +08:00
										 |  |  | /** @typedef {TODO} GroupOptions */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | module.exports = class AsyncDependenciesBlock extends DependenciesBlock { | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {GroupOptions} groupOptions options for the group | 
					
						
							|  |  |  | 	 * @param {Module} module the Module object | 
					
						
							| 
									
										
										
										
											2018-05-07 13:29:26 +08:00
										 |  |  | 	 * @param {DependencyLocation=} loc the line of code | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 * @param {TODO=} request the request | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 	constructor(groupOptions, module, loc, request) { | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		if (typeof groupOptions === "string") { | 
					
						
							|  |  |  | 			groupOptions = { name: groupOptions }; | 
					
						
							|  |  |  | 		} else if (!groupOptions) { | 
					
						
							|  |  |  | 			groupOptions = { name: undefined }; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.groupOptions = groupOptions; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {ChunkGroup=} */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.chunkGroup = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		this.module = module; | 
					
						
							|  |  |  | 		this.loc = loc; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.request = request; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {DependenciesBlock} */ | 
					
						
							|  |  |  | 		this.parent = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-09 22:09:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} The name of the chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 	get chunkName() { | 
					
						
							|  |  |  | 		return this.groupOptions.name; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} value The new chunk name | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 	set chunkName(value) { | 
					
						
							|  |  |  | 		this.groupOptions.name = value; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-23 23:25:38 +08:00
										 |  |  | 	 * @param {Hash} hash the hash used to track dependencies | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		hash.update(JSON.stringify(this.groupOptions)); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		hash.update( | 
					
						
							|  |  |  | 			(this.chunkGroup && | 
					
						
							|  |  |  | 				this.chunkGroup.chunks | 
					
						
							|  |  |  | 					.map(chunk => { | 
					
						
							|  |  |  | 						return chunk.id !== null ? chunk.id : ""; | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 					.join(",")) || | 
					
						
							|  |  |  | 				"" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super.updateHash(hash); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 	disconnect() { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.chunkGroup = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super.disconnect(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 	unseal() { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.chunkGroup = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super.unseal(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	 * Sorts items in this module | 
					
						
							|  |  |  | 	 * @param {boolean=} sortChunks sort the chunks too | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	sortItems(sortChunks) { | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super.sortItems(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-26 08:02:33 +08:00
										 |  |  | }; |