| 
									
										
										
										
											2017-05-10 19:15:14 +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-05-10 19:15:14 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 07:47:01 +08:00
										 |  |  | const eslintScope = require("eslint-scope"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { ConcatSource, ReplaceSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const DependencyTemplate = require("../DependencyTemplate"); | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | const InitFragment = require("../InitFragment"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const JavascriptParser = require("../JavascriptParser"); | 
					
						
							|  |  |  | const Module = require("../Module"); | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const Template = require("../Template"); | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | const DependencyReference = require("../dependencies/DependencyReference"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency"); | 
					
						
							|  |  |  | const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency"); | 
					
						
							|  |  |  | const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency"); | 
					
						
							|  |  |  | const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency"); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency"); | 
					
						
							| 
									
										
										
										
											2017-08-08 15:32:43 +08:00
										 |  |  | const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency"); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency"); | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | const createHash = require("../util/createHash"); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2018-06-08 16:34:38 +08:00
										 |  |  | /** @typedef {import("../Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("../Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2018-07-18 01:38:42 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | /** @typedef {import("../DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | /** @typedef {import("../Module").SourceContext} SourceContext */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | /** @typedef {import("../ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("../RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | /** @typedef {import("../WebpackError")} WebpackError */ | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | /** @typedef {import("../util/createHash").Hash} Hash */ | 
					
						
							| 
									
										
										
										
											2018-06-08 16:34:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo } ModuleInfo */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ConcatenatedModuleInfo | 
					
						
							|  |  |  |  * @property {"concatenated"} type | 
					
						
							|  |  |  |  * @property {Module} module | 
					
						
							|  |  |  |  * @property {TODO} index | 
					
						
							|  |  |  |  * @property {TODO} ast | 
					
						
							|  |  |  |  * @property {TODO} internalSource | 
					
						
							|  |  |  |  * @property {TODO} source | 
					
						
							|  |  |  |  * @property {TODO} globalScope | 
					
						
							|  |  |  |  * @property {TODO} moduleScope | 
					
						
							|  |  |  |  * @property {TODO} internalNames | 
					
						
							|  |  |  |  * @property {TODO} globalExports | 
					
						
							|  |  |  |  * @property {TODO} exportMap | 
					
						
							|  |  |  |  * @property {TODO} reexportMap | 
					
						
							|  |  |  |  * @property {TODO} hasNamespaceObject | 
					
						
							|  |  |  |  * @property {TODO} namespaceObjectSource | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ExternalModuleInfo | 
					
						
							|  |  |  |  * @property {"external"} type | 
					
						
							|  |  |  |  * @property {Module} module | 
					
						
							|  |  |  |  * @property {TODO} index | 
					
						
							|  |  |  |  * @property {TODO} name | 
					
						
							|  |  |  |  * @property {TODO} interopNamespaceObjectUsed | 
					
						
							|  |  |  |  * @property {TODO} interopNamespaceObjectName | 
					
						
							|  |  |  |  * @property {TODO} interopDefaultAccessUsed | 
					
						
							|  |  |  |  * @property {TODO} interopDefaultAccessName | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 22:02:17 +08:00
										 |  |  | const RESERVED_NAMES = [ | 
					
						
							|  |  |  | 	// internal name
 | 
					
						
							|  |  |  | 	"__WEBPACK_MODULE_DEFAULT_EXPORT__", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// keywords
 | 
					
						
							|  |  |  | 	"abstract,arguments,async,await,boolean,break,byte,case,catch,char,class,const,continue", | 
					
						
							|  |  |  | 	"debugger,default,delete,do,double,else,enum,eval,export,extends,false,final,finally,float", | 
					
						
							|  |  |  | 	"for,function,goto,if,implements,import,in,instanceof,int,interface,let,long,native,new,null", | 
					
						
							|  |  |  | 	"package,private,protected,public,return,short,static,super,switch,synchronized,this,throw", | 
					
						
							|  |  |  | 	"throws,transient,true,try,typeof,var,void,volatile,while,with,yield", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// commonjs
 | 
					
						
							|  |  |  | 	"module,__dirname,__filename,exports", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// js globals
 | 
					
						
							|  |  |  | 	"Array,Date,eval,function,hasOwnProperty,Infinity,isFinite,isNaN,isPrototypeOf,length,Math", | 
					
						
							|  |  |  | 	"NaN,name,Number,Object,prototype,String,toString,undefined,valueOf", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// browser globals
 | 
					
						
							|  |  |  | 	"alert,all,anchor,anchors,area,assign,blur,button,checkbox,clearInterval,clearTimeout", | 
					
						
							|  |  |  | 	"clientInformation,close,closed,confirm,constructor,crypto,decodeURI,decodeURIComponent", | 
					
						
							|  |  |  | 	"defaultStatus,document,element,elements,embed,embeds,encodeURI,encodeURIComponent,escape", | 
					
						
							|  |  |  | 	"event,fileUpload,focus,form,forms,frame,innerHeight,innerWidth,layer,layers,link,location", | 
					
						
							|  |  |  | 	"mimeTypes,navigate,navigator,frames,frameRate,hidden,history,image,images,offscreenBuffering", | 
					
						
							|  |  |  | 	"open,opener,option,outerHeight,outerWidth,packages,pageXOffset,pageYOffset,parent,parseFloat", | 
					
						
							|  |  |  | 	"parseInt,password,pkcs11,plugin,prompt,propertyIsEnum,radio,reset,screenX,screenY,scroll", | 
					
						
							|  |  |  | 	"secure,select,self,setInterval,setTimeout,status,submit,taint,text,textarea,top,unescape", | 
					
						
							|  |  |  | 	"untaint,window", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// window events
 | 
					
						
							|  |  |  | 	"onblur,onclick,onerror,onfocus,onkeydown,onkeypress,onkeyup,onmouseover,onload,onmouseup,onmousedown,onsubmit" | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 	.join(",") | 
					
						
							|  |  |  | 	.split(","); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 16:34:38 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ConcatenationEntry | 
					
						
							|  |  |  |  * @property {"concatenated" | "external"} type | 
					
						
							|  |  |  |  * @property {Module} module | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const ensureNsObjSource = ( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 	moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	info, | 
					
						
							|  |  |  | 	moduleToInfoMap, | 
					
						
							|  |  |  | 	requestShortener, | 
					
						
							|  |  |  | 	strictHarmonyModule | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	if (!info.hasNamespaceObject) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 		info.hasNamespaceObject = true; | 
					
						
							|  |  |  | 		const name = info.exportMap.get(true); | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 		const nsObj = [ | 
					
						
							|  |  |  | 			`var ${name} = {};`, | 
					
						
							|  |  |  | 			`${RuntimeGlobals.makeNamespaceObject}(${name});` | 
					
						
							|  |  |  | 		]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const exportName of info.module.buildMeta.providedExports) { | 
					
						
							|  |  |  | 			const finalName = getFinalName( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 				moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				info, | 
					
						
							|  |  |  | 				exportName, | 
					
						
							|  |  |  | 				moduleToInfoMap, | 
					
						
							|  |  |  | 				requestShortener, | 
					
						
							|  |  |  | 				false, | 
					
						
							|  |  |  | 				strictHarmonyModule | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			nsObj.push( | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 				`${RuntimeGlobals.definePropertyGetter}(${name}, ${JSON.stringify( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					exportName | 
					
						
							|  |  |  | 				)}, function() { return ${finalName}; });`
 | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		info.namespaceObjectSource = nsObj.join("\n") + "\n"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const getExternalImport = ( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 	moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	importedModule, | 
					
						
							|  |  |  | 	info, | 
					
						
							|  |  |  | 	exportName, | 
					
						
							|  |  |  | 	asCall, | 
					
						
							|  |  |  | 	strictHarmonyModule | 
					
						
							|  |  |  | ) => { | 
					
						
							| 
									
										
										
										
											2018-08-07 03:01:24 +08:00
										 |  |  | 	const used = importedModule.getUsedName(moduleGraph, exportName); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (!used) return "/* unused reexport */undefined"; | 
					
						
							|  |  |  | 	const comment = | 
					
						
							|  |  |  | 		used !== exportName ? ` ${Template.toNormalComment(exportName)}` : ""; | 
					
						
							|  |  |  | 	switch (importedModule.buildMeta.exportsType) { | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 		case "named": | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (exportName === "default") { | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 				return info.name; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (exportName === true) { | 
					
						
							| 
									
										
										
										
											2018-01-06 05:35:54 +08:00
										 |  |  | 				info.interopNamespaceObjectUsed = true; | 
					
						
							|  |  |  | 				return info.interopNamespaceObjectName; | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		case "namespace": | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (exportName === true) { | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 				return info.name; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (strictHarmonyModule) { | 
					
						
							|  |  |  | 				if (exportName === "default") { | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 					return info.name; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} else if (exportName === true) { | 
					
						
							| 
									
										
										
										
											2018-01-06 05:35:54 +08:00
										 |  |  | 					info.interopNamespaceObjectUsed = true; | 
					
						
							|  |  |  | 					return info.interopNamespaceObjectName; | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					return "/* non-default import from non-esm module */undefined"; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (exportName === "default") { | 
					
						
							| 
									
										
										
										
											2018-01-06 05:35:54 +08:00
										 |  |  | 					info.interopDefaultAccessUsed = true; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					return asCall | 
					
						
							|  |  |  | 						? `${info.interopDefaultAccessName}()` | 
					
						
							|  |  |  | 						: `${info.interopDefaultAccessName}.a`; | 
					
						
							|  |  |  | 				} else if (exportName === true) { | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 					return info.name; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-10 18:14:14 +08:00
										 |  |  | 	const reference = `${info.name}[${JSON.stringify(used)}${comment}]`; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (asCall) return `Object(${reference})`; | 
					
						
							| 
									
										
										
										
											2017-08-07 20:38:54 +08:00
										 |  |  | 	return reference; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const getFinalName = ( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 	moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	info, | 
					
						
							|  |  |  | 	exportName, | 
					
						
							|  |  |  | 	moduleToInfoMap, | 
					
						
							|  |  |  | 	requestShortener, | 
					
						
							|  |  |  | 	asCall, | 
					
						
							| 
									
										
										
										
											2018-06-20 05:19:28 +08:00
										 |  |  | 	strictHarmonyModule, | 
					
						
							|  |  |  | 	alreadyVisited = new Set() | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | ) => { | 
					
						
							|  |  |  | 	switch (info.type) { | 
					
						
							|  |  |  | 		case "concatenated": { | 
					
						
							|  |  |  | 			const directExport = info.exportMap.get(exportName); | 
					
						
							|  |  |  | 			if (directExport) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (exportName === true) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					ensureNsObjSource( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 						moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						info, | 
					
						
							|  |  |  | 						moduleToInfoMap, | 
					
						
							|  |  |  | 						requestShortener, | 
					
						
							|  |  |  | 						strictHarmonyModule | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-08-07 03:01:24 +08:00
										 |  |  | 				} else if (!info.module.isExportUsed(moduleGraph, exportName)) { | 
					
						
							| 
									
										
										
										
											2018-06-23 21:10:56 +08:00
										 |  |  | 					return "/* unused export */ undefined"; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-08-20 16:34:58 +08:00
										 |  |  | 				if (info.globalExports.has(directExport)) { | 
					
						
							|  |  |  | 					return directExport; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const name = info.internalNames.get(directExport); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!name) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						`The export "${directExport}" in "${info.module.readableIdentifier( | 
					
						
							|  |  |  | 							requestShortener | 
					
						
							|  |  |  | 						)}" has no internal name`
 | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return name; | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			const reexport = info.reexportMap.get(exportName); | 
					
						
							|  |  |  | 			if (reexport) { | 
					
						
							| 
									
										
										
										
											2018-06-20 05:19:28 +08:00
										 |  |  | 				if (alreadyVisited.has(reexport)) { | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						`Circular reexports ${Array.from( | 
					
						
							|  |  |  | 							alreadyVisited, | 
					
						
							|  |  |  | 							e => | 
					
						
							|  |  |  | 								`"${e.module.readableIdentifier(requestShortener)}".${ | 
					
						
							|  |  |  | 									e.exportName | 
					
						
							|  |  |  | 								}`
 | 
					
						
							|  |  |  | 						).join( | 
					
						
							|  |  |  | 							" --> " | 
					
						
							|  |  |  | 						)} -(circular)-> "${reexport.module.readableIdentifier( | 
					
						
							|  |  |  | 							requestShortener | 
					
						
							|  |  |  | 						)}".${reexport.exportName}`
 | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				alreadyVisited.add(reexport); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const refInfo = moduleToInfoMap.get(reexport.module); | 
					
						
							|  |  |  | 				if (refInfo) { | 
					
						
							|  |  |  | 					// module is in the concatenation
 | 
					
						
							|  |  |  | 					return getFinalName( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 						moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						refInfo, | 
					
						
							|  |  |  | 						reexport.exportName, | 
					
						
							|  |  |  | 						moduleToInfoMap, | 
					
						
							|  |  |  | 						requestShortener, | 
					
						
							|  |  |  | 						asCall, | 
					
						
							| 
									
										
										
										
											2018-06-20 05:19:28 +08:00
										 |  |  | 						strictHarmonyModule, | 
					
						
							|  |  |  | 						alreadyVisited | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			const problem = | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 				`Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier( | 
					
						
							|  |  |  | 					requestShortener | 
					
						
							|  |  |  | 				)}"` +
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				` (known exports: ${Array.from(info.exportMap.keys()) | 
					
						
							|  |  |  | 					.filter(name => name !== true) | 
					
						
							|  |  |  | 					.join(" ")}, ` +
 | 
					
						
							|  |  |  | 				`known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`; | 
					
						
							|  |  |  | 			return `${Template.toNormalComment(problem)} undefined`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case "external": { | 
					
						
							|  |  |  | 			const importedModule = info.module; | 
					
						
							|  |  |  | 			return getExternalImport( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 				moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				importedModule, | 
					
						
							|  |  |  | 				info, | 
					
						
							|  |  |  | 				exportName, | 
					
						
							|  |  |  | 				asCall, | 
					
						
							|  |  |  | 				strictHarmonyModule | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | const addScopeSymbols1 = (s, nameSet, scopeSet) => { | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 	let scope = s; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	while (scope) { | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 		if (scopeSet.has(scope)) break; | 
					
						
							|  |  |  | 		scopeSet.add(scope); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const variable of scope.variables) { | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 			nameSet.add(variable.name); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		scope = scope.upper; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const addScopeSymbols2 = (s, nameSet, scopeSet1, scopeSet2) => { | 
					
						
							|  |  |  | 	let scope = s; | 
					
						
							|  |  |  | 	while (scope) { | 
					
						
							|  |  |  | 		if (scopeSet1.has(scope)) break; | 
					
						
							|  |  |  | 		if (scopeSet2.has(scope)) break; | 
					
						
							|  |  |  | 		scopeSet1.add(scope); | 
					
						
							|  |  |  | 		for (const variable of scope.variables) { | 
					
						
							|  |  |  | 			nameSet.add(variable.name); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 		scope = scope.upper; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const getAllReferences = variable => { | 
					
						
							| 
									
										
										
										
											2017-06-06 17:18:34 +08:00
										 |  |  | 	let set = variable.references; | 
					
						
							|  |  |  | 	// Look for inner scope variables too (like in class Foo { t() { Foo } })
 | 
					
						
							|  |  |  | 	const identifiers = new Set(variable.identifiers); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for (const scope of variable.scope.childScopes) { | 
					
						
							|  |  |  | 		for (const innerVar of scope.variables) { | 
					
						
							|  |  |  | 			if (innerVar.identifiers.some(id => identifiers.has(id))) { | 
					
						
							| 
									
										
										
										
											2017-06-06 17:18:34 +08:00
										 |  |  | 				set = set.concat(innerVar.references); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return set; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-06-06 17:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const getPathInAst = (ast, node) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (ast === node) { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 		return []; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 	const nr = node.range; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	const enterNode = n => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!n) return undefined; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const r = n.range; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (r) { | 
					
						
							|  |  |  | 			if (r[0] <= nr[0] && r[1] >= nr[1]) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				const path = getPathInAst(n, node); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (path) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 					path.push(n); | 
					
						
							|  |  |  | 					return path; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return undefined; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 	var i; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (Array.isArray(ast)) { | 
					
						
							|  |  |  | 		for (i = 0; i < ast.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 			const enterResult = enterNode(ast[i]); | 
					
						
							| 
									
										
										
										
											2018-08-21 08:26:50 +08:00
										 |  |  | 			if (enterResult !== undefined) return enterResult; | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	} else if (ast && typeof ast === "object") { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 		const keys = Object.keys(ast); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (i = 0; i < keys.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 			const value = ast[keys[i]]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (Array.isArray(value)) { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 				const pathResult = getPathInAst(value, node); | 
					
						
							| 
									
										
										
										
											2018-08-21 08:26:50 +08:00
										 |  |  | 				if (pathResult !== undefined) return pathResult; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (value && typeof value === "object") { | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 				const enterResult = enterNode(value); | 
					
						
							| 
									
										
										
										
											2018-08-21 08:26:50 +08:00
										 |  |  | 				if (enterResult !== undefined) return enterResult; | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-06-13 19:38:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | const modulesWithInfoToMap = modulesWithInfo => { | 
					
						
							|  |  |  | 	const moduleToInfoMap = new Map(); | 
					
						
							|  |  |  | 	for (const m of modulesWithInfo) { | 
					
						
							|  |  |  | 		moduleToInfoMap.set(m.module, m); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return moduleToInfoMap; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | class ConcatenatedModule extends Module { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} rootModule the root module of the concatenation | 
					
						
							|  |  |  | 	 * @param {Set<Module>} modules all modules in the concantenation (including the root module) | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(rootModule, modules, compilation) { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 		super("javascript/esm", null); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 		const moduleGraph = compilation.moduleGraph; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		// Info from Factory
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.rootModule = rootModule; | 
					
						
							| 
									
										
										
										
											2018-06-26 21:27:44 +08:00
										 |  |  | 		this.factoryMeta = rootModule.factoryMeta; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Optimization
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		moduleGraph.setUsedExports(this, moduleGraph.getUsedExports(rootModule)); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		const modulesArray = Array.from(modules); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		// Info from Build
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildInfo = { | 
					
						
							|  |  |  | 			strict: true, | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			cacheable: modulesArray.every(m => m.buildInfo.cacheable), | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 			moduleArgument: rootModule.buildInfo.moduleArgument, | 
					
						
							|  |  |  | 			exportsArgument: rootModule.buildInfo.exportsArgument, | 
					
						
							|  |  |  | 			fileDependencies: new Set(), | 
					
						
							|  |  |  | 			contextDependencies: new Set(), | 
					
						
							|  |  |  | 			assets: undefined | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		this.buildMeta = rootModule.buildMeta; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Caching
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		this._numberOfConcatenatedModules = modules.size; | 
					
						
							| 
									
										
										
										
											2017-06-18 20:46:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		// Graph
 | 
					
						
							|  |  |  | 		const modulesSet = new Set(modules); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-18 20:46:06 +08:00
										 |  |  | 		this.dependencies = []; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-18 20:46:06 +08:00
										 |  |  | 		this.warnings = []; | 
					
						
							|  |  |  | 		this.errors = []; | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		this._orderedConcatenationList = ConcatenatedModule._createConcatenationList( | 
					
						
							|  |  |  | 			rootModule, | 
					
						
							|  |  |  | 			modulesSet, | 
					
						
							|  |  |  | 			compilation | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of this._orderedConcatenationList) { | 
					
						
							|  |  |  | 			if (info.type === "concatenated") { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				const m = info.module; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// populate dependencies
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const d of m.dependencies.filter( | 
					
						
							|  |  |  | 					dep => | 
					
						
							|  |  |  | 						!(dep instanceof HarmonyImportDependency) || | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 						!modulesSet.has(compilation.moduleGraph.getModule(dep)) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				)) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					this.dependencies.push(d); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				// populate file dependencies
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (m.buildInfo.fileDependencies) { | 
					
						
							|  |  |  | 					for (const file of m.buildInfo.fileDependencies) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 						this.buildInfo.fileDependencies.add(file); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				// populate context dependencies
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (m.buildInfo.contextDependencies) { | 
					
						
							|  |  |  | 					for (const context of m.buildInfo.contextDependencies) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 						this.buildInfo.contextDependencies.add(context); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				// populate warnings
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				for (const warning of m.warnings) { | 
					
						
							|  |  |  | 					this.warnings.push(warning); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				// populate errors
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				for (const error of m.errors) { | 
					
						
							|  |  |  | 					this.errors.push(error); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (m.buildInfo.assets) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					if (this.buildInfo.assets === undefined) { | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 						this.buildInfo.assets = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 					Object.assign(this.buildInfo.assets, m.buildInfo.assets); | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-18 20:46:06 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-23 00:14:39 +08:00
										 |  |  | 		this._identifier = this._createIdentifier(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 05:23:40 +08:00
										 |  |  | 	get modules() { | 
					
						
							| 
									
										
										
										
											2017-08-12 06:01:50 +08:00
										 |  |  | 		return this._orderedConcatenationList | 
					
						
							|  |  |  | 			.filter(info => info.type === "concatenated") | 
					
						
							|  |  |  | 			.map(info => info.module); | 
					
						
							| 
									
										
										
										
											2017-08-10 05:23:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a unique identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	identifier() { | 
					
						
							| 
									
										
										
										
											2017-11-23 00:14:39 +08:00
										 |  |  | 		return this._identifier; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener the request shortener | 
					
						
							|  |  |  | 	 * @returns {string} a user readable identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	readableIdentifier(requestShortener) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return ( | 
					
						
							|  |  |  | 			this.rootModule.readableIdentifier(requestShortener) + | 
					
						
							|  |  |  | 			` + ${this._numberOfConcatenatedModules - 1} modules` | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {LibIdentOptions} options options | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier for library inclusion | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	libIdent(options) { | 
					
						
							| 
									
										
										
										
											2017-06-05 20:01:19 +08:00
										 |  |  | 		return this.rootModule.libIdent(options); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string | null} absolute path which should be used for condition matching (usually the resource path) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	nameForCondition() { | 
					
						
							|  |  |  | 		return this.rootModule.nameForCondition(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} options TODO | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @param {TODO} resolver TODO | 
					
						
							|  |  |  | 	 * @param {TODO} fs the file system | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {function(WebpackError=): void} callback callback function | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	build(options, compilation, resolver, fs, callback) { | 
					
						
							|  |  |  | 		throw new Error("Cannot build this module. It should be already built."); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the estimated size of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	size() { | 
					
						
							|  |  |  | 		// Guess size from embedded modules
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 		return this._orderedConcatenationList.reduce((sum, info) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			switch (info.type) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				case "concatenated": | 
					
						
							|  |  |  | 					return sum + info.module.size(); | 
					
						
							|  |  |  | 				case "external": | 
					
						
							|  |  |  | 					return sum + 5; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return sum; | 
					
						
							|  |  |  | 		}, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 16:34:38 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	 * @private | 
					
						
							| 
									
										
										
										
											2018-06-08 16:34:38 +08:00
										 |  |  | 	 * @param {Module} rootModule the root of the concatenation | 
					
						
							|  |  |  | 	 * @param {Set<Module>} modulesSet a set of modules which should be concatenated | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation context | 
					
						
							|  |  |  | 	 * @returns {ConcatenationEntry[]} concatenation list | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	static _createConcatenationList(rootModule, modulesSet, compilation) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 		const list = []; | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 		const set = new Set(); | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Module} module a module | 
					
						
							|  |  |  | 		 * @returns {(function(): Module)[]} imported modules in order | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const getConcatenatedImports = module => { | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 			const references = module.dependencies | 
					
						
							| 
									
										
										
										
											2017-08-08 15:32:43 +08:00
										 |  |  | 				.filter(dep => dep instanceof HarmonyImportDependency) | 
					
						
							| 
									
										
										
										
											2018-07-23 03:01:05 +08:00
										 |  |  | 				.map(dep => compilation.getDependencyReference(module, dep)) | 
					
						
							|  |  |  | 				.filter(ref => ref !== null); | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 			DependencyReference.sort(references); | 
					
						
							|  |  |  | 			return references.map(ref => { | 
					
						
							| 
									
										
										
										
											2018-07-23 03:01:05 +08:00
										 |  |  | 				return () => ref.module; | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const enterModule = getModule => { | 
					
						
							| 
									
										
										
										
											2017-08-07 19:56:50 +08:00
										 |  |  | 			const module = getModule(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!module) return; | 
					
						
							|  |  |  | 			if (set.has(module)) return; | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 			set.add(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (modulesSet.has(module)) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				const imports = getConcatenatedImports(module); | 
					
						
							|  |  |  | 				imports.forEach(enterModule); | 
					
						
							|  |  |  | 				list.push({ | 
					
						
							|  |  |  | 					type: "concatenated", | 
					
						
							|  |  |  | 					module | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				list.push({ | 
					
						
							|  |  |  | 					type: "external", | 
					
						
							| 
									
										
										
										
											2017-08-07 19:56:50 +08:00
										 |  |  | 					get module() { | 
					
						
							|  |  |  | 						// We need to use a getter here, because the module in the dependency
 | 
					
						
							|  |  |  | 						// could be replaced by some other process (i. e. also replaced with a
 | 
					
						
							|  |  |  | 						// concatenated module)
 | 
					
						
							|  |  |  | 						return getModule(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 19:56:50 +08:00
										 |  |  | 		enterModule(() => rootModule); | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return list; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 00:14:39 +08:00
										 |  |  | 	_createIdentifier() { | 
					
						
							| 
									
										
										
										
											2017-11-23 23:57:07 +08:00
										 |  |  | 		let orderedConcatenationListIdentifiers = ""; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this._orderedConcatenationList.length; i++) { | 
					
						
							|  |  |  | 			if (this._orderedConcatenationList[i].type === "concatenated") { | 
					
						
							|  |  |  | 				orderedConcatenationListIdentifiers += this._orderedConcatenationList[ | 
					
						
							|  |  |  | 					i | 
					
						
							|  |  |  | 				].module.identifier(); | 
					
						
							| 
									
										
										
										
											2017-11-23 23:57:07 +08:00
										 |  |  | 				orderedConcatenationListIdentifiers += " "; | 
					
						
							| 
									
										
										
										
											2017-11-23 00:14:39 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-23 23:57:07 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-22 18:27:11 +08:00
										 |  |  | 		const hash = createHash("md4"); | 
					
						
							| 
									
										
										
										
											2017-11-23 00:14:39 +08:00
										 |  |  | 		hash.update(orderedConcatenationListIdentifiers); | 
					
						
							|  |  |  | 		return this.rootModule.identifier() + " " + hash.digest("hex"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-18 00:57:03 +08:00
										 |  |  | 	 * @param {SourceContext} sourceContext source context | 
					
						
							| 
									
										
										
										
											2018-07-11 19:05:13 +08:00
										 |  |  | 	 * @returns {Source} generated source | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	source({ dependencyTemplates, runtimeTemplate, moduleGraph, chunkGraph }) { | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 		const requestShortener = runtimeTemplate.requestShortener; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		// Metainfo for each module
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 		const modulesWithInfo = this._getModulesWithInfo(moduleGraph); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Create mapping from module to info
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 		const moduleToInfoMap = modulesWithInfoToMap(modulesWithInfo); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Configure template decorators for dependencies
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 		const innerDependencyTemplates = this._getInnerDependencyTemplates( | 
					
						
							|  |  |  | 			dependencyTemplates, | 
					
						
							|  |  |  | 			moduleToInfoMap | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-04-29 04:32:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		// Generate source code and analyse scopes
 | 
					
						
							|  |  |  | 		// Prepare a ReplaceSource for the final source
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 			this._analyseModule( | 
					
						
							|  |  |  | 				info, | 
					
						
							|  |  |  | 				innerDependencyTemplates, | 
					
						
							|  |  |  | 				runtimeTemplate, | 
					
						
							|  |  |  | 				moduleGraph, | 
					
						
							|  |  |  | 				chunkGraph | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// List of all used names to avoid conflicts
 | 
					
						
							| 
									
										
										
										
											2018-11-16 22:02:17 +08:00
										 |  |  | 		const allUsedNames = new Set(RESERVED_NAMES); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 		// Set of already checked scopes
 | 
					
						
							|  |  |  | 		const alreadyCheckedScopes = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		// get all global names
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 			if (info.type === "concatenated") { | 
					
						
							|  |  |  | 				const superClassExpressions = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// ignore symbols from moduleScope
 | 
					
						
							|  |  |  | 				if (info.moduleScope) { | 
					
						
							|  |  |  | 					alreadyCheckedScopes.add(info.moduleScope); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// The super class expression in class scopes behaves weird
 | 
					
						
							|  |  |  | 					// We store ranges of all super class expressions to make
 | 
					
						
							|  |  |  | 					// renaming to work correctly
 | 
					
						
							|  |  |  | 					for (const childScope of info.moduleScope.childScopes) { | 
					
						
							|  |  |  | 						if (childScope.type !== "class") continue; | 
					
						
							|  |  |  | 						if (!childScope.block.superClass) continue; | 
					
						
							|  |  |  | 						superClassExpressions.push({ | 
					
						
							|  |  |  | 							range: childScope.block.superClass.range, | 
					
						
							|  |  |  | 							variables: childScope.variables | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 				// add global symbols
 | 
					
						
							|  |  |  | 				if (info.globalScope) { | 
					
						
							|  |  |  | 					for (const reference of info.globalScope.through) { | 
					
						
							|  |  |  | 						const name = reference.identifier.name; | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							/^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test( | 
					
						
							|  |  |  | 								name | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							for (const expr of superClassExpressions) { | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									expr.range[0] <= reference.identifier.range[0] && | 
					
						
							|  |  |  | 									expr.range[1] >= reference.identifier.range[1] | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									for (const variable of expr.variables) { | 
					
						
							|  |  |  | 										allUsedNames.add(variable.name); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 							addScopeSymbols1( | 
					
						
							|  |  |  | 								reference.from, | 
					
						
							|  |  |  | 								allUsedNames, | 
					
						
							|  |  |  | 								alreadyCheckedScopes | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							allUsedNames.add(name); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-08-20 16:34:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 				// add exported globals
 | 
					
						
							| 
									
										
										
										
											2018-08-20 16:34:58 +08:00
										 |  |  | 				const variables = new Set(); | 
					
						
							|  |  |  | 				for (const variable of info.moduleScope.variables) { | 
					
						
							|  |  |  | 					variables.add(variable.name); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for (const [, variable] of info.exportMap) { | 
					
						
							|  |  |  | 					if (!variables.has(variable)) { | 
					
						
							|  |  |  | 						info.globalExports.add(variable); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 		// generate names for symbols
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							|  |  |  | 			switch (info.type) { | 
					
						
							|  |  |  | 				case "concatenated": { | 
					
						
							|  |  |  | 					const namespaceObjectName = this.findNewName( | 
					
						
							|  |  |  | 						"namespaceObject", | 
					
						
							|  |  |  | 						allUsedNames, | 
					
						
							|  |  |  | 						null, | 
					
						
							|  |  |  | 						info.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					allUsedNames.add(namespaceObjectName); | 
					
						
							|  |  |  | 					info.internalNames.set(namespaceObjectName, namespaceObjectName); | 
					
						
							|  |  |  | 					info.exportMap.set(true, namespaceObjectName); | 
					
						
							|  |  |  | 					for (const variable of info.moduleScope.variables) { | 
					
						
							|  |  |  | 						const name = variable.name; | 
					
						
							|  |  |  | 						if (allUsedNames.has(name)) { | 
					
						
							|  |  |  | 							const references = getAllReferences(variable); | 
					
						
							| 
									
										
										
										
											2018-03-29 20:43:01 +08:00
										 |  |  | 							const symbolsInReferences = new Set(); | 
					
						
							|  |  |  | 							const alreadyCheckedInnerScopes = new Set(); | 
					
						
							|  |  |  | 							for (const ref of references) { | 
					
						
							|  |  |  | 								addScopeSymbols2( | 
					
						
							|  |  |  | 									ref.from, | 
					
						
							|  |  |  | 									symbolsInReferences, | 
					
						
							|  |  |  | 									alreadyCheckedInnerScopes, | 
					
						
							|  |  |  | 									alreadyCheckedScopes | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							const newName = this.findNewName( | 
					
						
							|  |  |  | 								name, | 
					
						
							|  |  |  | 								allUsedNames, | 
					
						
							|  |  |  | 								symbolsInReferences, | 
					
						
							|  |  |  | 								info.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							allUsedNames.add(newName); | 
					
						
							|  |  |  | 							info.internalNames.set(name, newName); | 
					
						
							|  |  |  | 							const source = info.source; | 
					
						
							|  |  |  | 							const allIdentifiers = new Set( | 
					
						
							|  |  |  | 								references.map(r => r.identifier).concat(variable.identifiers) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							for (const identifier of allIdentifiers) { | 
					
						
							|  |  |  | 								const r = identifier.range; | 
					
						
							|  |  |  | 								const path = getPathInAst(info.ast, identifier); | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									path && | 
					
						
							|  |  |  | 									path.length > 1 && | 
					
						
							|  |  |  | 									path[1].type === "Property" && | 
					
						
							|  |  |  | 									path[1].shorthand | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									source.insert(r[1], `: ${newName}`); | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									source.replace(r[0], r[1] - 1, newName); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							allUsedNames.add(name); | 
					
						
							|  |  |  | 							info.internalNames.set(name, name); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "external": { | 
					
						
							|  |  |  | 					const externalName = this.findNewName( | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						allUsedNames, | 
					
						
							|  |  |  | 						null, | 
					
						
							|  |  |  | 						info.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					allUsedNames.add(externalName); | 
					
						
							|  |  |  | 					info.name = externalName; | 
					
						
							|  |  |  | 					if ( | 
					
						
							|  |  |  | 						info.module.buildMeta.exportsType === "named" || | 
					
						
							|  |  |  | 						!info.module.buildMeta.exportsType | 
					
						
							|  |  |  | 					) { | 
					
						
							|  |  |  | 						const externalNameInterop = this.findNewName( | 
					
						
							|  |  |  | 							"namespaceObject", | 
					
						
							|  |  |  | 							allUsedNames, | 
					
						
							|  |  |  | 							null, | 
					
						
							|  |  |  | 							info.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						allUsedNames.add(externalNameInterop); | 
					
						
							|  |  |  | 						info.interopNamespaceObjectName = externalNameInterop; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if (!info.module.buildMeta.exportsType) { | 
					
						
							|  |  |  | 						const externalNameInterop = this.findNewName( | 
					
						
							|  |  |  | 							"default", | 
					
						
							|  |  |  | 							allUsedNames, | 
					
						
							|  |  |  | 							null, | 
					
						
							|  |  |  | 							info.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						allUsedNames.add(externalNameInterop); | 
					
						
							|  |  |  | 						info.interopDefaultAccessName = externalNameInterop; | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 		// Find and replace referenced to modules
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							|  |  |  | 			if (info.type === "concatenated") { | 
					
						
							|  |  |  | 				for (const reference of info.globalScope.through) { | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 					const name = reference.identifier.name; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec( | 
					
						
							|  |  |  | 						name | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					if (match) { | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 						const referencedModule = modulesWithInfo[+match[1]]; | 
					
						
							|  |  |  | 						let exportName; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (match[2] === "ns") { | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 							exportName = true; | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2017-08-07 19:56:50 +08:00
										 |  |  | 							const exportData = match[2]; | 
					
						
							| 
									
										
										
										
											2018-01-22 22:00:12 +08:00
										 |  |  | 							exportName = Buffer.from(exportData, "hex").toString("utf-8"); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						const asCall = !!match[3]; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:10:52 +08:00
										 |  |  | 						const strictHarmonyModule = !!match[4]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						const finalName = getFinalName( | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 							moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							referencedModule, | 
					
						
							|  |  |  | 							exportName, | 
					
						
							|  |  |  | 							moduleToInfoMap, | 
					
						
							|  |  |  | 							requestShortener, | 
					
						
							|  |  |  | 							asCall, | 
					
						
							|  |  |  | 							strictHarmonyModule | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 						const r = reference.identifier.range; | 
					
						
							|  |  |  | 						const source = info.source; | 
					
						
							|  |  |  | 						source.replace(r[0], r[1] - 1, finalName); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const result = new ConcatSource(); | 
					
						
							| 
									
										
										
										
											2017-08-07 20:12:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// add harmony compatibility flag (must be first because of possible circular dependencies)
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:55:41 +08:00
										 |  |  | 		const usedExports = moduleGraph.getUsedExports(this.rootModule); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (usedExports === true) { | 
					
						
							|  |  |  | 			result.add( | 
					
						
							|  |  |  | 				runtimeTemplate.defineEsModuleFlagStatement({ | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 					exportsArgument: this.exportsArgument, | 
					
						
							|  |  |  | 					runtimeRequirements: new Set() | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				}) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-07 20:12:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// define required namespace objects (must be before evaluation modules)
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 			if (info.type === "concatenated" && info.namespaceObjectSource) { | 
					
						
							| 
									
										
										
										
											2017-08-07 20:12:31 +08:00
										 |  |  | 				result.add(info.namespaceObjectSource); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-07 20:12:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// evaluate modules in order
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of modulesWithInfo) { | 
					
						
							|  |  |  | 			switch (info.type) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				case "concatenated": | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					result.add( | 
					
						
							|  |  |  | 						`\n// CONCATENATED MODULE: ${info.module.readableIdentifier( | 
					
						
							|  |  |  | 							requestShortener | 
					
						
							|  |  |  | 						)}\n`
 | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 					result.add(info.source); | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				case "external": | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					result.add( | 
					
						
							|  |  |  | 						`\n// EXTERNAL MODULE: ${info.module.readableIdentifier( | 
					
						
							|  |  |  | 							requestShortener | 
					
						
							|  |  |  | 						)}\n`
 | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					result.add( | 
					
						
							|  |  |  | 						`var ${info.name} = __webpack_require__(${JSON.stringify( | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 							chunkGraph.getModuleId(info.module) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						)});\n`
 | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					if (info.interopNamespaceObjectUsed) { | 
					
						
							|  |  |  | 						if (info.module.buildMeta.exportsType === "named") { | 
					
						
							|  |  |  | 							result.add( | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 								`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${ | 
					
						
							|  |  |  | 									RuntimeGlobals.createFakeNamespaceObject | 
					
						
							|  |  |  | 								}(${info.name}, 2);\n`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							); | 
					
						
							|  |  |  | 						} else if (!info.module.buildMeta.exportsType) { | 
					
						
							|  |  |  | 							result.add( | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 								`var ${info.interopNamespaceObjectName} = /*#__PURE__*/${ | 
					
						
							|  |  |  | 									RuntimeGlobals.createFakeNamespaceObject | 
					
						
							|  |  |  | 								}(${info.name});\n`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							); | 
					
						
							| 
									
										
										
										
											2018-01-06 04:35:36 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (info.interopDefaultAccessUsed) { | 
					
						
							|  |  |  | 						result.add( | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 							`var ${info.interopDefaultAccessName} = /*#__PURE__*/${ | 
					
						
							|  |  |  | 								RuntimeGlobals.compatGetDefaultExport | 
					
						
							|  |  |  | 							}(${info.name});\n`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 					// @ts-ignore never is expected here
 | 
					
						
							| 
									
										
										
										
											2017-08-07 19:19:24 +08:00
										 |  |  | 					throw new Error(`Unsupported concatenation entry type ${info.type}`); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 	_analyseModule( | 
					
						
							|  |  |  | 		info, | 
					
						
							|  |  |  | 		innerDependencyTemplates, | 
					
						
							|  |  |  | 		runtimeTemplate, | 
					
						
							|  |  |  | 		moduleGraph, | 
					
						
							|  |  |  | 		chunkGraph | 
					
						
							|  |  |  | 	) { | 
					
						
							|  |  |  | 		if (info.type === "concatenated") { | 
					
						
							|  |  |  | 			const m = info.module; | 
					
						
							|  |  |  | 			const source = m.source({ | 
					
						
							|  |  |  | 				dependencyTemplates: innerDependencyTemplates, | 
					
						
							|  |  |  | 				runtimeTemplate, | 
					
						
							|  |  |  | 				moduleGraph, | 
					
						
							|  |  |  | 				chunkGraph | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			const code = source.source(); | 
					
						
							|  |  |  | 			let ast; | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				ast = JavascriptParser.parse(code, { | 
					
						
							|  |  |  | 					sourceType: "module" | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} catch (err) { | 
					
						
							|  |  |  | 				if ( | 
					
						
							|  |  |  | 					err.loc && | 
					
						
							|  |  |  | 					typeof err.loc === "object" && | 
					
						
							|  |  |  | 					typeof err.loc.line === "number" | 
					
						
							|  |  |  | 				) { | 
					
						
							|  |  |  | 					const lineNumber = err.loc.line; | 
					
						
							|  |  |  | 					const lines = code.split("\n"); | 
					
						
							|  |  |  | 					err.message += | 
					
						
							|  |  |  | 						"\n| " + | 
					
						
							|  |  |  | 						lines | 
					
						
							|  |  |  | 							.slice(Math.max(0, lineNumber - 3), lineNumber + 2) | 
					
						
							|  |  |  | 							.join("\n| "); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				throw err; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			const scopeManager = eslintScope.analyze(ast, { | 
					
						
							|  |  |  | 				ecmaVersion: 6, | 
					
						
							|  |  |  | 				sourceType: "module", | 
					
						
							|  |  |  | 				optimistic: true, | 
					
						
							|  |  |  | 				ignoreEval: true, | 
					
						
							|  |  |  | 				impliedStrict: true | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			const globalScope = scopeManager.acquire(ast); | 
					
						
							|  |  |  | 			const moduleScope = globalScope.childScopes[0]; | 
					
						
							|  |  |  | 			const resultSource = new ReplaceSource(source); | 
					
						
							|  |  |  | 			info.ast = ast; | 
					
						
							|  |  |  | 			info.internalSource = source; | 
					
						
							|  |  |  | 			info.source = resultSource; | 
					
						
							|  |  |  | 			info.globalScope = globalScope; | 
					
						
							|  |  |  | 			info.moduleScope = moduleScope; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							|  |  |  | 	 * @returns {ModuleInfo[]} module info items | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getModulesWithInfo(moduleGraph) { | 
					
						
							|  |  |  | 		return this._orderedConcatenationList.map((info, idx) => { | 
					
						
							|  |  |  | 			/** @type {ModuleInfo} */ | 
					
						
							|  |  |  | 			let result; | 
					
						
							|  |  |  | 			switch (info.type) { | 
					
						
							|  |  |  | 				case "concatenated": { | 
					
						
							|  |  |  | 					const exportMap = new Map(); | 
					
						
							|  |  |  | 					const reexportMap = new Map(); | 
					
						
							|  |  |  | 					for (const dep of info.module.dependencies) { | 
					
						
							|  |  |  | 						if (dep instanceof HarmonyExportSpecifierDependency) { | 
					
						
							|  |  |  | 							if (!exportMap.has(dep.name)) { | 
					
						
							|  |  |  | 								exportMap.set(dep.name, dep.id); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} else if (dep instanceof HarmonyExportExpressionDependency) { | 
					
						
							|  |  |  | 							if (!exportMap.has("default")) { | 
					
						
							|  |  |  | 								exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__"); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} else if ( | 
					
						
							|  |  |  | 							dep instanceof HarmonyExportImportedSpecifierDependency | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							const exportName = dep.name; | 
					
						
							|  |  |  | 							const importName = dep.id; | 
					
						
							|  |  |  | 							const importedModule = moduleGraph.getModule(dep); | 
					
						
							|  |  |  | 							if (exportName && importName) { | 
					
						
							|  |  |  | 								if (!reexportMap.has(exportName)) { | 
					
						
							|  |  |  | 									reexportMap.set(exportName, { | 
					
						
							|  |  |  | 										module: importedModule, | 
					
						
							|  |  |  | 										exportName: importName, | 
					
						
							|  |  |  | 										dependency: dep | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} else if (exportName) { | 
					
						
							|  |  |  | 								if (!reexportMap.has(exportName)) { | 
					
						
							|  |  |  | 									reexportMap.set(exportName, { | 
					
						
							|  |  |  | 										module: importedModule, | 
					
						
							|  |  |  | 										exportName: true, | 
					
						
							|  |  |  | 										dependency: dep | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} else if ( | 
					
						
							|  |  |  | 								importedModule && | 
					
						
							|  |  |  | 								Array.isArray(importedModule.buildMeta.providedExports) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								for (const name of importedModule.buildMeta.providedExports) { | 
					
						
							|  |  |  | 									if (dep.activeExports.has(name) || name === "default") { | 
					
						
							|  |  |  | 										continue; | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									if (!reexportMap.has(name)) { | 
					
						
							|  |  |  | 										reexportMap.set(name, { | 
					
						
							|  |  |  | 											module: importedModule, | 
					
						
							|  |  |  | 											exportName: name, | 
					
						
							|  |  |  | 											dependency: dep | 
					
						
							|  |  |  | 										}); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					result = { | 
					
						
							|  |  |  | 						type: "concatenated", | 
					
						
							|  |  |  | 						module: info.module, | 
					
						
							|  |  |  | 						index: idx, | 
					
						
							|  |  |  | 						ast: undefined, | 
					
						
							|  |  |  | 						internalSource: undefined, | 
					
						
							|  |  |  | 						source: undefined, | 
					
						
							|  |  |  | 						globalScope: undefined, | 
					
						
							|  |  |  | 						moduleScope: undefined, | 
					
						
							|  |  |  | 						internalNames: new Map(), | 
					
						
							|  |  |  | 						globalExports: new Set(), | 
					
						
							|  |  |  | 						exportMap: exportMap, | 
					
						
							|  |  |  | 						reexportMap: reexportMap, | 
					
						
							|  |  |  | 						hasNamespaceObject: false, | 
					
						
							|  |  |  | 						namespaceObjectSource: null | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "external": | 
					
						
							|  |  |  | 					result = { | 
					
						
							|  |  |  | 						type: "external", | 
					
						
							|  |  |  | 						module: info.module, | 
					
						
							|  |  |  | 						index: idx, | 
					
						
							|  |  |  | 						name: undefined, | 
					
						
							|  |  |  | 						interopNamespaceObjectUsed: false, | 
					
						
							|  |  |  | 						interopNamespaceObjectName: undefined, | 
					
						
							|  |  |  | 						interopDefaultAccessUsed: false, | 
					
						
							|  |  |  | 						interopDefaultAccessName: undefined | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					throw new Error(`Unsupported concatenation entry type ${info.type}`); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return result; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {DependencyTemplates} dependencyTemplates outer dependency templates | 
					
						
							|  |  |  | 	 * @param {Map<Module, ModuleInfo>} moduleToInfoMap map for module info | 
					
						
							|  |  |  | 	 * @returns {DependencyTemplates} inner dependency templates | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getInnerDependencyTemplates(dependencyTemplates, moduleToInfoMap) { | 
					
						
							|  |  |  | 		const innerDependencyTemplates = dependencyTemplates.clone(); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyImportSpecifierDependency, | 
					
						
							|  |  |  | 			new HarmonyImportSpecifierDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyImportSpecifierDependency), | 
					
						
							|  |  |  | 				moduleToInfoMap | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyImportSideEffectDependency, | 
					
						
							|  |  |  | 			new HarmonyImportSideEffectDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyImportSideEffectDependency), | 
					
						
							|  |  |  | 				moduleToInfoMap | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyExportSpecifierDependency, | 
					
						
							|  |  |  | 			new HarmonyExportSpecifierDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyExportSpecifierDependency), | 
					
						
							|  |  |  | 				this.rootModule | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyExportExpressionDependency, | 
					
						
							|  |  |  | 			new HarmonyExportExpressionDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyExportExpressionDependency), | 
					
						
							|  |  |  | 				this.rootModule | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyExportImportedSpecifierDependency, | 
					
						
							|  |  |  | 			new HarmonyExportImportedSpecifierDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyExportImportedSpecifierDependency), | 
					
						
							|  |  |  | 				this.rootModule, | 
					
						
							|  |  |  | 				moduleToInfoMap | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		innerDependencyTemplates.set( | 
					
						
							|  |  |  | 			HarmonyCompatibilityDependency, | 
					
						
							|  |  |  | 			new HarmonyCompatibilityDependencyConcatenatedTemplate( | 
					
						
							|  |  |  | 				dependencyTemplates.get(HarmonyCompatibilityDependency), | 
					
						
							|  |  |  | 				this.rootModule, | 
					
						
							|  |  |  | 				moduleToInfoMap | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		// Must use full identifier in our cache here to ensure that the source
 | 
					
						
							|  |  |  | 		// is updated should our dependencies list change.
 | 
					
						
							|  |  |  | 		// TODO webpack 5 refactor
 | 
					
						
							|  |  |  | 		innerDependencyTemplates.updateHash(this.identifier()); | 
					
						
							|  |  |  | 		return innerDependencyTemplates; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 	findNewName(oldName, usedNamed1, usedNamed2, extraInfo) { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		let name = oldName; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (name === "__WEBPACK_MODULE_DEFAULT_EXPORT__") name = ""; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-07 18:57:15 +08:00
										 |  |  | 		// Remove uncool stuff
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		extraInfo = extraInfo.replace( | 
					
						
							|  |  |  | 			/\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g, | 
					
						
							|  |  |  | 			"" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-06-07 18:57:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		const splittedInfo = extraInfo.split("/"); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (splittedInfo.length) { | 
					
						
							| 
									
										
										
										
											2017-08-07 20:38:54 +08:00
										 |  |  | 			name = splittedInfo.pop() + (name ? "_" + name : ""); | 
					
						
							| 
									
										
										
										
											2017-05-31 22:46:25 +08:00
										 |  |  | 			const nameIdent = Template.toIdentifier(name); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if ( | 
					
						
							|  |  |  | 				!usedNamed1.has(nameIdent) && | 
					
						
							|  |  |  | 				(!usedNamed2 || !usedNamed2.has(nameIdent)) | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 				return nameIdent; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 22:15:49 +08:00
										 |  |  | 		let i = 0; | 
					
						
							|  |  |  | 		let nameWithNumber = Template.toIdentifier(`${name}_${i}`); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while ( | 
					
						
							|  |  |  | 			usedNamed1.has(nameWithNumber) || | 
					
						
							|  |  |  | 			(usedNamed2 && usedNamed2.has(nameWithNumber)) | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2017-08-07 21:43:17 +08:00
										 |  |  | 			i++; | 
					
						
							|  |  |  | 			nameWithNumber = Template.toIdentifier(`${name}_${i}`); | 
					
						
							| 
									
										
										
										
											2017-08-07 22:15:49 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-07 21:43:17 +08:00
										 |  |  | 		return nameWithNumber; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get a list of runtime requirements | 
					
						
							|  |  |  | 	 * @param {SourceContext} context context for code generation | 
					
						
							|  |  |  | 	 * @returns {Iterable<string> | null} required runtime modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getRuntimeRequirements(context) { | 
					
						
							|  |  |  | 		const { dependencyTemplates, moduleGraph } = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Metainfo for each module
 | 
					
						
							|  |  |  | 		const modulesWithInfo = this._getModulesWithInfo(moduleGraph); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Create mapping from module to info
 | 
					
						
							|  |  |  | 		const moduleToInfoMap = modulesWithInfoToMap(modulesWithInfo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Configure template decorators for dependencies
 | 
					
						
							|  |  |  | 		const innerDependencyTemplates = this._getInnerDependencyTemplates( | 
					
						
							|  |  |  | 			dependencyTemplates, | 
					
						
							|  |  |  | 			moduleToInfoMap | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const innerContext = Object.assign({}, context, { | 
					
						
							|  |  |  | 			dependencyTemplates: innerDependencyTemplates | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		const set = new Set([ | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 			RuntimeGlobals.exports, // TODO check if really used
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			RuntimeGlobals.makeNamespaceObject, | 
					
						
							|  |  |  | 			RuntimeGlobals.definePropertyGetter | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 		for (const info of this._orderedConcatenationList) { | 
					
						
							|  |  |  | 			switch (info.type) { | 
					
						
							|  |  |  | 				case "concatenated": { | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 					const req = info.module.getRuntimeRequirements(innerContext); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 					if (req) { | 
					
						
							|  |  |  | 						for (const r of req) set.add(r); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "external": { | 
					
						
							|  |  |  | 					if ( | 
					
						
							|  |  |  | 						!info.module.buildMeta.exportsType || | 
					
						
							|  |  |  | 						info.module.buildMeta.exportsType === "named" | 
					
						
							|  |  |  | 					) { | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.createFakeNamespaceObject); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.compatGetDefaultExport); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return set; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash used to track dependencies | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	updateHash(hash, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const info of this._orderedConcatenationList) { | 
					
						
							|  |  |  | 			switch (info.type) { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 				case "concatenated": | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 					info.module.updateHash(hash, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				case "external": | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 					hash.update(`${chunkGraph.getModuleId(info.module)}`); | 
					
						
							| 
									
										
										
										
											2017-08-07 17:53:07 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-07 17:48:52 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		super.updateHash(hash, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-07-07 17:48:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyImportSpecifierDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, modulesMap) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.modulesMap = modulesMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +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-25 19:16:08 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	apply(dependency, source, templateContext) { | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 		const { moduleGraph, module: parentModule } = templateContext; | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		const module = moduleGraph.getModule(dep); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		const info = this.modulesMap.get(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!info) { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			this.originalTemplate.apply(dependency, source, templateContext); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		let content; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:10:52 +08:00
										 |  |  | 		const callFlag = dep.call ? "_call" : ""; | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 		const strictFlag = parentModule.buildMeta.strictHarmonyModule | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			? "_strict" | 
					
						
							|  |  |  | 			: ""; | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		const id = dep.getId(moduleGraph); | 
					
						
							|  |  |  | 		if (id === null) { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:10:52 +08:00
										 |  |  | 			content = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		} else if (dep.namespaceObjectAsContext) { | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 			content = `__WEBPACK_MODULE_REFERENCE__${ | 
					
						
							|  |  |  | 				info.index | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			}_ns${strictFlag}__[${JSON.stringify(id)}]`;
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			const exportData = Buffer.from(id, "utf-8").toString("hex"); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 			content = `__WEBPACK_MODULE_REFERENCE__${ | 
					
						
							|  |  |  | 				info.index | 
					
						
							|  |  |  | 			}_${exportData}${callFlag}${strictFlag}__`;
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (dep.shorthand) { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			content = dep.name + ": " + content; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		source.replace(dep.range[0], dep.range[1] - 1, content); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyImportSideEffectDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, modulesMap) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.modulesMap = modulesMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +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-25 19:16:08 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	apply(dependency, source, templateContext) { | 
					
						
							|  |  |  | 		const { moduleGraph } = templateContext; | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		const dep = /** @type {HarmonyImportSideEffectDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		const module = moduleGraph.getModule(dep); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		const info = this.modulesMap.get(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!info) { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			this.originalTemplate.apply(dependency, source, templateContext); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyExportSpecifierDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, rootModule) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.rootModule = rootModule; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +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-25 19:16:08 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	apply(dependency, source, templateContext) { | 
					
						
							| 
									
										
										
										
											2018-08-07 20:20:53 +08:00
										 |  |  | 		if (templateContext.module === this.rootModule) { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			this.originalTemplate.apply(dependency, source, templateContext); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyExportExpressionDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, rootModule) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.rootModule = rootModule; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency for which the template should be applied | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	 * @param {ReplaceSource} source the current replace source which can be modified | 
					
						
							|  |  |  | 	 * @param {DependencyTemplateContext} templateContext the context object | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	apply(dependency, source, { module, moduleGraph, initFragments }) { | 
					
						
							|  |  |  | 		const dep = /** @type {HarmonyExportExpressionDependency} */ (dependency); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 		if (module === this.rootModule) { | 
					
						
							|  |  |  | 			const used = module.getUsedName(moduleGraph, "default"); | 
					
						
							|  |  |  | 			const exportsName = module.exportsArgument; | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 			initFragments.push( | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 				new InitFragment( | 
					
						
							|  |  |  | 					`/* harmony export export */ ` + | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 						`${ | 
					
						
							|  |  |  | 							RuntimeGlobals.definePropertyGetter | 
					
						
							|  |  |  | 						}(${exportsName}, ${JSON.stringify(used)}, ` +
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 						`function() { return __WEBPACK_MODULE_DEFAULT_EXPORT__; });\n`, | 
					
						
							|  |  |  | 					InitFragment.STAGE_HARMONY_EXPORTS, | 
					
						
							|  |  |  | 					1 | 
					
						
							|  |  |  | 				) | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const content = | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			"/* harmony default export */ var __WEBPACK_MODULE_DEFAULT_EXPORT__ = "; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (dep.range) { | 
					
						
							| 
									
										
										
										
											2018-09-26 03:52:03 +08:00
										 |  |  | 			source.replace( | 
					
						
							|  |  |  | 				dep.rangeStatement[0], | 
					
						
							|  |  |  | 				dep.range[0] - 1, | 
					
						
							|  |  |  | 				content + "(" + dep.prefix | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-07-22 05:32:31 +08:00
										 |  |  | 			source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");"); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-22 05:32:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 03:52:03 +08:00
										 |  |  | 		source.replace( | 
					
						
							|  |  |  | 			dep.rangeStatement[0], | 
					
						
							|  |  |  | 			dep.rangeStatement[1] - 1, | 
					
						
							|  |  |  | 			content + dep.prefix | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, rootModule, modulesMap) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.rootModule = rootModule; | 
					
						
							|  |  |  | 		this.modulesMap = modulesMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @typedef {Object} GetExportsResultItem | 
					
						
							|  |  |  | 	 * @property {string} name | 
					
						
							|  |  |  | 	 * @property {string | true} id | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {HarmonyExportImportedSpecifierDependency} dep dependency | 
					
						
							|  |  |  | 	 * @param {DependencyTemplateContext} templateContext template context | 
					
						
							|  |  |  | 	 * @returns {GetExportsResultItem[]} exports | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	getExports(dep, { moduleGraph }) { | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		const importModule = moduleGraph.getModule(dep); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (dep.id) { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			// export { named } from "module"
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return [ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: dep.name, | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 					id: dep.id | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			]; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (dep.name) { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 			// export * as abc from "module"
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return [ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: dep.name, | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 					id: true | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			]; | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		// export * from "module"
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 		if (Array.isArray(importModule.buildMeta.providedExports)) { | 
					
						
							|  |  |  | 			return importModule.buildMeta.providedExports | 
					
						
							|  |  |  | 				.filter(exp => exp !== "default" && !dep.activeExports.has(exp)) | 
					
						
							|  |  |  | 				.map(exp => { | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						name: exp, | 
					
						
							|  |  |  | 						id: exp | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// unknown, should not happen
 | 
					
						
							|  |  |  | 		throw new Error("ConcatenatedModule: unknown exports"); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 17:45:12 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Dependency} dependency the dependency for which the template should be applied | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	 * @param {ReplaceSource} source the current replace source which can be modified | 
					
						
							|  |  |  | 	 * @param {DependencyTemplateContext} templateContext the context object | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-07-27 17:45:12 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 	apply(dependency, source, templateContext) { | 
					
						
							|  |  |  | 		const { module, moduleGraph, initFragments } = templateContext; | 
					
						
							| 
									
										
										
										
											2018-07-27 17:45:12 +08:00
										 |  |  | 		const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 		const importedModule = moduleGraph.getModule(dep); | 
					
						
							|  |  |  | 		const info = this.modulesMap.get(importedModule); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!info) { | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 			this.originalTemplate.apply(dependency, source, templateContext); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 		} else if (module === this.rootModule) { | 
					
						
							|  |  |  | 			const exportDefs = this.getExports(dep, templateContext); | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 			for (const def of exportDefs) { | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 				const used = module.getUsedName(moduleGraph, def.name); | 
					
						
							|  |  |  | 				if (!used) { | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 					initFragments.push( | 
					
						
							|  |  |  | 						new InitFragment( | 
					
						
							|  |  |  | 							`/* unused concated harmony import ${dep.name} */\n`, | 
					
						
							|  |  |  | 							InitFragment.STAGE_HARMONY_EXPORTS, | 
					
						
							|  |  |  | 							1 | 
					
						
							|  |  |  | 						) | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 					continue; | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				let finalName; | 
					
						
							|  |  |  | 				const strictFlag = module.buildMeta.strictHarmonyModule | 
					
						
							|  |  |  | 					? "_strict" | 
					
						
							|  |  |  | 					: ""; | 
					
						
							|  |  |  | 				if (def.id === true) { | 
					
						
							|  |  |  | 					finalName = `__WEBPACK_MODULE_REFERENCE__${ | 
					
						
							|  |  |  | 						info.index | 
					
						
							|  |  |  | 					}_ns${strictFlag}__`;
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					const exportData = Buffer.from(def.id, "utf-8").toString("hex"); | 
					
						
							|  |  |  | 					finalName = `__WEBPACK_MODULE_REFERENCE__${ | 
					
						
							|  |  |  | 						info.index | 
					
						
							|  |  |  | 					}_${exportData}${strictFlag}__`;
 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				const exportsName = this.rootModule.exportsArgument; | 
					
						
							|  |  |  | 				const content = | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 					`/* concated harmony reexport */ ${ | 
					
						
							|  |  |  | 						RuntimeGlobals.definePropertyGetter | 
					
						
							|  |  |  | 					}(` +
 | 
					
						
							| 
									
										
										
										
											2018-08-09 17:46:44 +08:00
										 |  |  | 					`${exportsName}, ${JSON.stringify(used)}, ` + | 
					
						
							|  |  |  | 					`function() { return ${finalName}; });\n`; | 
					
						
							| 
									
										
										
										
											2018-11-16 23:40:03 +08:00
										 |  |  | 				initFragments.push( | 
					
						
							|  |  |  | 					new InitFragment(content, InitFragment.STAGE_HARMONY_EXPORTS, 1) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | class HarmonyCompatibilityDependencyConcatenatedTemplate extends DependencyTemplate { | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	constructor(originalTemplate, rootModule, modulesMap) { | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 		this.originalTemplate = originalTemplate; | 
					
						
							|  |  |  | 		this.rootModule = rootModule; | 
					
						
							|  |  |  | 		this.modulesMap = modulesMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 19:16:08 +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-25 19:16:08 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	apply( | 
					
						
							|  |  |  | 		dependency, | 
					
						
							|  |  |  | 		source, | 
					
						
							|  |  |  | 		{ runtimeTemplate, dependencyTemplates, moduleGraph } | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2017-08-16 20:54:31 +08:00
										 |  |  | 		// do nothing
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ConcatenatedModule; |