ConcatenatedModule.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const eslintScope = require("eslint-scope");
  7. const Referencer = require("eslint-scope/lib/referencer");
  8. const {
  9. CachedSource,
  10. ConcatSource,
  11. ReplaceSource
  12. } = require("webpack-sources");
  13. const ConcatenationScope = require("../ConcatenationScope");
  14. const { UsageState } = require("../ExportsInfo");
  15. const Module = require("../Module");
  16. const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
  17. const RuntimeGlobals = require("../RuntimeGlobals");
  18. const Template = require("../Template");
  19. const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
  20. const JavascriptParser = require("../javascript/JavascriptParser");
  21. const { equals } = require("../util/ArrayHelpers");
  22. const LazySet = require("../util/LazySet");
  23. const { concatComparators } = require("../util/comparators");
  24. const createHash = require("../util/createHash");
  25. const { makePathsRelative } = require("../util/identifier");
  26. const makeSerializable = require("../util/makeSerializable");
  27. const { getAllReferences, getPathInAst } = require("../util/mergeScope");
  28. const propertyAccess = require("../util/propertyAccess");
  29. const { propertyName } = require("../util/propertyName");
  30. const {
  31. filterRuntime,
  32. intersectRuntime,
  33. mergeRuntimeCondition,
  34. mergeRuntimeConditionNonFalse,
  35. runtimeConditionToString,
  36. subtractRuntimeCondition
  37. } = require("../util/runtime");
  38. /** @typedef {import("eslint-scope").Reference} Reference */
  39. /** @typedef {import("eslint-scope").Scope} Scope */
  40. /** @typedef {import("eslint-scope").Variable} Variable */
  41. /** @typedef {import("webpack-sources").Source} Source */
  42. /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
  43. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  44. /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
  45. /** @typedef {import("../Compilation")} Compilation */
  46. /** @typedef {import("../Dependency")} Dependency */
  47. /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
  48. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  49. /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
  50. /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
  51. /** @typedef {import("../Module").BuildInfo} BuildInfo */
  52. /** @typedef {import("../Module").BuildMeta} BuildMeta */
  53. /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
  54. /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
  55. /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
  56. /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
  57. /** @typedef {import("../Module").SourceTypes} SourceTypes */
  58. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  59. /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
  60. /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
  61. /** @typedef {import("../RequestShortener")} RequestShortener */
  62. /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
  63. /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
  64. /** @typedef {import("../WebpackError")} WebpackError */
  65. /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
  66. /** @typedef {import("../javascript/JavascriptParser").Program} Program */
  67. /** @typedef {import("../javascript/JavascriptParser").Range} Range */
  68. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  69. /** @typedef {import("../util/Hash")} Hash */
  70. /** @typedef {typeof import("../util/Hash")} HashConstructor */
  71. /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
  72. /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
  73. /**
  74. * @template T
  75. * @typedef {import("../InitFragment")<T>} InitFragment
  76. */
  77. /**
  78. * @template T
  79. * @typedef {import("../util/comparators").Comparator<T>} Comparator
  80. */
  81. // fix eslint-scope to support class properties correctly
  82. // cspell:word Referencer
  83. const ReferencerClass = /** @type {any} */ (Referencer);
  84. if (!ReferencerClass.prototype.PropertyDefinition) {
  85. ReferencerClass.prototype.PropertyDefinition =
  86. ReferencerClass.prototype.Property;
  87. }
  88. /**
  89. * @typedef {object} ReexportInfo
  90. * @property {Module} module
  91. * @property {string[]} export
  92. */
  93. /** @typedef {RawBinding | SymbolBinding} Binding */
  94. /**
  95. * @typedef {object} RawBinding
  96. * @property {ModuleInfo} info
  97. * @property {string} rawName
  98. * @property {string=} comment
  99. * @property {string[]} ids
  100. * @property {string[]} exportName
  101. */
  102. /**
  103. * @typedef {object} SymbolBinding
  104. * @property {ConcatenatedModuleInfo} info
  105. * @property {string} name
  106. * @property {string=} comment
  107. * @property {string[]} ids
  108. * @property {string[]} exportName
  109. */
  110. /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo } ModuleInfo */
  111. /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo } ModuleInfoOrReference */
  112. /**
  113. * @typedef {object} ConcatenatedModuleInfo
  114. * @property {"concatenated"} type
  115. * @property {Module} module
  116. * @property {number} index
  117. * @property {Program | undefined} ast
  118. * @property {Source} internalSource
  119. * @property {ReplaceSource} source
  120. * @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
  121. * @property {ReadOnlyRuntimeRequirements} runtimeRequirements
  122. * @property {Scope} globalScope
  123. * @property {Scope} moduleScope
  124. * @property {Map<string, string>} internalNames
  125. * @property {Map<string, string> | undefined} exportMap
  126. * @property {Map<string, string> | undefined} rawExportMap
  127. * @property {string=} namespaceExportSymbol
  128. * @property {string | undefined} namespaceObjectName
  129. * @property {boolean} interopNamespaceObjectUsed
  130. * @property {string | undefined} interopNamespaceObjectName
  131. * @property {boolean} interopNamespaceObject2Used
  132. * @property {string | undefined} interopNamespaceObject2Name
  133. * @property {boolean} interopDefaultAccessUsed
  134. * @property {string | undefined} interopDefaultAccessName
  135. */
  136. /**
  137. * @typedef {object} ExternalModuleInfo
  138. * @property {"external"} type
  139. * @property {Module} module
  140. * @property {RuntimeSpec | boolean} runtimeCondition
  141. * @property {number} index
  142. * @property {string} name
  143. * @property {boolean} interopNamespaceObjectUsed
  144. * @property {string} interopNamespaceObjectName
  145. * @property {boolean} interopNamespaceObject2Used
  146. * @property {string} interopNamespaceObject2Name
  147. * @property {boolean} interopDefaultAccessUsed
  148. * @property {string} interopDefaultAccessName
  149. */
  150. /**
  151. * @typedef {object} ReferenceToModuleInfo
  152. * @property {"reference"} type
  153. * @property {RuntimeSpec | boolean} runtimeCondition
  154. * @property {ConcatenatedModuleInfo | ExternalModuleInfo} target
  155. */
  156. /** @typedef {Set<string>} UsedNames */
  157. const RESERVED_NAMES = new Set(
  158. [
  159. // internal names (should always be renamed)
  160. ConcatenationScope.DEFAULT_EXPORT,
  161. ConcatenationScope.NAMESPACE_OBJECT_EXPORT,
  162. // keywords
  163. "abstract,arguments,async,await,boolean,break,byte,case,catch,char,class,const,continue",
  164. "debugger,default,delete,do,double,else,enum,eval,export,extends,false,final,finally,float",
  165. "for,function,goto,if,implements,import,in,instanceof,int,interface,let,long,native,new,null",
  166. "package,private,protected,public,return,short,static,super,switch,synchronized,this,throw",
  167. "throws,transient,true,try,typeof,var,void,volatile,while,with,yield",
  168. // commonjs/amd
  169. "module,__dirname,__filename,exports,require,define",
  170. // js globals
  171. "Array,Date,eval,function,hasOwnProperty,Infinity,isFinite,isNaN,isPrototypeOf,length,Math",
  172. "NaN,name,Number,Object,prototype,String,toString,undefined,valueOf",
  173. // browser globals
  174. "alert,all,anchor,anchors,area,assign,blur,button,checkbox,clearInterval,clearTimeout",
  175. "clientInformation,close,closed,confirm,constructor,crypto,decodeURI,decodeURIComponent",
  176. "defaultStatus,document,element,elements,embed,embeds,encodeURI,encodeURIComponent,escape",
  177. "event,fileUpload,focus,form,forms,frame,innerHeight,innerWidth,layer,layers,link,location",
  178. "mimeTypes,navigate,navigator,frames,frameRate,hidden,history,image,images,offscreenBuffering",
  179. "open,opener,option,outerHeight,outerWidth,packages,pageXOffset,pageYOffset,parent,parseFloat",
  180. "parseInt,password,pkcs11,plugin,prompt,propertyIsEnum,radio,reset,screenX,screenY,scroll",
  181. "secure,select,self,setInterval,setTimeout,status,submit,taint,text,textarea,top,unescape",
  182. "untaint,window",
  183. // window events
  184. "onblur,onclick,onerror,onfocus,onkeydown,onkeypress,onkeyup,onmouseover,onload,onmouseup,onmousedown,onsubmit"
  185. ]
  186. .join(",")
  187. .split(",")
  188. );
  189. const createComparator = (property, comparator) => (a, b) =>
  190. comparator(a[property], b[property]);
  191. /**
  192. * @param {number} a a
  193. * @param {number} b b
  194. * @returns {0 | 1 | -1} result
  195. */
  196. const compareNumbers = (a, b) => {
  197. if (isNaN(a)) {
  198. if (!isNaN(b)) {
  199. return 1;
  200. }
  201. } else {
  202. if (isNaN(b)) {
  203. return -1;
  204. }
  205. if (a !== b) {
  206. return a < b ? -1 : 1;
  207. }
  208. }
  209. return 0;
  210. };
  211. const bySourceOrder = createComparator("sourceOrder", compareNumbers);
  212. const byRangeStart = createComparator("rangeStart", compareNumbers);
  213. /**
  214. * @param {Iterable<string>} iterable iterable object
  215. * @returns {string} joined iterable object
  216. */
  217. const joinIterableWithComma = iterable => {
  218. // This is more performant than Array.from().join(", ")
  219. // as it doesn't create an array
  220. let str = "";
  221. let first = true;
  222. for (const item of iterable) {
  223. if (first) {
  224. first = false;
  225. } else {
  226. str += ", ";
  227. }
  228. str += item;
  229. }
  230. return str;
  231. };
  232. /**
  233. * @typedef {object} ConcatenationEntry
  234. * @property {"concatenated" | "external"} type
  235. * @property {Module} module
  236. * @property {RuntimeSpec | boolean} runtimeCondition
  237. */
  238. /**
  239. * @param {ModuleGraph} moduleGraph the module graph
  240. * @param {ModuleInfo} info module info
  241. * @param {string[]} exportName exportName
  242. * @param {Map<Module, ModuleInfo>} moduleToInfoMap moduleToInfoMap
  243. * @param {RuntimeSpec} runtime for which runtime
  244. * @param {RequestShortener} requestShortener the request shortener
  245. * @param {RuntimeTemplate} runtimeTemplate the runtime template
  246. * @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
  247. * @param {boolean} asCall asCall
  248. * @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
  249. * @param {boolean | undefined} asiSafe asiSafe
  250. * @param {Set<ExportInfo>} alreadyVisited alreadyVisited
  251. * @returns {Binding} the final variable
  252. */
  253. const getFinalBinding = (
  254. moduleGraph,
  255. info,
  256. exportName,
  257. moduleToInfoMap,
  258. runtime,
  259. requestShortener,
  260. runtimeTemplate,
  261. neededNamespaceObjects,
  262. asCall,
  263. strictHarmonyModule,
  264. asiSafe,
  265. alreadyVisited = new Set()
  266. ) => {
  267. const exportsType = info.module.getExportsType(
  268. moduleGraph,
  269. strictHarmonyModule
  270. );
  271. if (exportName.length === 0) {
  272. switch (exportsType) {
  273. case "default-only":
  274. info.interopNamespaceObject2Used = true;
  275. return {
  276. info,
  277. rawName: /** @type {string} */ (info.interopNamespaceObject2Name),
  278. ids: exportName,
  279. exportName
  280. };
  281. case "default-with-named":
  282. info.interopNamespaceObjectUsed = true;
  283. return {
  284. info,
  285. rawName: /** @type {string} */ (info.interopNamespaceObjectName),
  286. ids: exportName,
  287. exportName
  288. };
  289. case "namespace":
  290. case "dynamic":
  291. break;
  292. default:
  293. throw new Error(`Unexpected exportsType ${exportsType}`);
  294. }
  295. } else {
  296. switch (exportsType) {
  297. case "namespace":
  298. break;
  299. case "default-with-named":
  300. switch (exportName[0]) {
  301. case "default":
  302. exportName = exportName.slice(1);
  303. break;
  304. case "__esModule":
  305. return {
  306. info,
  307. rawName: "/* __esModule */true",
  308. ids: exportName.slice(1),
  309. exportName
  310. };
  311. }
  312. break;
  313. case "default-only": {
  314. const exportId = exportName[0];
  315. if (exportId === "__esModule") {
  316. return {
  317. info,
  318. rawName: "/* __esModule */true",
  319. ids: exportName.slice(1),
  320. exportName
  321. };
  322. }
  323. exportName = exportName.slice(1);
  324. if (exportId !== "default") {
  325. return {
  326. info,
  327. rawName:
  328. "/* non-default import from default-exporting module */undefined",
  329. ids: exportName,
  330. exportName
  331. };
  332. }
  333. break;
  334. }
  335. case "dynamic":
  336. switch (exportName[0]) {
  337. case "default": {
  338. exportName = exportName.slice(1);
  339. info.interopDefaultAccessUsed = true;
  340. const defaultExport = asCall
  341. ? `${info.interopDefaultAccessName}()`
  342. : asiSafe
  343. ? `(${info.interopDefaultAccessName}())`
  344. : asiSafe === false
  345. ? `;(${info.interopDefaultAccessName}())`
  346. : `${info.interopDefaultAccessName}.a`;
  347. return {
  348. info,
  349. rawName: defaultExport,
  350. ids: exportName,
  351. exportName
  352. };
  353. }
  354. case "__esModule":
  355. return {
  356. info,
  357. rawName: "/* __esModule */true",
  358. ids: exportName.slice(1),
  359. exportName
  360. };
  361. }
  362. break;
  363. default:
  364. throw new Error(`Unexpected exportsType ${exportsType}`);
  365. }
  366. }
  367. if (exportName.length === 0) {
  368. switch (info.type) {
  369. case "concatenated":
  370. neededNamespaceObjects.add(info);
  371. return {
  372. info,
  373. rawName: /** @type {string} */ (info.namespaceObjectName),
  374. ids: exportName,
  375. exportName
  376. };
  377. case "external":
  378. return { info, rawName: info.name, ids: exportName, exportName };
  379. }
  380. }
  381. const exportsInfo = moduleGraph.getExportsInfo(info.module);
  382. const exportInfo = exportsInfo.getExportInfo(exportName[0]);
  383. if (alreadyVisited.has(exportInfo)) {
  384. return {
  385. info,
  386. rawName: "/* circular reexport */ Object(function x() { x() }())",
  387. ids: [],
  388. exportName
  389. };
  390. }
  391. alreadyVisited.add(exportInfo);
  392. switch (info.type) {
  393. case "concatenated": {
  394. const exportId = exportName[0];
  395. if (exportInfo.provided === false) {
  396. // It's not provided, but it could be on the prototype
  397. neededNamespaceObjects.add(info);
  398. return {
  399. info,
  400. rawName: /** @type {string} */ (info.namespaceObjectName),
  401. ids: exportName,
  402. exportName
  403. };
  404. }
  405. const directExport = info.exportMap && info.exportMap.get(exportId);
  406. if (directExport) {
  407. const usedName = /** @type {string[]} */ (
  408. exportsInfo.getUsedName(exportName, runtime)
  409. );
  410. if (!usedName) {
  411. return {
  412. info,
  413. rawName: "/* unused export */ undefined",
  414. ids: exportName.slice(1),
  415. exportName
  416. };
  417. }
  418. return {
  419. info,
  420. name: directExport,
  421. ids: usedName.slice(1),
  422. exportName
  423. };
  424. }
  425. const rawExport = info.rawExportMap && info.rawExportMap.get(exportId);
  426. if (rawExport) {
  427. return {
  428. info,
  429. rawName: rawExport,
  430. ids: exportName.slice(1),
  431. exportName
  432. };
  433. }
  434. const reexport = exportInfo.findTarget(moduleGraph, module =>
  435. moduleToInfoMap.has(module)
  436. );
  437. if (reexport === false) {
  438. throw new Error(
  439. `Target module of reexport from '${info.module.readableIdentifier(
  440. requestShortener
  441. )}' is not part of the concatenation (export '${exportId}')\nModules in the concatenation:\n${Array.from(
  442. moduleToInfoMap,
  443. ([m, info]) =>
  444. ` * ${info.type} ${m.readableIdentifier(requestShortener)}`
  445. ).join("\n")}`
  446. );
  447. }
  448. if (reexport) {
  449. const refInfo = moduleToInfoMap.get(reexport.module);
  450. return getFinalBinding(
  451. moduleGraph,
  452. /** @type {ModuleInfo} */ (refInfo),
  453. reexport.export
  454. ? [...reexport.export, ...exportName.slice(1)]
  455. : exportName.slice(1),
  456. moduleToInfoMap,
  457. runtime,
  458. requestShortener,
  459. runtimeTemplate,
  460. neededNamespaceObjects,
  461. asCall,
  462. /** @type {BuildMeta} */
  463. (info.module.buildMeta).strictHarmonyModule,
  464. asiSafe,
  465. alreadyVisited
  466. );
  467. }
  468. if (info.namespaceExportSymbol) {
  469. const usedName = /** @type {string[]} */ (
  470. exportsInfo.getUsedName(exportName, runtime)
  471. );
  472. return {
  473. info,
  474. rawName: /** @type {string} */ (info.namespaceObjectName),
  475. ids: usedName,
  476. exportName
  477. };
  478. }
  479. throw new Error(
  480. `Cannot get final name for export '${exportName.join(
  481. "."
  482. )}' of ${info.module.readableIdentifier(requestShortener)}`
  483. );
  484. }
  485. case "external": {
  486. const used = /** @type {string[]} */ (
  487. exportsInfo.getUsedName(exportName, runtime)
  488. );
  489. if (!used) {
  490. return {
  491. info,
  492. rawName: "/* unused export */ undefined",
  493. ids: exportName.slice(1),
  494. exportName
  495. };
  496. }
  497. const comment = equals(used, exportName)
  498. ? ""
  499. : Template.toNormalComment(`${exportName.join(".")}`);
  500. return { info, rawName: info.name + comment, ids: used, exportName };
  501. }
  502. }
  503. };
  504. /**
  505. * @param {ModuleGraph} moduleGraph the module graph
  506. * @param {ModuleInfo} info module info
  507. * @param {string[]} exportName exportName
  508. * @param {Map<Module, ModuleInfo>} moduleToInfoMap moduleToInfoMap
  509. * @param {RuntimeSpec} runtime for which runtime
  510. * @param {RequestShortener} requestShortener the request shortener
  511. * @param {RuntimeTemplate} runtimeTemplate the runtime template
  512. * @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
  513. * @param {boolean} asCall asCall
  514. * @param {boolean | undefined} callContext callContext
  515. * @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
  516. * @param {boolean | undefined} asiSafe asiSafe
  517. * @returns {string} the final name
  518. */
  519. const getFinalName = (
  520. moduleGraph,
  521. info,
  522. exportName,
  523. moduleToInfoMap,
  524. runtime,
  525. requestShortener,
  526. runtimeTemplate,
  527. neededNamespaceObjects,
  528. asCall,
  529. callContext,
  530. strictHarmonyModule,
  531. asiSafe
  532. ) => {
  533. const binding = getFinalBinding(
  534. moduleGraph,
  535. info,
  536. exportName,
  537. moduleToInfoMap,
  538. runtime,
  539. requestShortener,
  540. runtimeTemplate,
  541. neededNamespaceObjects,
  542. asCall,
  543. strictHarmonyModule,
  544. asiSafe
  545. );
  546. {
  547. const { ids, comment } = binding;
  548. let reference;
  549. let isPropertyAccess;
  550. if ("rawName" in binding) {
  551. reference = `${binding.rawName}${comment || ""}${propertyAccess(ids)}`;
  552. isPropertyAccess = ids.length > 0;
  553. } else {
  554. const { info, name: exportId } = binding;
  555. const name = info.internalNames.get(exportId);
  556. if (!name) {
  557. throw new Error(
  558. `The export "${exportId}" in "${info.module.readableIdentifier(
  559. requestShortener
  560. )}" has no internal name (existing names: ${
  561. Array.from(
  562. info.internalNames,
  563. ([name, symbol]) => `${name}: ${symbol}`
  564. ).join(", ") || "none"
  565. })`
  566. );
  567. }
  568. reference = `${name}${comment || ""}${propertyAccess(ids)}`;
  569. isPropertyAccess = ids.length > 1;
  570. }
  571. if (isPropertyAccess && asCall && callContext === false) {
  572. return asiSafe
  573. ? `(0,${reference})`
  574. : asiSafe === false
  575. ? `;(0,${reference})`
  576. : `/*#__PURE__*/Object(${reference})`;
  577. }
  578. return reference;
  579. }
  580. };
  581. /**
  582. * @param {Scope | null} s scope
  583. * @param {UsedNames} nameSet name set
  584. * @param {TODO} scopeSet1 scope set 1
  585. * @param {TODO} scopeSet2 scope set 2
  586. */
  587. const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
  588. let scope = s;
  589. while (scope) {
  590. if (scopeSet1.has(scope)) break;
  591. if (scopeSet2.has(scope)) break;
  592. scopeSet1.add(scope);
  593. for (const variable of scope.variables) {
  594. nameSet.add(variable.name);
  595. }
  596. scope = scope.upper;
  597. }
  598. };
  599. const TYPES = new Set(["javascript"]);
  600. class ConcatenatedModule extends Module {
  601. /**
  602. * @param {Module} rootModule the root module of the concatenation
  603. * @param {Set<Module>} modules all modules in the concatenation (including the root module)
  604. * @param {RuntimeSpec} runtime the runtime
  605. * @param {object=} associatedObjectForCache object for caching
  606. * @param {string | HashConstructor=} hashFunction hash function to use
  607. * @returns {ConcatenatedModule} the module
  608. */
  609. static create(
  610. rootModule,
  611. modules,
  612. runtime,
  613. associatedObjectForCache,
  614. hashFunction = "md4"
  615. ) {
  616. const identifier = ConcatenatedModule._createIdentifier(
  617. rootModule,
  618. modules,
  619. associatedObjectForCache,
  620. hashFunction
  621. );
  622. return new ConcatenatedModule({
  623. identifier,
  624. rootModule,
  625. modules,
  626. runtime
  627. });
  628. }
  629. /**
  630. * @param {object} options options
  631. * @param {string} options.identifier the identifier of the module
  632. * @param {Module=} options.rootModule the root module of the concatenation
  633. * @param {RuntimeSpec} options.runtime the selected runtime
  634. * @param {Set<Module>=} options.modules all concatenated modules
  635. */
  636. constructor({ identifier, rootModule, modules, runtime }) {
  637. super(JAVASCRIPT_MODULE_TYPE_ESM, null, rootModule && rootModule.layer);
  638. // Info from Factory
  639. /** @type {string} */
  640. this._identifier = identifier;
  641. /** @type {Module} */
  642. this.rootModule = rootModule;
  643. /** @type {Set<Module>} */
  644. this._modules = modules;
  645. this._runtime = runtime;
  646. this.factoryMeta = rootModule && rootModule.factoryMeta;
  647. }
  648. /**
  649. * Assuming this module is in the cache. Update the (cached) module with
  650. * the fresh module from the factory. Usually updates internal references
  651. * and properties.
  652. * @param {Module} module fresh module
  653. * @returns {void}
  654. */
  655. updateCacheModule(module) {
  656. throw new Error("Must not be called");
  657. }
  658. /**
  659. * @returns {SourceTypes} types available (do not mutate)
  660. */
  661. getSourceTypes() {
  662. return TYPES;
  663. }
  664. get modules() {
  665. return Array.from(this._modules);
  666. }
  667. /**
  668. * @returns {string} a unique identifier of the module
  669. */
  670. identifier() {
  671. return this._identifier;
  672. }
  673. /**
  674. * @param {RequestShortener} requestShortener the request shortener
  675. * @returns {string} a user readable identifier of the module
  676. */
  677. readableIdentifier(requestShortener) {
  678. return (
  679. this.rootModule.readableIdentifier(requestShortener) +
  680. ` + ${this._modules.size - 1} modules`
  681. );
  682. }
  683. /**
  684. * @param {LibIdentOptions} options options
  685. * @returns {string | null} an identifier for library inclusion
  686. */
  687. libIdent(options) {
  688. return this.rootModule.libIdent(options);
  689. }
  690. /**
  691. * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)
  692. */
  693. nameForCondition() {
  694. return this.rootModule.nameForCondition();
  695. }
  696. /**
  697. * @param {ModuleGraph} moduleGraph the module graph
  698. * @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
  699. */
  700. getSideEffectsConnectionState(moduleGraph) {
  701. return this.rootModule.getSideEffectsConnectionState(moduleGraph);
  702. }
  703. /**
  704. * @param {WebpackOptions} options webpack options
  705. * @param {Compilation} compilation the compilation
  706. * @param {ResolverWithOptions} resolver the resolver
  707. * @param {InputFileSystem} fs the file system
  708. * @param {function(WebpackError=): void} callback callback function
  709. * @returns {void}
  710. */
  711. build(options, compilation, resolver, fs, callback) {
  712. const { rootModule } = this;
  713. const { moduleArgument, exportsArgument } =
  714. /** @type {BuildInfo} */
  715. (rootModule.buildInfo);
  716. this.buildInfo = {
  717. strict: true,
  718. cacheable: true,
  719. moduleArgument,
  720. exportsArgument,
  721. fileDependencies: new LazySet(),
  722. contextDependencies: new LazySet(),
  723. missingDependencies: new LazySet(),
  724. topLevelDeclarations: new Set(),
  725. assets: undefined
  726. };
  727. this.buildMeta = rootModule.buildMeta;
  728. this.clearDependenciesAndBlocks();
  729. this.clearWarningsAndErrors();
  730. for (const m of this._modules) {
  731. // populate cacheable
  732. if (!(/** @type {BuildInfo} */ (m.buildInfo).cacheable)) {
  733. this.buildInfo.cacheable = false;
  734. }
  735. // populate dependencies
  736. for (const d of m.dependencies.filter(
  737. dep =>
  738. !(dep instanceof HarmonyImportDependency) ||
  739. !this._modules.has(
  740. /** @type {Module} */ (compilation.moduleGraph.getModule(dep))
  741. )
  742. )) {
  743. this.dependencies.push(d);
  744. }
  745. // populate blocks
  746. for (const d of m.blocks) {
  747. this.blocks.push(d);
  748. }
  749. // populate warnings
  750. const warnings = m.getWarnings();
  751. if (warnings !== undefined) {
  752. for (const warning of warnings) {
  753. this.addWarning(warning);
  754. }
  755. }
  756. // populate errors
  757. const errors = m.getErrors();
  758. if (errors !== undefined) {
  759. for (const error of errors) {
  760. this.addError(error);
  761. }
  762. }
  763. const { assets, assetsInfo, topLevelDeclarations } =
  764. /** @type {BuildInfo} */ (m.buildInfo);
  765. // populate topLevelDeclarations
  766. if (topLevelDeclarations) {
  767. const topLevelDeclarations = this.buildInfo.topLevelDeclarations;
  768. if (topLevelDeclarations !== undefined) {
  769. for (const decl of topLevelDeclarations) {
  770. topLevelDeclarations.add(decl);
  771. }
  772. }
  773. } else {
  774. this.buildInfo.topLevelDeclarations = undefined;
  775. }
  776. // populate assets
  777. if (assets) {
  778. if (this.buildInfo.assets === undefined) {
  779. this.buildInfo.assets = Object.create(null);
  780. }
  781. Object.assign(/** @type {BuildInfo} */ (this.buildInfo).assets, assets);
  782. }
  783. if (assetsInfo) {
  784. if (this.buildInfo.assetsInfo === undefined) {
  785. this.buildInfo.assetsInfo = new Map();
  786. }
  787. for (const [key, value] of assetsInfo) {
  788. this.buildInfo.assetsInfo.set(key, value);
  789. }
  790. }
  791. }
  792. callback();
  793. }
  794. /**
  795. * @param {string=} type the source type for which the size should be estimated
  796. * @returns {number} the estimated size of the module (must be non-zero)
  797. */
  798. size(type) {
  799. // Guess size from embedded modules
  800. let size = 0;
  801. for (const module of this._modules) {
  802. size += module.size(type);
  803. }
  804. return size;
  805. }
  806. /**
  807. * @private
  808. * @param {Module} rootModule the root of the concatenation
  809. * @param {Set<Module>} modulesSet a set of modules which should be concatenated
  810. * @param {RuntimeSpec} runtime for this runtime
  811. * @param {ModuleGraph} moduleGraph the module graph
  812. * @returns {ConcatenationEntry[]} concatenation list
  813. */
  814. _createConcatenationList(rootModule, modulesSet, runtime, moduleGraph) {
  815. /** @type {ConcatenationEntry[]} */
  816. const list = [];
  817. /** @type {Map<Module, RuntimeSpec | true>} */
  818. const existingEntries = new Map();
  819. /**
  820. * @param {Module} module a module
  821. * @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} imported modules in order
  822. */
  823. const getConcatenatedImports = module => {
  824. let connections = Array.from(moduleGraph.getOutgoingConnections(module));
  825. if (module === rootModule) {
  826. for (const c of moduleGraph.getOutgoingConnections(this))
  827. connections.push(c);
  828. }
  829. /**
  830. * @type {Array<{ connection: ModuleGraphConnection, sourceOrder: number, rangeStart: number }>}
  831. */
  832. const references = connections
  833. .filter(connection => {
  834. if (!(connection.dependency instanceof HarmonyImportDependency))
  835. return false;
  836. return (
  837. connection &&
  838. connection.resolvedOriginModule === module &&
  839. connection.module &&
  840. connection.isTargetActive(runtime)
  841. );
  842. })
  843. .map(connection => {
  844. const dep = /** @type {HarmonyImportDependency} */ (
  845. connection.dependency
  846. );
  847. return {
  848. connection,
  849. sourceOrder: dep.sourceOrder,
  850. rangeStart: dep.range && dep.range[0]
  851. };
  852. });
  853. /**
  854. * bySourceOrder
  855. * @example
  856. * import a from "a"; // sourceOrder=1
  857. * import b from "b"; // sourceOrder=2
  858. *
  859. * byRangeStart
  860. * @example
  861. * import {a, b} from "a"; // sourceOrder=1
  862. * a.a(); // first range
  863. * b.b(); // second range
  864. *
  865. * If there is no reexport, we have the same source.
  866. * If there is reexport, but module has side effects, this will lead to reexport module only.
  867. * If there is side-effects-free reexport, we can get simple deterministic result with range start comparison.
  868. */
  869. references.sort(concatComparators(bySourceOrder, byRangeStart));
  870. /** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */
  871. const referencesMap = new Map();
  872. for (const { connection } of references) {
  873. const runtimeCondition = filterRuntime(runtime, r =>
  874. connection.isTargetActive(r)
  875. );
  876. if (runtimeCondition === false) continue;
  877. const module = connection.module;
  878. const entry = referencesMap.get(module);
  879. if (entry === undefined) {
  880. referencesMap.set(module, { connection, runtimeCondition });
  881. continue;
  882. }
  883. entry.runtimeCondition = mergeRuntimeConditionNonFalse(
  884. entry.runtimeCondition,
  885. runtimeCondition,
  886. runtime
  887. );
  888. }
  889. return referencesMap.values();
  890. };
  891. /**
  892. * @param {ModuleGraphConnection} connection graph connection
  893. * @param {RuntimeSpec | true} runtimeCondition runtime condition
  894. * @returns {void}
  895. */
  896. const enterModule = (connection, runtimeCondition) => {
  897. const module = connection.module;
  898. if (!module) return;
  899. const existingEntry = existingEntries.get(module);
  900. if (existingEntry === true) {
  901. return;
  902. }
  903. if (modulesSet.has(module)) {
  904. existingEntries.set(module, true);
  905. if (runtimeCondition !== true) {
  906. throw new Error(
  907. `Cannot runtime-conditional concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}, ${runtimeConditionToString(
  908. runtimeCondition
  909. )}). This should not happen.`
  910. );
  911. }
  912. const imports = getConcatenatedImports(module);
  913. for (const { connection, runtimeCondition } of imports)
  914. enterModule(connection, runtimeCondition);
  915. list.push({
  916. type: "concatenated",
  917. module: connection.module,
  918. runtimeCondition
  919. });
  920. } else {
  921. if (existingEntry !== undefined) {
  922. const reducedRuntimeCondition = subtractRuntimeCondition(
  923. runtimeCondition,
  924. existingEntry,
  925. runtime
  926. );
  927. if (reducedRuntimeCondition === false) return;
  928. runtimeCondition = reducedRuntimeCondition;
  929. existingEntries.set(
  930. connection.module,
  931. mergeRuntimeConditionNonFalse(
  932. existingEntry,
  933. runtimeCondition,
  934. runtime
  935. )
  936. );
  937. } else {
  938. existingEntries.set(connection.module, runtimeCondition);
  939. }
  940. if (list.length > 0) {
  941. const lastItem = list[list.length - 1];
  942. if (
  943. lastItem.type === "external" &&
  944. lastItem.module === connection.module
  945. ) {
  946. lastItem.runtimeCondition = mergeRuntimeCondition(
  947. lastItem.runtimeCondition,
  948. runtimeCondition,
  949. runtime
  950. );
  951. return;
  952. }
  953. }
  954. list.push({
  955. type: "external",
  956. get module() {
  957. // We need to use a getter here, because the module in the dependency
  958. // could be replaced by some other process (i. e. also replaced with a
  959. // concatenated module)
  960. return connection.module;
  961. },
  962. runtimeCondition
  963. });
  964. }
  965. };
  966. existingEntries.set(rootModule, true);
  967. const imports = getConcatenatedImports(rootModule);
  968. for (const { connection, runtimeCondition } of imports)
  969. enterModule(connection, runtimeCondition);
  970. list.push({
  971. type: "concatenated",
  972. module: rootModule,
  973. runtimeCondition: true
  974. });
  975. return list;
  976. }
  977. /**
  978. * @param {Module} rootModule the root module of the concatenation
  979. * @param {Set<Module>} modules all modules in the concatenation (including the root module)
  980. * @param {object=} associatedObjectForCache object for caching
  981. * @param {string | HashConstructor=} hashFunction hash function to use
  982. * @returns {string} the identifier
  983. */
  984. static _createIdentifier(
  985. rootModule,
  986. modules,
  987. associatedObjectForCache,
  988. hashFunction = "md4"
  989. ) {
  990. const cachedMakePathsRelative = makePathsRelative.bindContextCache(
  991. /** @type {string} */ (rootModule.context),
  992. associatedObjectForCache
  993. );
  994. let identifiers = [];
  995. for (const module of modules) {
  996. identifiers.push(cachedMakePathsRelative(module.identifier()));
  997. }
  998. identifiers.sort();
  999. const hash = createHash(hashFunction);
  1000. hash.update(identifiers.join(" "));
  1001. return rootModule.identifier() + "|" + hash.digest("hex");
  1002. }
  1003. /**
  1004. * @param {LazySet<string>} fileDependencies set where file dependencies are added to
  1005. * @param {LazySet<string>} contextDependencies set where context dependencies are added to
  1006. * @param {LazySet<string>} missingDependencies set where missing dependencies are added to
  1007. * @param {LazySet<string>} buildDependencies set where build dependencies are added to
  1008. */
  1009. addCacheDependencies(
  1010. fileDependencies,
  1011. contextDependencies,
  1012. missingDependencies,
  1013. buildDependencies
  1014. ) {
  1015. for (const module of this._modules) {
  1016. module.addCacheDependencies(
  1017. fileDependencies,
  1018. contextDependencies,
  1019. missingDependencies,
  1020. buildDependencies
  1021. );
  1022. }
  1023. }
  1024. /**
  1025. * @param {CodeGenerationContext} context context for code generation
  1026. * @returns {CodeGenerationResult} result
  1027. */
  1028. codeGeneration({
  1029. dependencyTemplates,
  1030. runtimeTemplate,
  1031. moduleGraph,
  1032. chunkGraph,
  1033. runtime: generationRuntime,
  1034. codeGenerationResults
  1035. }) {
  1036. /** @type {Set<string>} */
  1037. const runtimeRequirements = new Set();
  1038. const runtime = intersectRuntime(generationRuntime, this._runtime);
  1039. const requestShortener = runtimeTemplate.requestShortener;
  1040. // Meta info for each module
  1041. const [modulesWithInfo, moduleToInfoMap] = this._getModulesWithInfo(
  1042. moduleGraph,
  1043. runtime
  1044. );
  1045. // Set with modules that need a generated namespace object
  1046. /** @type {Set<ConcatenatedModuleInfo>} */
  1047. const neededNamespaceObjects = new Set();
  1048. // Generate source code and analyse scopes
  1049. // Prepare a ReplaceSource for the final source
  1050. for (const info of moduleToInfoMap.values()) {
  1051. this._analyseModule(
  1052. moduleToInfoMap,
  1053. info,
  1054. dependencyTemplates,
  1055. runtimeTemplate,
  1056. moduleGraph,
  1057. chunkGraph,
  1058. runtime,
  1059. codeGenerationResults
  1060. );
  1061. }
  1062. // List of all used names to avoid conflicts
  1063. const allUsedNames = new Set(RESERVED_NAMES);
  1064. // Updated Top level declarations are created by renaming
  1065. const topLevelDeclarations = new Set();
  1066. // List of additional names in scope for module references
  1067. /** @type {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} */
  1068. const usedNamesInScopeInfo = new Map();
  1069. /**
  1070. * @param {string} module module identifier
  1071. * @param {string} id export id
  1072. * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
  1073. */
  1074. const getUsedNamesInScopeInfo = (module, id) => {
  1075. const key = `${module}-${id}`;
  1076. let info = usedNamesInScopeInfo.get(key);
  1077. if (info === undefined) {
  1078. info = {
  1079. usedNames: new Set(),
  1080. alreadyCheckedScopes: new Set()
  1081. };
  1082. usedNamesInScopeInfo.set(key, info);
  1083. }
  1084. return info;
  1085. };
  1086. // Set of already checked scopes
  1087. const ignoredScopes = new Set();
  1088. // get all global names
  1089. for (const info of modulesWithInfo) {
  1090. if (info.type === "concatenated") {
  1091. // ignore symbols from moduleScope
  1092. if (info.moduleScope) {
  1093. ignoredScopes.add(info.moduleScope);
  1094. }
  1095. // The super class expression in class scopes behaves weird
  1096. // We get ranges of all super class expressions to make
  1097. // renaming to work correctly
  1098. const superClassCache = new WeakMap();
  1099. /**
  1100. * @param {Scope} scope scope
  1101. * @returns {TODO} result
  1102. */
  1103. const getSuperClassExpressions = scope => {
  1104. const cacheEntry = superClassCache.get(scope);
  1105. if (cacheEntry !== undefined) return cacheEntry;
  1106. const superClassExpressions = [];
  1107. for (const childScope of scope.childScopes) {
  1108. if (childScope.type !== "class") continue;
  1109. const block = childScope.block;
  1110. if (
  1111. (block.type === "ClassDeclaration" ||
  1112. block.type === "ClassExpression") &&
  1113. block.superClass
  1114. ) {
  1115. superClassExpressions.push({
  1116. range: block.superClass.range,
  1117. variables: childScope.variables
  1118. });
  1119. }
  1120. }
  1121. superClassCache.set(scope, superClassExpressions);
  1122. return superClassExpressions;
  1123. };
  1124. // add global symbols
  1125. if (info.globalScope) {
  1126. for (const reference of info.globalScope.through) {
  1127. const name = reference.identifier.name;
  1128. if (ConcatenationScope.isModuleReference(name)) {
  1129. const match = ConcatenationScope.matchModuleReference(name);
  1130. if (!match) continue;
  1131. const referencedInfo = modulesWithInfo[match.index];
  1132. if (referencedInfo.type === "reference")
  1133. throw new Error("Module reference can't point to a reference");
  1134. const binding = getFinalBinding(
  1135. moduleGraph,
  1136. referencedInfo,
  1137. match.ids,
  1138. moduleToInfoMap,
  1139. runtime,
  1140. requestShortener,
  1141. runtimeTemplate,
  1142. neededNamespaceObjects,
  1143. false,
  1144. /** @type {BuildMeta} */
  1145. (info.module.buildMeta).strictHarmonyModule,
  1146. true
  1147. );
  1148. if (!binding.ids) continue;
  1149. const { usedNames, alreadyCheckedScopes } =
  1150. getUsedNamesInScopeInfo(
  1151. binding.info.module.identifier(),
  1152. "name" in binding ? binding.name : ""
  1153. );
  1154. for (const expr of getSuperClassExpressions(reference.from)) {
  1155. if (
  1156. expr.range[0] <=
  1157. /** @type {Range} */ (reference.identifier.range)[0] &&
  1158. expr.range[1] >=
  1159. /** @type {Range} */ (reference.identifier.range)[1]
  1160. ) {
  1161. for (const variable of expr.variables) {
  1162. usedNames.add(variable.name);
  1163. }
  1164. }
  1165. }
  1166. addScopeSymbols(
  1167. reference.from,
  1168. usedNames,
  1169. alreadyCheckedScopes,
  1170. ignoredScopes
  1171. );
  1172. } else {
  1173. allUsedNames.add(name);
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. // generate names for symbols
  1180. for (const info of moduleToInfoMap.values()) {
  1181. const { usedNames: namespaceObjectUsedNames } = getUsedNamesInScopeInfo(
  1182. info.module.identifier(),
  1183. ""
  1184. );
  1185. switch (info.type) {
  1186. case "concatenated": {
  1187. for (const variable of info.moduleScope.variables) {
  1188. const name = variable.name;
  1189. const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
  1190. info.module.identifier(),
  1191. name
  1192. );
  1193. if (allUsedNames.has(name) || usedNames.has(name)) {
  1194. const references = getAllReferences(variable);
  1195. for (const ref of references) {
  1196. addScopeSymbols(
  1197. ref.from,
  1198. usedNames,
  1199. alreadyCheckedScopes,
  1200. ignoredScopes
  1201. );
  1202. }
  1203. const newName = this.findNewName(
  1204. name,
  1205. allUsedNames,
  1206. usedNames,
  1207. info.module.readableIdentifier(requestShortener)
  1208. );
  1209. allUsedNames.add(newName);
  1210. info.internalNames.set(name, newName);
  1211. topLevelDeclarations.add(newName);
  1212. const source = info.source;
  1213. const allIdentifiers = new Set(
  1214. references.map(r => r.identifier).concat(variable.identifiers)
  1215. );
  1216. for (const identifier of allIdentifiers) {
  1217. const r = /** @type {Range} */ (identifier.range);
  1218. const path = getPathInAst(info.ast, identifier);
  1219. if (path && path.length > 1) {
  1220. const maybeProperty =
  1221. path[1].type === "AssignmentPattern" &&
  1222. path[1].left === path[0]
  1223. ? path[2]
  1224. : path[1];
  1225. if (
  1226. maybeProperty.type === "Property" &&
  1227. maybeProperty.shorthand
  1228. ) {
  1229. source.insert(r[1], `: ${newName}`);
  1230. continue;
  1231. }
  1232. }
  1233. source.replace(r[0], r[1] - 1, newName);
  1234. }
  1235. } else {
  1236. allUsedNames.add(name);
  1237. info.internalNames.set(name, name);
  1238. topLevelDeclarations.add(name);
  1239. }
  1240. }
  1241. let namespaceObjectName;
  1242. if (info.namespaceExportSymbol) {
  1243. namespaceObjectName = info.internalNames.get(
  1244. info.namespaceExportSymbol
  1245. );
  1246. } else {
  1247. namespaceObjectName = this.findNewName(
  1248. "namespaceObject",
  1249. allUsedNames,
  1250. namespaceObjectUsedNames,
  1251. info.module.readableIdentifier(requestShortener)
  1252. );
  1253. allUsedNames.add(namespaceObjectName);
  1254. }
  1255. info.namespaceObjectName =
  1256. /** @type {string} */
  1257. (namespaceObjectName);
  1258. topLevelDeclarations.add(namespaceObjectName);
  1259. break;
  1260. }
  1261. case "external": {
  1262. const externalName = this.findNewName(
  1263. "",
  1264. allUsedNames,
  1265. namespaceObjectUsedNames,
  1266. info.module.readableIdentifier(requestShortener)
  1267. );
  1268. allUsedNames.add(externalName);
  1269. info.name = externalName;
  1270. topLevelDeclarations.add(externalName);
  1271. break;
  1272. }
  1273. }
  1274. const buildMeta = /** @type {BuildMeta} */ (info.module.buildMeta);
  1275. if (buildMeta.exportsType !== "namespace") {
  1276. const externalNameInterop = this.findNewName(
  1277. "namespaceObject",
  1278. allUsedNames,
  1279. namespaceObjectUsedNames,
  1280. info.module.readableIdentifier(requestShortener)
  1281. );
  1282. allUsedNames.add(externalNameInterop);
  1283. info.interopNamespaceObjectName = externalNameInterop;
  1284. topLevelDeclarations.add(externalNameInterop);
  1285. }
  1286. if (
  1287. buildMeta.exportsType === "default" &&
  1288. buildMeta.defaultObject !== "redirect"
  1289. ) {
  1290. const externalNameInterop = this.findNewName(
  1291. "namespaceObject2",
  1292. allUsedNames,
  1293. namespaceObjectUsedNames,
  1294. info.module.readableIdentifier(requestShortener)
  1295. );
  1296. allUsedNames.add(externalNameInterop);
  1297. info.interopNamespaceObject2Name = externalNameInterop;
  1298. topLevelDeclarations.add(externalNameInterop);
  1299. }
  1300. if (buildMeta.exportsType === "dynamic" || !buildMeta.exportsType) {
  1301. const externalNameInterop = this.findNewName(
  1302. "default",
  1303. allUsedNames,
  1304. namespaceObjectUsedNames,
  1305. info.module.readableIdentifier(requestShortener)
  1306. );
  1307. allUsedNames.add(externalNameInterop);
  1308. info.interopDefaultAccessName = externalNameInterop;
  1309. topLevelDeclarations.add(externalNameInterop);
  1310. }
  1311. }
  1312. // Find and replace references to modules
  1313. for (const info of moduleToInfoMap.values()) {
  1314. if (info.type === "concatenated") {
  1315. for (const reference of info.globalScope.through) {
  1316. const name = reference.identifier.name;
  1317. const match = ConcatenationScope.matchModuleReference(name);
  1318. if (match) {
  1319. const referencedInfo = modulesWithInfo[match.index];
  1320. if (referencedInfo.type === "reference")
  1321. throw new Error("Module reference can't point to a reference");
  1322. const finalName = getFinalName(
  1323. moduleGraph,
  1324. referencedInfo,
  1325. match.ids,
  1326. moduleToInfoMap,
  1327. runtime,
  1328. requestShortener,
  1329. runtimeTemplate,
  1330. neededNamespaceObjects,
  1331. match.call,
  1332. !match.directImport,
  1333. /** @type {BuildMeta} */
  1334. (info.module.buildMeta).strictHarmonyModule,
  1335. match.asiSafe
  1336. );
  1337. const r = /** @type {Range} */ (reference.identifier.range);
  1338. const source = info.source;
  1339. // range is extended by 2 chars to cover the appended "._"
  1340. source.replace(r[0], r[1] + 1, finalName);
  1341. }
  1342. }
  1343. }
  1344. }
  1345. // Map with all root exposed used exports
  1346. /** @type {Map<string, function(RequestShortener): string>} */
  1347. const exportsMap = new Map();
  1348. // Set with all root exposed unused exports
  1349. /** @type {Set<string>} */
  1350. const unusedExports = new Set();
  1351. const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
  1352. moduleToInfoMap.get(this.rootModule)
  1353. );
  1354. const strictHarmonyModule =
  1355. /** @type {BuildMeta} */
  1356. (rootInfo.module.buildMeta).strictHarmonyModule;
  1357. const exportsInfo = moduleGraph.getExportsInfo(rootInfo.module);
  1358. for (const exportInfo of exportsInfo.orderedExports) {
  1359. const name = exportInfo.name;
  1360. if (exportInfo.provided === false) continue;
  1361. const used = exportInfo.getUsedName(undefined, runtime);
  1362. if (!used) {
  1363. unusedExports.add(name);
  1364. continue;
  1365. }
  1366. exportsMap.set(used, requestShortener => {
  1367. try {
  1368. const finalName = getFinalName(
  1369. moduleGraph,
  1370. rootInfo,
  1371. [name],
  1372. moduleToInfoMap,
  1373. runtime,
  1374. requestShortener,
  1375. runtimeTemplate,
  1376. neededNamespaceObjects,
  1377. false,
  1378. false,
  1379. strictHarmonyModule,
  1380. true
  1381. );
  1382. return `/* ${
  1383. exportInfo.isReexport() ? "reexport" : "binding"
  1384. } */ ${finalName}`;
  1385. } catch (e) {
  1386. /** @type {Error} */
  1387. (e).message +=
  1388. `\nwhile generating the root export '${name}' (used name: '${used}')`;
  1389. throw e;
  1390. }
  1391. });
  1392. }
  1393. const result = new ConcatSource();
  1394. // add harmony compatibility flag (must be first because of possible circular dependencies)
  1395. if (
  1396. moduleGraph.getExportsInfo(this).otherExportsInfo.getUsed(runtime) !==
  1397. UsageState.Unused
  1398. ) {
  1399. result.add(`// ESM COMPAT FLAG\n`);
  1400. result.add(
  1401. runtimeTemplate.defineEsModuleFlagStatement({
  1402. exportsArgument: this.exportsArgument,
  1403. runtimeRequirements
  1404. })
  1405. );
  1406. }
  1407. // define exports
  1408. if (exportsMap.size > 0) {
  1409. runtimeRequirements.add(RuntimeGlobals.exports);
  1410. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1411. const definitions = [];
  1412. for (const [key, value] of exportsMap) {
  1413. definitions.push(
  1414. `\n ${propertyName(key)}: ${runtimeTemplate.returningFunction(
  1415. value(requestShortener)
  1416. )}`
  1417. );
  1418. }
  1419. result.add(`\n// EXPORTS\n`);
  1420. result.add(
  1421. `${RuntimeGlobals.definePropertyGetters}(${
  1422. this.exportsArgument
  1423. }, {${definitions.join(",")}\n});\n`
  1424. );
  1425. }
  1426. // list unused exports
  1427. if (unusedExports.size > 0) {
  1428. result.add(
  1429. `\n// UNUSED EXPORTS: ${joinIterableWithComma(unusedExports)}\n`
  1430. );
  1431. }
  1432. // generate namespace objects
  1433. const namespaceObjectSources = new Map();
  1434. for (const info of neededNamespaceObjects) {
  1435. if (info.namespaceExportSymbol) continue;
  1436. const nsObj = [];
  1437. const exportsInfo = moduleGraph.getExportsInfo(info.module);
  1438. for (const exportInfo of exportsInfo.orderedExports) {
  1439. if (exportInfo.provided === false) continue;
  1440. const usedName = exportInfo.getUsedName(undefined, runtime);
  1441. if (usedName) {
  1442. const finalName = getFinalName(
  1443. moduleGraph,
  1444. info,
  1445. [exportInfo.name],
  1446. moduleToInfoMap,
  1447. runtime,
  1448. requestShortener,
  1449. runtimeTemplate,
  1450. neededNamespaceObjects,
  1451. false,
  1452. undefined,
  1453. /** @type {BuildMeta} */
  1454. (info.module.buildMeta).strictHarmonyModule,
  1455. true
  1456. );
  1457. nsObj.push(
  1458. `\n ${propertyName(usedName)}: ${runtimeTemplate.returningFunction(
  1459. finalName
  1460. )}`
  1461. );
  1462. }
  1463. }
  1464. const name = info.namespaceObjectName;
  1465. const defineGetters =
  1466. nsObj.length > 0
  1467. ? `${RuntimeGlobals.definePropertyGetters}(${name}, {${nsObj.join(
  1468. ","
  1469. )}\n});\n`
  1470. : "";
  1471. if (nsObj.length > 0)
  1472. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1473. namespaceObjectSources.set(
  1474. info,
  1475. `
  1476. // NAMESPACE OBJECT: ${info.module.readableIdentifier(requestShortener)}
  1477. var ${name} = {};
  1478. ${RuntimeGlobals.makeNamespaceObject}(${name});
  1479. ${defineGetters}`
  1480. );
  1481. runtimeRequirements.add(RuntimeGlobals.makeNamespaceObject);
  1482. }
  1483. // define required namespace objects (must be before evaluation modules)
  1484. for (const info of modulesWithInfo) {
  1485. if (info.type === "concatenated") {
  1486. const source = namespaceObjectSources.get(info);
  1487. if (!source) continue;
  1488. result.add(source);
  1489. }
  1490. }
  1491. const chunkInitFragments = [];
  1492. // evaluate modules in order
  1493. for (const rawInfo of modulesWithInfo) {
  1494. let name;
  1495. let isConditional = false;
  1496. const info = rawInfo.type === "reference" ? rawInfo.target : rawInfo;
  1497. switch (info.type) {
  1498. case "concatenated": {
  1499. result.add(
  1500. `\n;// CONCATENATED MODULE: ${info.module.readableIdentifier(
  1501. requestShortener
  1502. )}\n`
  1503. );
  1504. result.add(info.source);
  1505. if (info.chunkInitFragments) {
  1506. for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
  1507. }
  1508. if (info.runtimeRequirements) {
  1509. for (const r of info.runtimeRequirements) {
  1510. runtimeRequirements.add(r);
  1511. }
  1512. }
  1513. name = info.namespaceObjectName;
  1514. break;
  1515. }
  1516. case "external": {
  1517. result.add(
  1518. `\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
  1519. requestShortener
  1520. )}\n`
  1521. );
  1522. runtimeRequirements.add(RuntimeGlobals.require);
  1523. const { runtimeCondition } =
  1524. /** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
  1525. const condition = runtimeTemplate.runtimeConditionExpression({
  1526. chunkGraph,
  1527. runtimeCondition,
  1528. runtime,
  1529. runtimeRequirements
  1530. });
  1531. if (condition !== "true") {
  1532. isConditional = true;
  1533. result.add(`if (${condition}) {\n`);
  1534. }
  1535. result.add(
  1536. `var ${info.name} = ${RuntimeGlobals.require}(${JSON.stringify(
  1537. chunkGraph.getModuleId(info.module)
  1538. )});`
  1539. );
  1540. name = info.name;
  1541. break;
  1542. }
  1543. default:
  1544. // @ts-expect-error never is expected here
  1545. throw new Error(`Unsupported concatenation entry type ${info.type}`);
  1546. }
  1547. if (info.interopNamespaceObjectUsed) {
  1548. runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
  1549. result.add(
  1550. `\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name}, 2);`
  1551. );
  1552. }
  1553. if (info.interopNamespaceObject2Used) {
  1554. runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
  1555. result.add(
  1556. `\nvar ${info.interopNamespaceObject2Name} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name});`
  1557. );
  1558. }
  1559. if (info.interopDefaultAccessUsed) {
  1560. runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
  1561. result.add(
  1562. `\nvar ${info.interopDefaultAccessName} = /*#__PURE__*/${RuntimeGlobals.compatGetDefaultExport}(${name});`
  1563. );
  1564. }
  1565. if (isConditional) {
  1566. result.add("\n}");
  1567. }
  1568. }
  1569. const data = new Map();
  1570. if (chunkInitFragments.length > 0)
  1571. data.set("chunkInitFragments", chunkInitFragments);
  1572. data.set("topLevelDeclarations", topLevelDeclarations);
  1573. /** @type {CodeGenerationResult} */
  1574. const resultEntry = {
  1575. sources: new Map([["javascript", new CachedSource(result)]]),
  1576. data,
  1577. runtimeRequirements
  1578. };
  1579. return resultEntry;
  1580. }
  1581. /**
  1582. * @param {Map<Module, ModuleInfo>} modulesMap modulesMap
  1583. * @param {ModuleInfo} info info
  1584. * @param {DependencyTemplates} dependencyTemplates dependencyTemplates
  1585. * @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
  1586. * @param {ModuleGraph} moduleGraph moduleGraph
  1587. * @param {ChunkGraph} chunkGraph chunkGraph
  1588. * @param {RuntimeSpec} runtime runtime
  1589. * @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
  1590. */
  1591. _analyseModule(
  1592. modulesMap,
  1593. info,
  1594. dependencyTemplates,
  1595. runtimeTemplate,
  1596. moduleGraph,
  1597. chunkGraph,
  1598. runtime,
  1599. codeGenerationResults
  1600. ) {
  1601. if (info.type === "concatenated") {
  1602. const m = info.module;
  1603. try {
  1604. // Create a concatenation scope to track and capture information
  1605. const concatenationScope = new ConcatenationScope(modulesMap, info);
  1606. // TODO cache codeGeneration results
  1607. const codeGenResult = m.codeGeneration({
  1608. dependencyTemplates,
  1609. runtimeTemplate,
  1610. moduleGraph,
  1611. chunkGraph,
  1612. runtime,
  1613. concatenationScope,
  1614. codeGenerationResults,
  1615. sourceTypes: TYPES
  1616. });
  1617. const source = /** @type {Source} */ (
  1618. codeGenResult.sources.get("javascript")
  1619. );
  1620. const data = codeGenResult.data;
  1621. const chunkInitFragments = data && data.get("chunkInitFragments");
  1622. const code = source.source().toString();
  1623. let ast;
  1624. try {
  1625. ast = JavascriptParser._parse(code, {
  1626. sourceType: "module"
  1627. });
  1628. } catch (err) {
  1629. if (
  1630. err.loc &&
  1631. typeof err.loc === "object" &&
  1632. typeof err.loc.line === "number"
  1633. ) {
  1634. const lineNumber = err.loc.line;
  1635. const lines = code.split("\n");
  1636. err.message +=
  1637. "\n| " +
  1638. lines
  1639. .slice(Math.max(0, lineNumber - 3), lineNumber + 2)
  1640. .join("\n| ");
  1641. }
  1642. throw err;
  1643. }
  1644. const scopeManager = eslintScope.analyze(ast, {
  1645. ecmaVersion: 6,
  1646. sourceType: "module",
  1647. optimistic: true,
  1648. ignoreEval: true,
  1649. impliedStrict: true
  1650. });
  1651. const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
  1652. const moduleScope = globalScope.childScopes[0];
  1653. const resultSource = new ReplaceSource(source);
  1654. info.runtimeRequirements = codeGenResult.runtimeRequirements;
  1655. info.ast = ast;
  1656. info.internalSource = source;
  1657. info.source = resultSource;
  1658. info.chunkInitFragments = chunkInitFragments;
  1659. info.globalScope = globalScope;
  1660. info.moduleScope = moduleScope;
  1661. } catch (err) {
  1662. /** @type {Error} */
  1663. (err).message +=
  1664. `\nwhile analyzing module ${m.identifier()} for concatenation`;
  1665. throw err;
  1666. }
  1667. }
  1668. }
  1669. /**
  1670. * @param {ModuleGraph} moduleGraph the module graph
  1671. * @param {RuntimeSpec} runtime the runtime
  1672. * @returns {[ModuleInfoOrReference[], Map<Module, ModuleInfo>]} module info items
  1673. */
  1674. _getModulesWithInfo(moduleGraph, runtime) {
  1675. const orderedConcatenationList = this._createConcatenationList(
  1676. this.rootModule,
  1677. this._modules,
  1678. runtime,
  1679. moduleGraph
  1680. );
  1681. /** @type {Map<Module, ModuleInfo>} */
  1682. const map = new Map();
  1683. const list = orderedConcatenationList.map((info, index) => {
  1684. let item = map.get(info.module);
  1685. if (item === undefined) {
  1686. switch (info.type) {
  1687. case "concatenated":
  1688. item = {
  1689. type: "concatenated",
  1690. module: info.module,
  1691. index,
  1692. ast: undefined,
  1693. internalSource: undefined,
  1694. runtimeRequirements: undefined,
  1695. source: undefined,
  1696. globalScope: undefined,
  1697. moduleScope: undefined,
  1698. internalNames: new Map(),
  1699. exportMap: undefined,
  1700. rawExportMap: undefined,
  1701. namespaceExportSymbol: undefined,
  1702. namespaceObjectName: undefined,
  1703. interopNamespaceObjectUsed: false,
  1704. interopNamespaceObjectName: undefined,
  1705. interopNamespaceObject2Used: false,
  1706. interopNamespaceObject2Name: undefined,
  1707. interopDefaultAccessUsed: false,
  1708. interopDefaultAccessName: undefined
  1709. };
  1710. break;
  1711. case "external":
  1712. item = {
  1713. type: "external",
  1714. module: info.module,
  1715. runtimeCondition: info.runtimeCondition,
  1716. index,
  1717. name: undefined,
  1718. interopNamespaceObjectUsed: false,
  1719. interopNamespaceObjectName: undefined,
  1720. interopNamespaceObject2Used: false,
  1721. interopNamespaceObject2Name: undefined,
  1722. interopDefaultAccessUsed: false,
  1723. interopDefaultAccessName: undefined
  1724. };
  1725. break;
  1726. default:
  1727. throw new Error(
  1728. `Unsupported concatenation entry type ${info.type}`
  1729. );
  1730. }
  1731. map.set(
  1732. /** @type {ModuleInfo} */ (item).module,
  1733. /** @type {ModuleInfo} */ (item)
  1734. );
  1735. return item;
  1736. } else {
  1737. /** @type {ReferenceToModuleInfo} */
  1738. const ref = {
  1739. type: "reference",
  1740. runtimeCondition: info.runtimeCondition,
  1741. target: item
  1742. };
  1743. return ref;
  1744. }
  1745. });
  1746. return [list, map];
  1747. }
  1748. /**
  1749. * @param {string} oldName old name
  1750. * @param {UsedNames} usedNamed1 used named 1
  1751. * @param {UsedNames} usedNamed2 used named 2
  1752. * @param {string} extraInfo extra info
  1753. * @returns {string} found new name
  1754. */
  1755. findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
  1756. let name = oldName;
  1757. if (name === ConcatenationScope.DEFAULT_EXPORT) {
  1758. name = "";
  1759. }
  1760. if (name === ConcatenationScope.NAMESPACE_OBJECT_EXPORT) {
  1761. name = "namespaceObject";
  1762. }
  1763. // Remove uncool stuff
  1764. extraInfo = extraInfo.replace(
  1765. /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
  1766. ""
  1767. );
  1768. const splittedInfo = extraInfo.split("/");
  1769. while (splittedInfo.length) {
  1770. name = splittedInfo.pop() + (name ? "_" + name : "");
  1771. const nameIdent = Template.toIdentifier(name);
  1772. if (
  1773. !usedNamed1.has(nameIdent) &&
  1774. (!usedNamed2 || !usedNamed2.has(nameIdent))
  1775. )
  1776. return nameIdent;
  1777. }
  1778. let i = 0;
  1779. let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
  1780. while (
  1781. usedNamed1.has(nameWithNumber) ||
  1782. (usedNamed2 && usedNamed2.has(nameWithNumber))
  1783. ) {
  1784. i++;
  1785. nameWithNumber = Template.toIdentifier(`${name}_${i}`);
  1786. }
  1787. return nameWithNumber;
  1788. }
  1789. /**
  1790. * @param {Hash} hash the hash used to track dependencies
  1791. * @param {UpdateHashContext} context context
  1792. * @returns {void}
  1793. */
  1794. updateHash(hash, context) {
  1795. const { chunkGraph, runtime } = context;
  1796. for (const info of this._createConcatenationList(
  1797. this.rootModule,
  1798. this._modules,
  1799. intersectRuntime(runtime, this._runtime),
  1800. chunkGraph.moduleGraph
  1801. )) {
  1802. switch (info.type) {
  1803. case "concatenated":
  1804. info.module.updateHash(hash, context);
  1805. break;
  1806. case "external":
  1807. hash.update(`${chunkGraph.getModuleId(info.module)}`);
  1808. // TODO runtimeCondition
  1809. break;
  1810. }
  1811. }
  1812. super.updateHash(hash, context);
  1813. }
  1814. /**
  1815. * @param {ObjectDeserializerContext} context context
  1816. * @returns {ConcatenatedModule} ConcatenatedModule
  1817. */
  1818. static deserialize(context) {
  1819. const obj = new ConcatenatedModule({
  1820. identifier: undefined,
  1821. rootModule: undefined,
  1822. modules: undefined,
  1823. runtime: undefined
  1824. });
  1825. obj.deserialize(context);
  1826. return obj;
  1827. }
  1828. }
  1829. makeSerializable(ConcatenatedModule, "webpack/lib/optimize/ConcatenatedModule");
  1830. module.exports = ConcatenatedModule;