| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const InitFragment = require("../InitFragment"); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | const makeSerializable = require("../util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | const NullDependency = require("./NullDependency"); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | /** @typedef {import("../Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2018-07-18 01:38:42 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2018-07-17 22:42:05 +08:00
										 |  |  | /** @typedef {import("../ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | /** @typedef {import("../util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | class ModuleDecoratorDependency extends NullDependency { | 
					
						
							| 
									
										
										
										
											2018-07-30 19:23:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | 	 * @param {string} decorator the decorator requirement | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(decorator) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 		this.decorator = decorator; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a display name for the type of dependency | 
					
						
							| 
									
										
										
										
											2018-07-30 19:23:59 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | 	get type() { | 
					
						
							|  |  |  | 		return "module decorator"; | 
					
						
							| 
									
										
										
										
											2018-07-30 19:23:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-12-07 05:13:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 05:54:26 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier to merge equal requests | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getResourceIdentifier() { | 
					
						
							|  |  |  | 		return `self`; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Returns list of exports referenced by this dependency | 
					
						
							|  |  |  | 	 * @param {ModuleGraph} moduleGraph module graph | 
					
						
							|  |  |  | 	 * @returns {string[][]} referenced exports | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getReferencedExports(moduleGraph) { | 
					
						
							|  |  |  | 		return [[]]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 05:13:21 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Update the hash | 
					
						
							|  |  |  | 	 * @param {Hash} hash hash to be updated | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	updateHash(hash, chunkGraph) { | 
					
						
							|  |  |  | 		super.updateHash(hash, chunkGraph); | 
					
						
							|  |  |  | 		hash.update(this.decorator); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 		write(this.decorator); | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		this.decorator = read(); | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | makeSerializable( | 
					
						
							|  |  |  | 	ModuleDecoratorDependency, | 
					
						
							|  |  |  | 	"webpack/lib/dependencies/ModuleDecoratorDependency" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | ModuleDecoratorDependency.Template = class ModuleDecoratorDependencyTemplate extends NullDependency.Template { | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency for which the template should be applied | 
					
						
							|  |  |  | 	 * @param {ReplaceSource} source the current replace source which can be modified | 
					
						
							| 
									
										
										
										
											2018-07-18 01:38:42 +08:00
										 |  |  | 	 * @param {DependencyTemplateContext} templateContext the context object | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	apply( | 
					
						
							|  |  |  | 		dependency, | 
					
						
							|  |  |  | 		source, | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | 		{ module, chunkGraph, initFragments, runtimeRequirements } | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 		const dep = /** @type {ModuleDecoratorDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2019-12-04 21:12:16 +08:00
										 |  |  | 		runtimeRequirements.add(RuntimeGlobals.moduleLoaded); | 
					
						
							|  |  |  | 		runtimeRequirements.add(RuntimeGlobals.moduleId); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 		runtimeRequirements.add(RuntimeGlobals.module); | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | 		runtimeRequirements.add(dep.decorator); | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 		initFragments.push( | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 			new InitFragment( | 
					
						
							| 
									
										
										
										
											2019-06-13 16:51:12 +08:00
										 |  |  | 				`/* module decorator */ ${module.moduleArgument} = ${dep.decorator}(${module.moduleArgument});\n`, | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 				InitFragment.STAGE_PROVIDES, | 
					
						
							|  |  |  | 				0, | 
					
						
							| 
									
										
										
										
											2018-12-07 04:45:44 +08:00
										 |  |  | 				`module decorator ${chunkGraph.getModuleId(module)}` | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 			) | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:33:33 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ModuleDecoratorDependency; |