| 
									
										
										
										
											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-11 17:51:58 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | const Dependency = require("../Dependency"); | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | const DependencyTemplate = require("../DependencyTemplate"); | 
					
						
							| 
									
										
										
										
											2024-02-28 23:08:34 +08:00
										 |  |  | const RawModule = require("../RawModule"); | 
					
						
							| 
									
										
										
										
											2021-03-11 22:04:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 22:43:34 +08:00
										 |  |  | /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */ | 
					
						
							| 
									
										
										
										
											2021-03-11 22:04:53 +08:00
										 |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							| 
									
										
										
										
											2024-06-11 00:21:03 +08:00
										 |  |  | /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */ | 
					
						
							| 
									
										
										
										
											2023-04-12 03:22:51 +08:00
										 |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ | 
					
						
							|  |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ | 
					
						
							| 
									
										
										
										
											2021-03-11 22:04:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | class ModuleDependency extends Dependency { | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} request request path which needs resolving | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | 	constructor(request) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 		this.request = request; | 
					
						
							|  |  |  | 		this.userRequest = request; | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | 		this.range = undefined; | 
					
						
							| 
									
										
										
										
											2024-03-15 23:11:02 +08:00
										 |  |  | 		// TODO move it to subclasses and rename
 | 
					
						
							| 
									
										
										
										
											2021-07-17 04:16:06 +08:00
										 |  |  | 		// assertions must be serialized by subclasses that use it
 | 
					
						
							| 
									
										
										
										
											2024-06-11 00:21:03 +08:00
										 |  |  | 		/** @type {ImportAttributes | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-07-17 04:16:06 +08:00
										 |  |  | 		this.assertions = undefined; | 
					
						
							| 
									
										
										
										
											2022-03-28 23:51:48 +08:00
										 |  |  | 		this._context = undefined; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string | undefined} a request context | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getContext() { | 
					
						
							|  |  |  | 		return this._context; | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 15:33:48 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier to merge equal requests | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 	getResourceIdentifier() { | 
					
						
							| 
									
										
										
										
											2022-03-28 23:51:48 +08:00
										 |  |  | 		let str = `context${this._context || ""}|module${this.request}`; | 
					
						
							| 
									
										
										
										
											2021-07-17 04:16:06 +08:00
										 |  |  | 		if (this.assertions !== undefined) { | 
					
						
							|  |  |  | 			str += JSON.stringify(this.assertions); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return str; | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 22:43:34 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	couldAffectReferencingModule() { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 22:04:53 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} context context directory | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | 	 * @returns {Module | null} a module | 
					
						
							| 
									
										
										
										
											2021-03-11 22:04:53 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	createIgnoredModule(context) { | 
					
						
							|  |  |  | 		return new RawModule( | 
					
						
							|  |  |  | 			"/* (ignored) */", | 
					
						
							|  |  |  | 			`ignored|${context}|${this.request}`, | 
					
						
							|  |  |  | 			`${this.request} (ignored)` | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-12 03:22:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectSerializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 		write(this.request); | 
					
						
							|  |  |  | 		write(this.userRequest); | 
					
						
							| 
									
										
										
										
											2022-03-28 23:51:48 +08:00
										 |  |  | 		write(this._context); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		write(this.range); | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-12 03:22:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectDeserializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		this.request = read(); | 
					
						
							|  |  |  | 		this.userRequest = read(); | 
					
						
							| 
									
										
										
										
											2022-03-28 23:51:48 +08:00
										 |  |  | 		this._context = read(); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		this.range = read(); | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | ModuleDependency.Template = DependencyTemplate; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 12:02:55 +08:00
										 |  |  | module.exports = ModuleDependency; |