mirror of https://github.com/webpack/webpack.git
				
				
				
			
							parent
							
								
									25302e51a6
								
							
						
					
					
						commit
						0e73a2458a
					
				|  | @ -32,17 +32,16 @@ function ensureNsObjSource(info, moduleToInfoMap, requestShortener) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| function getExternalImport(importedModule, importedVar, exportName, asCall) { | ||||
| 	const isHarmonyModule = importedModule && (!importedModule.meta || importedModule.meta.harmonyModule); | ||||
| 	if(exportName === true) return importedVar; | ||||
| function getExternalImport(importedModule, info, exportName, asCall) { | ||||
| 	if(exportName === true) return info.name; | ||||
| 	const used = importedModule.isUsed(exportName); | ||||
| 	if(!used) return "/* unused reexport */undefined"; | ||||
| 	if(!isHarmonyModule && exportName === "default") { | ||||
| 		return asCall ? `${importedVar}_default()` : `${importedVar}_default.a`; | ||||
| 	if(info.interop && exportName === "default") { | ||||
| 		return asCall ? `${info.interopName}()` : `${info.interopName}.a`; | ||||
| 	} | ||||
| 	// TODO use Template.toNormalComment when merging with pure-module
 | ||||
| 	const comment = used !== exportName ? ` /* ${exportName} */` : ""; | ||||
| 	const reference = `${importedVar}[${JSON.stringify(used)}${comment}]`; | ||||
| 	const reference = `${info.name}[${JSON.stringify(used)}${comment}]`; | ||||
| 	if(asCall) | ||||
| 		return `Object(${reference})`; | ||||
| 	return reference; | ||||
|  | @ -67,12 +66,6 @@ function getFinalName(info, exportName, moduleToInfoMap, requestShortener, asCal | |||
| 					if(refInfo) { | ||||
| 						// module is in the concatenation
 | ||||
| 						return getFinalName(refInfo, reexport.exportName, moduleToInfoMap, requestShortener, asCall); | ||||
| 					} else { | ||||
| 						const dep = reexport.dependency; | ||||
| 						const importedModule = reexport.module; | ||||
| 						const exportName = reexport.exportName; | ||||
| 						const importedVar = dep.importedVar; | ||||
| 						return getExternalImport(importedModule, importedVar, exportName, asCall); | ||||
| 					} | ||||
| 				} | ||||
| 				const problem = `Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(requestShortener)}"` + | ||||
|  | @ -84,7 +77,7 @@ function getFinalName(info, exportName, moduleToInfoMap, requestShortener, asCal | |||
| 		case "external": | ||||
| 			{ | ||||
| 				const importedModule = info.module; | ||||
| 				return getExternalImport(importedModule, info.name, exportName, asCall); | ||||
| 				return getExternalImport(importedModule, info, exportName, asCall); | ||||
| 			} | ||||
| 	} | ||||
| } | ||||
|  | @ -363,7 +356,9 @@ class ConcatenatedModule extends Module { | |||
| 						type: "external", | ||||
| 						module: info.module, | ||||
| 						index: idx, | ||||
| 						name: undefined | ||||
| 						name: undefined, | ||||
| 						interopName: undefined, | ||||
| 						interop: undefined | ||||
| 					}; | ||||
| 				default: | ||||
| 					throw new Error(`Unsupported concatenation entry type ${info.type}`); | ||||
|  | @ -458,6 +453,8 @@ class ConcatenatedModule extends Module { | |||
| 			"switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", | ||||
| 			"var", "void", "volatile", "while", "with", "yield", | ||||
| 
 | ||||
| 			"module", "__dirname", "__filename", "exports", | ||||
| 
 | ||||
| 			"Array", "Date", "eval", "function", "hasOwnProperty", "Infinity", "isFinite", "isNaN", | ||||
| 			"isPrototypeOf", "length", "Math", "NaN", "name", "Number", "Object", "prototype", "String", | ||||
| 			"toString", "undefined", "valueOf", | ||||
|  | @ -531,9 +528,15 @@ class ConcatenatedModule extends Module { | |||
| 					} | ||||
| 				case "external": | ||||
| 					{ | ||||
| 						info.interop = info.module.meta && !info.module.meta.harmonyModule; | ||||
| 						const externalName = this.findNewName("", allUsedNames, null, info.module.readableIdentifier(requestShortener)); | ||||
| 						allUsedNames.add(externalName); | ||||
| 						info.name = externalName; | ||||
| 						if(info.interop) { | ||||
| 							const externalNameInterop = this.findNewName("default", allUsedNames, null, info.module.readableIdentifier(requestShortener)); | ||||
| 							allUsedNames.add(externalNameInterop); | ||||
| 							info.interopName = externalNameInterop; | ||||
| 						} | ||||
| 						break; | ||||
| 					} | ||||
| 			} | ||||
|  | @ -588,8 +591,8 @@ class ConcatenatedModule extends Module { | |||
| 				case "external": | ||||
| 					result.add(`\n// EXTERNAL MODULE: ${info.module.readableIdentifier(requestShortener)}\n`); | ||||
| 					result.add(`var ${info.name} = __webpack_require__(${JSON.stringify(info.module.id)});\n`); | ||||
| 					if(info.module.meta && !info.module.meta.harmonyModule) { | ||||
| 						result.add(`var ${info.name}_default = /*#__PURE__*/__webpack_require__.n(${info.name});\n`); | ||||
| 					if(info.interop) { | ||||
| 						result.add(`var ${info.interopName} = /*#__PURE__*/__webpack_require__.n(${info.name});\n`); | ||||
| 					} | ||||
| 					break; | ||||
| 				default: | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| module.exports = "ok"; | ||||
|  | @ -0,0 +1,5 @@ | |||
| import value from "./module"; | ||||
| 
 | ||||
| it("should not cause name conflicts", function() { | ||||
| 	(typeof value).should.be.eql("undefined"); | ||||
| }); | ||||
|  | @ -0,0 +1,5 @@ | |||
| import a from "./cjs"; | ||||
| 
 | ||||
| var cjs_default; | ||||
| 
 | ||||
| export default cjs_default; | ||||
		Loading…
	
		Reference in New Issue