| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { RawSource, ReplaceSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class DependenciesBlockVariable { | 
					
						
							|  |  |  | 	constructor(name, expression, dependencies) { | 
					
						
							|  |  |  | 		this.name = name; | 
					
						
							|  |  |  | 		this.expression = expression; | 
					
						
							|  |  |  | 		this.dependencies = dependencies || []; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							|  |  |  | 		hash.update(this.name); | 
					
						
							|  |  |  | 		hash.update(this.expression); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const d of this.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 			d.updateHash(hash); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 	expressionSource(dependencyTemplates, runtimeTemplate) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 		const source = new ReplaceSource(new RawSource(this.expression)); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const dep of this.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 			const template = dependencyTemplates.get(dep.constructor); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!template) | 
					
						
							|  |  |  | 				throw new Error(`No template for dependency: ${dep.constructor.name}`); | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 			template.apply(dep, source, runtimeTemplate, dependencyTemplates); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 		return source; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 	disconnect() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const d of this.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 			d.disconnect(); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-01 05:28:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 	hasDependencies(filter) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (filter) { | 
					
						
							|  |  |  | 			if (this.dependencies.some(filter)) return true; | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.dependencies.length > 0) return true; | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = DependenciesBlockVariable; |