| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | const DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {import("./ChunkGroup")} ChunkGroup | 
					
						
							|  |  |  |  * @typedef {import("./Module")} Module | 
					
						
							|  |  |  |  * @typedef {import("crypto").Hash} Hash | 
					
						
							|  |  |  |  * @typedef {TODO} GroupOptions | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} SourcePosition | 
					
						
							|  |  |  |  * @property {number} line | 
					
						
							|  |  |  |  * @property {number} column | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} SourceLocation | 
					
						
							|  |  |  |  * @property {number} index | 
					
						
							|  |  |  |  * @property {SourcePosition} start | 
					
						
							|  |  |  |  * @property {SourcePosition} end | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 	 * @param {SourceLocation=} loc the line of code | 
					
						
							|  |  |  | 	 * @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
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {never} this throws and should never be called | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get chunks() { | 
					
						
							|  |  |  | 		throw new Error("Moved to AsyncDependenciesBlock.chunkGroup"); | 
					
						
							| 
									
										
										
										
											2017-01-09 22:09:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {never} value setter value | 
					
						
							|  |  |  | 	 * @returns {never} this is going to throw therefore we should throw type | 
					
						
							|  |  |  | 	 * assertions by returning never | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	set chunks(value) { | 
					
						
							|  |  |  | 		throw new Error("Moved to AsyncDependenciesBlock.chunkGroup"); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash used to track block changes, from "crypto" module | 
					
						
							|  |  |  | 	 * @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
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 	sortItems() { | 
					
						
							|  |  |  | 		super.sortItems(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-26 08:02:33 +08:00
										 |  |  | }; |