| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_AUTO, | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_DYNAMIC, | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_ESM | 
					
						
							|  |  |  | } = require("./ModuleTypeConstants"); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | const ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							|  |  |  | const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +08:00
										 |  |  | /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */ | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | /** @typedef {import("./javascript/JavascriptParser").Range} Range */ | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | const PLUGIN_NAME = "ExportsInfoApiPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | class ExportsInfoApiPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 			PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					ExportsInfoDependency, | 
					
						
							|  |  |  | 					new ExportsInfoDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 				 * @returns {void} | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				const handler = (parser) => { | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 					parser.hooks.expressionMemberChain | 
					
						
							|  |  |  | 						.for("__webpack_exports_info__") | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 						.tap(PLUGIN_NAME, (expr, members) => { | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 							const dep = | 
					
						
							|  |  |  | 								members.length >= 2 | 
					
						
							|  |  |  | 									? new ExportsInfoDependency( | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 											/** @type {Range} */ (expr.range), | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 											members.slice(0, -1), | 
					
						
							|  |  |  | 											members[members.length - 1] | 
					
						
							| 
									
										
										
										
											2024-01-14 09:41:34 +08:00
										 |  |  | 										) | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 									: new ExportsInfoDependency( | 
					
						
							|  |  |  | 											/** @type {Range} */ (expr.range), | 
					
						
							|  |  |  | 											null, | 
					
						
							|  |  |  | 											members[0] | 
					
						
							| 
									
										
										
										
											2024-01-14 09:41:34 +08:00
										 |  |  | 										); | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 							dep.loc = /** @type {DependencyLocation} */ (expr.loc); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 							parser.state.module.addDependency(dep); | 
					
						
							|  |  |  | 							return true; | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					parser.hooks.expression | 
					
						
							|  |  |  | 						.for("__webpack_exports_info__") | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						.tap(PLUGIN_NAME, (expr) => { | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 							const dep = new ConstDependency( | 
					
						
							|  |  |  | 								"true", | 
					
						
							|  |  |  | 								/** @type {Range} */ (expr.range) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							dep.loc = /** @type {DependencyLocation} */ (expr.loc); | 
					
						
							| 
									
										
										
										
											2019-10-30 13:40:40 +08:00
										 |  |  | 							parser.state.module.addPresentationalDependency(dep); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 							return true; | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_AUTO) | 
					
						
							|  |  |  | 					.tap(PLUGIN_NAME, handler); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC) | 
					
						
							|  |  |  | 					.tap(PLUGIN_NAME, handler); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_ESM) | 
					
						
							|  |  |  | 					.tap(PLUGIN_NAME, handler); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ExportsInfoApiPlugin; |