| 
									
										
										
										
											2015-01-13 00:45:30 +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-05 00:21:57 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | const ConcatenationScope = require("../ConcatenationScope"); | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2023-05-05 11:41:15 +08:00
										 |  |  | const propertyAccess = require("../util/propertyAccess"); | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | const HarmonyExportInitFragment = require("./HarmonyExportInitFragment"); | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | const NullDependency = require("./NullDependency"); | 
					
						
							| 
									
										
										
										
											2015-01-13 00:45:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("../Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2018-07-25 15:33:48 +08:00
										 |  |  | /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */ | 
					
						
							| 
									
										
										
										
											2018-07-18 01:38:42 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ | 
					
						
							| 
									
										
										
										
											2018-07-17 22:34:36 +08:00
										 |  |  | /** @typedef {import("../ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2020-10-05 22:57:31 +08:00
										 |  |  | /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */ | 
					
						
							| 
									
										
										
										
											2023-05-22 04:31:30 +08:00
										 |  |  | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ | 
					
						
							| 
									
										
										
										
											2023-04-12 03:22:51 +08:00
										 |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ | 
					
						
							|  |  |  | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | class HarmonyExportExpressionDependency extends NullDependency { | 
					
						
							| 
									
										
										
										
											2023-05-22 04:31:30 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Range} range range | 
					
						
							|  |  |  | 	 * @param {Range} rangeStatement range statement | 
					
						
							|  |  |  | 	 * @param {string} prefix prefix | 
					
						
							| 
									
										
										
										
											2023-05-22 06:28:57 +08:00
										 |  |  | 	 * @param {string | { range: Range, prefix: string, suffix: string }} [declarationId] declaration id | 
					
						
							| 
									
										
										
										
											2023-05-22 04:31:30 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 	constructor(range, rangeStatement, prefix, declarationId) { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 		super(); | 
					
						
							|  |  |  | 		this.range = range; | 
					
						
							|  |  |  | 		this.rangeStatement = rangeStatement; | 
					
						
							| 
									
										
										
										
											2018-09-17 20:58:55 +08:00
										 |  |  | 		this.prefix = prefix; | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 		this.declarationId = declarationId; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get type() { | 
					
						
							|  |  |  | 		return "harmony export expression"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 15:33:48 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Returns the exported names | 
					
						
							| 
									
										
										
										
											2018-07-17 22:34:36 +08:00
										 |  |  | 	 * @param {ModuleGraph} moduleGraph module graph | 
					
						
							| 
									
										
										
										
											2018-07-25 15:33:48 +08:00
										 |  |  | 	 * @returns {ExportsSpec | undefined} export names | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-17 22:34:36 +08:00
										 |  |  | 	getExports(moduleGraph) { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 		return { | 
					
						
							| 
									
										
										
										
											2018-04-04 19:42:37 +08:00
										 |  |  | 			exports: ["default"], | 
					
						
							| 
									
										
										
										
											2021-04-07 03:14:54 +08:00
										 |  |  | 			priority: 1, | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 			terminalBinding: true, | 
					
						
							| 
									
										
										
										
											2018-04-04 19:42:37 +08:00
										 |  |  | 			dependencies: undefined | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-05 22:57:31 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							|  |  |  | 	 * @returns {ConnectionState} how this dependency connects the module to referencing modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleEvaluationSideEffectsState(moduleGraph) { | 
					
						
							|  |  |  | 		// The expression/declaration is already covered by SideEffectsFlagPlugin
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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.range); | 
					
						
							|  |  |  | 		write(this.rangeStatement); | 
					
						
							|  |  |  | 		write(this.prefix); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 		write(this.declarationId); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		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.range = read(); | 
					
						
							|  |  |  | 		this.rangeStatement = read(); | 
					
						
							|  |  |  | 		this.prefix = read(); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 		this.declarationId = read(); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-13 00:45:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | makeSerializable( | 
					
						
							|  |  |  | 	HarmonyExportExpressionDependency, | 
					
						
							|  |  |  | 	"webpack/lib/dependencies/HarmonyExportExpressionDependency" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 17:52:55 +08:00
										 |  |  | HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate extends ( | 
					
						
							|  |  |  | 	NullDependency.Template | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +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-23 23:33:29 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	apply( | 
					
						
							|  |  |  | 		dependency, | 
					
						
							|  |  |  | 		source, | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			module, | 
					
						
							|  |  |  | 			moduleGraph, | 
					
						
							|  |  |  | 			runtimeTemplate, | 
					
						
							|  |  |  | 			runtimeRequirements, | 
					
						
							|  |  |  | 			initFragments, | 
					
						
							| 
									
										
										
										
											2020-09-11 15:27:03 +08:00
										 |  |  | 			runtime, | 
					
						
							|  |  |  | 			concatenationScope | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2018-07-23 23:33:29 +08:00
										 |  |  | 		const dep = /** @type {HarmonyExportExpressionDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 		const { declarationId } = dep; | 
					
						
							|  |  |  | 		const exportsName = module.exportsArgument; | 
					
						
							|  |  |  | 		if (declarationId) { | 
					
						
							|  |  |  | 			let name; | 
					
						
							|  |  |  | 			if (typeof declarationId === "string") { | 
					
						
							|  |  |  | 				name = declarationId; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | 				name = ConcatenationScope.DEFAULT_EXPORT; | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 				source.replace( | 
					
						
							|  |  |  | 					declarationId.range[0], | 
					
						
							|  |  |  | 					declarationId.range[1] - 1, | 
					
						
							|  |  |  | 					`${declarationId.prefix}${name}${declarationId.suffix}` | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 16:02:55 +08:00
										 |  |  | 			if (concatenationScope) { | 
					
						
							|  |  |  | 				concatenationScope.registerExport("default", name); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const used = moduleGraph | 
					
						
							|  |  |  | 					.getExportsInfo(module) | 
					
						
							|  |  |  | 					.getUsedName("default", runtime); | 
					
						
							|  |  |  | 				if (used) { | 
					
						
							|  |  |  | 					const map = new Map(); | 
					
						
							|  |  |  | 					map.set(used, `/* export default binding */ ${name}`); | 
					
						
							|  |  |  | 					initFragments.push(new HarmonyExportInitFragment(exportsName, map)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 20:58:55 +08:00
										 |  |  | 			source.replace( | 
					
						
							|  |  |  | 				dep.rangeStatement[0], | 
					
						
							|  |  |  | 				dep.range[0] - 1, | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 				`/* harmony default export */ ${dep.prefix}` | 
					
						
							| 
									
										
										
										
											2018-09-17 20:58:55 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2023-05-22 06:28:57 +08:00
										 |  |  | 			/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 			let content; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | 			const name = ConcatenationScope.DEFAULT_EXPORT; | 
					
						
							| 
									
										
										
										
											2020-09-11 16:02:55 +08:00
										 |  |  | 			if (runtimeTemplate.supportsConst()) { | 
					
						
							|  |  |  | 				content = `/* harmony default export */ const ${name} = `; | 
					
						
							|  |  |  | 				if (concatenationScope) { | 
					
						
							|  |  |  | 					concatenationScope.registerExport("default", name); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					const used = moduleGraph | 
					
						
							|  |  |  | 						.getExportsInfo(module) | 
					
						
							|  |  |  | 						.getUsedName("default", runtime); | 
					
						
							|  |  |  | 					if (used) { | 
					
						
							| 
									
										
										
										
											2020-09-11 15:27:03 +08:00
										 |  |  | 						runtimeRequirements.add(RuntimeGlobals.exports); | 
					
						
							|  |  |  | 						const map = new Map(); | 
					
						
							|  |  |  | 						map.set(used, name); | 
					
						
							|  |  |  | 						initFragments.push(new HarmonyExportInitFragment(exportsName, map)); | 
					
						
							| 
									
										
										
										
											2020-09-11 16:02:55 +08:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | 						content = `/* unused harmony default export */ var ${name} = `; | 
					
						
							| 
									
										
										
										
											2020-09-11 15:27:03 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-09-11 16:02:55 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else if (concatenationScope) { | 
					
						
							|  |  |  | 				content = `/* harmony default export */ var ${name} = `; | 
					
						
							|  |  |  | 				concatenationScope.registerExport("default", name); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const used = moduleGraph | 
					
						
							|  |  |  | 					.getExportsInfo(module) | 
					
						
							|  |  |  | 					.getUsedName("default", runtime); | 
					
						
							|  |  |  | 				if (used) { | 
					
						
							| 
									
										
										
										
											2020-09-11 15:27:03 +08:00
										 |  |  | 					runtimeRequirements.add(RuntimeGlobals.exports); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 					// This is a little bit incorrect as TDZ is not correct, but we can't use const.
 | 
					
						
							| 
									
										
										
										
											2023-05-05 11:41:15 +08:00
										 |  |  | 					content = `/* harmony default export */ ${exportsName}${propertyAccess( | 
					
						
							| 
									
										
										
										
											2023-05-18 02:47:54 +08:00
										 |  |  | 						typeof used === "string" ? [used] : used | 
					
						
							| 
									
										
										
										
											2023-05-05 11:41:15 +08:00
										 |  |  | 					)} = `;
 | 
					
						
							| 
									
										
										
										
											2020-09-11 15:27:03 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | 					content = `/* unused harmony default export */ var ${name} = `; | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 			if (dep.range) { | 
					
						
							|  |  |  | 				source.replace( | 
					
						
							|  |  |  | 					dep.rangeStatement[0], | 
					
						
							|  |  |  | 					dep.range[0] - 1, | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 					`${content}(${dep.prefix}` | 
					
						
							| 
									
										
										
										
											2020-05-13 01:09:56 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 				source.replace(dep.range[1], dep.rangeStatement[1] - 0.5, ");"); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-15 05:41:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:21:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = HarmonyExportExpressionDependency; |