ConcatenatedModule.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Module = require("../Module");
  7. const Template = require("../Template");
  8. const Parser = require("../Parser");
  9. const eslintScope = require("eslint-scope");
  10. const { ConcatSource, ReplaceSource } = require("webpack-sources");
  11. const DependencyReference = require("../dependencies/DependencyReference");
  12. const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
  13. const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
  14. const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
  15. const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency");
  16. const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency");
  17. const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
  18. const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
  19. const createHash = require("../util/createHash");
  20. /** @typedef {import("../Dependency")} Dependency */
  21. /** @typedef {import("../Compilation")} Compilation */
  22. /** @typedef {import("../util/createHash").Hash} Hash */
  23. /**
  24. * @typedef {Object} ConcatenationEntry
  25. * @property {"concatenated" | "external"} type
  26. * @property {Module} module
  27. */
  28. const ensureNsObjSource = (
  29. info,
  30. moduleToInfoMap,
  31. requestShortener,
  32. strictHarmonyModule
  33. ) => {
  34. if (!info.hasNamespaceObject) {
  35. info.hasNamespaceObject = true;
  36. const name = info.exportMap.get(true);
  37. const nsObj = [`var ${name} = {};`, `__webpack_require__.r(${name});`];
  38. for (const exportName of info.module.buildMeta.providedExports) {
  39. const finalName = getFinalName(
  40. info,
  41. exportName,
  42. moduleToInfoMap,
  43. requestShortener,
  44. false,
  45. strictHarmonyModule
  46. );
  47. nsObj.push(
  48. `__webpack_require__.d(${name}, ${JSON.stringify(
  49. exportName
  50. )}, function() { return ${finalName}; });`
  51. );
  52. }
  53. info.namespaceObjectSource = nsObj.join("\n") + "\n";
  54. }
  55. };
  56. const getExternalImport = (
  57. importedModule,
  58. info,
  59. exportName,
  60. asCall,
  61. strictHarmonyModule
  62. ) => {
  63. const used = importedModule.isUsed(exportName);
  64. if (!used) return "/* unused reexport */undefined";
  65. const comment =
  66. used !== exportName ? ` ${Template.toNormalComment(exportName)}` : "";
  67. switch (importedModule.buildMeta.exportsType) {
  68. case "named":
  69. if (exportName === "default") {
  70. return info.name;
  71. } else if (exportName === true) {
  72. info.interopNamespaceObjectUsed = true;
  73. return info.interopNamespaceObjectName;
  74. } else {
  75. break;
  76. }
  77. case "namespace":
  78. if (exportName === true) {
  79. return info.name;
  80. } else {
  81. break;
  82. }
  83. default:
  84. if (strictHarmonyModule) {
  85. if (exportName === "default") {
  86. return info.name;
  87. } else if (exportName === true) {
  88. info.interopNamespaceObjectUsed = true;
  89. return info.interopNamespaceObjectName;
  90. } else {
  91. return "/* non-default import from non-esm module */undefined";
  92. }
  93. } else {
  94. if (exportName === "default") {
  95. info.interopDefaultAccessUsed = true;
  96. return asCall
  97. ? `${info.interopDefaultAccessName}()`
  98. : `${info.interopDefaultAccessName}.a`;
  99. } else if (exportName === true) {
  100. return info.name;
  101. } else {
  102. break;
  103. }
  104. }
  105. }
  106. const reference = `${info.name}[${JSON.stringify(used)}${comment}]`;
  107. if (asCall) return `Object(${reference})`;
  108. return reference;
  109. };
  110. const getFinalName = (
  111. info,
  112. exportName,
  113. moduleToInfoMap,
  114. requestShortener,
  115. asCall,
  116. strictHarmonyModule,
  117. alreadyVisited = new Set()
  118. ) => {
  119. switch (info.type) {
  120. case "concatenated": {
  121. const directExport = info.exportMap.get(exportName);
  122. if (directExport) {
  123. if (exportName === true) {
  124. ensureNsObjSource(
  125. info,
  126. moduleToInfoMap,
  127. requestShortener,
  128. strictHarmonyModule
  129. );
  130. } else if (!info.module.isUsed(exportName)) {
  131. return "/* unused export */ undefined";
  132. }
  133. if (info.globalExports.has(directExport)) {
  134. return directExport;
  135. }
  136. const name = info.internalNames.get(directExport);
  137. if (!name) {
  138. throw new Error(
  139. `The export "${directExport}" in "${info.module.readableIdentifier(
  140. requestShortener
  141. )}" has no internal name`
  142. );
  143. }
  144. return name;
  145. }
  146. const reexport = info.reexportMap.get(exportName);
  147. if (reexport) {
  148. if (alreadyVisited.has(reexport)) {
  149. throw new Error(
  150. `Circular reexports ${Array.from(
  151. alreadyVisited,
  152. e =>
  153. `"${e.module.readableIdentifier(requestShortener)}".${
  154. e.exportName
  155. }`
  156. ).join(
  157. " --> "
  158. )} -(circular)-> "${reexport.module.readableIdentifier(
  159. requestShortener
  160. )}".${reexport.exportName}`
  161. );
  162. }
  163. alreadyVisited.add(reexport);
  164. const refInfo = moduleToInfoMap.get(reexport.module);
  165. if (refInfo) {
  166. // module is in the concatenation
  167. return getFinalName(
  168. refInfo,
  169. reexport.exportName,
  170. moduleToInfoMap,
  171. requestShortener,
  172. asCall,
  173. strictHarmonyModule,
  174. alreadyVisited
  175. );
  176. }
  177. }
  178. const problem =
  179. `Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(
  180. requestShortener
  181. )}"` +
  182. ` (known exports: ${Array.from(info.exportMap.keys())
  183. .filter(name => name !== true)
  184. .join(" ")}, ` +
  185. `known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`;
  186. return `${Template.toNormalComment(problem)} undefined`;
  187. }
  188. case "external": {
  189. const importedModule = info.module;
  190. return getExternalImport(
  191. importedModule,
  192. info,
  193. exportName,
  194. asCall,
  195. strictHarmonyModule
  196. );
  197. }
  198. }
  199. };
  200. const addScopeSymbols1 = (s, nameSet, scopeSet) => {
  201. let scope = s;
  202. while (scope) {
  203. if (scopeSet.has(scope)) break;
  204. scopeSet.add(scope);
  205. for (const variable of scope.variables) {
  206. nameSet.add(variable.name);
  207. }
  208. scope = scope.upper;
  209. }
  210. };
  211. const addScopeSymbols2 = (s, nameSet, scopeSet1, scopeSet2) => {
  212. let scope = s;
  213. while (scope) {
  214. if (scopeSet1.has(scope)) break;
  215. if (scopeSet2.has(scope)) break;
  216. scopeSet1.add(scope);
  217. for (const variable of scope.variables) {
  218. nameSet.add(variable.name);
  219. }
  220. scope = scope.upper;
  221. }
  222. };
  223. const getAllReferences = variable => {
  224. let set = variable.references;
  225. // Look for inner scope variables too (like in class Foo { t() { Foo } })
  226. const identifiers = new Set(variable.identifiers);
  227. for (const scope of variable.scope.childScopes) {
  228. for (const innerVar of scope.variables) {
  229. if (innerVar.identifiers.some(id => identifiers.has(id))) {
  230. set = set.concat(innerVar.references);
  231. break;
  232. }
  233. }
  234. }
  235. return set;
  236. };
  237. const getPathInAst = (ast, node) => {
  238. if (ast === node) {
  239. return [];
  240. }
  241. const nr = node.range;
  242. const enterNode = n => {
  243. if (!n) return undefined;
  244. const r = n.range;
  245. if (r) {
  246. if (r[0] <= nr[0] && r[1] >= nr[1]) {
  247. const path = getPathInAst(n, node);
  248. if (path) {
  249. path.push(n);
  250. return path;
  251. }
  252. }
  253. }
  254. return undefined;
  255. };
  256. var i;
  257. if (Array.isArray(ast)) {
  258. for (i = 0; i < ast.length; i++) {
  259. const enterResult = enterNode(ast[i]);
  260. if (enterResult !== undefined) return enterResult;
  261. }
  262. } else if (ast && typeof ast === "object") {
  263. const keys = Object.keys(ast);
  264. for (i = 0; i < keys.length; i++) {
  265. const value = ast[keys[i]];
  266. if (Array.isArray(value)) {
  267. const pathResult = getPathInAst(value, node);
  268. if (pathResult !== undefined) return pathResult;
  269. } else if (value && typeof value === "object") {
  270. const enterResult = enterNode(value);
  271. if (enterResult !== undefined) return enterResult;
  272. }
  273. }
  274. }
  275. };
  276. class ConcatenatedModule extends Module {
  277. constructor(rootModule, modules, concatenationList) {
  278. super("javascript/esm", null);
  279. super.setChunks(rootModule._chunks);
  280. // Info from Factory
  281. this.rootModule = rootModule;
  282. this.factoryMeta = rootModule.factoryMeta;
  283. // Info from Compilation
  284. this.index = rootModule.index;
  285. this.index2 = rootModule.index2;
  286. this.depth = rootModule.depth;
  287. // Info from Optimization
  288. this.used = rootModule.used;
  289. this.usedExports = rootModule.usedExports;
  290. // Info from Build
  291. this.buildInfo = {
  292. strict: true,
  293. cacheable: modules.every(m => m.buildInfo.cacheable),
  294. moduleArgument: rootModule.buildInfo.moduleArgument,
  295. exportsArgument: rootModule.buildInfo.exportsArgument,
  296. fileDependencies: new Set(),
  297. contextDependencies: new Set(),
  298. assets: undefined
  299. };
  300. this.built = modules.some(m => m.built);
  301. this.buildMeta = rootModule.buildMeta;
  302. // Caching
  303. this._numberOfConcatenatedModules = modules.length;
  304. // Graph
  305. const modulesSet = new Set(modules);
  306. this.reasons = rootModule.reasons.filter(
  307. reason =>
  308. !(reason.dependency instanceof HarmonyImportDependency) ||
  309. !modulesSet.has(reason.module)
  310. );
  311. this.dependencies = [];
  312. this.warnings = [];
  313. this.errors = [];
  314. this._orderedConcatenationList =
  315. concatenationList ||
  316. ConcatenatedModule.createConcatenationList(rootModule, modulesSet, null);
  317. for (const info of this._orderedConcatenationList) {
  318. if (info.type === "concatenated") {
  319. const m = info.module;
  320. // populate dependencies
  321. for (const d of m.dependencies.filter(
  322. dep =>
  323. !(dep instanceof HarmonyImportDependency) ||
  324. !modulesSet.has(dep._module)
  325. )) {
  326. this.dependencies.push(d);
  327. }
  328. // populate file dependencies
  329. if (m.buildInfo.fileDependencies) {
  330. for (const file of m.buildInfo.fileDependencies) {
  331. this.buildInfo.fileDependencies.add(file);
  332. }
  333. }
  334. // populate context dependencies
  335. if (m.buildInfo.contextDependencies) {
  336. for (const context of m.buildInfo.contextDependencies) {
  337. this.buildInfo.contextDependencies.add(context);
  338. }
  339. }
  340. // populate warnings
  341. for (const warning of m.warnings) {
  342. this.warnings.push(warning);
  343. }
  344. // populate errors
  345. for (const error of m.errors) {
  346. this.errors.push(error);
  347. }
  348. if (m.buildInfo.assets) {
  349. if (this.buildInfo.assets === undefined) {
  350. this.buildInfo.assets = Object.create(null);
  351. }
  352. Object.assign(this.buildInfo.assets, m.buildInfo.assets);
  353. }
  354. }
  355. }
  356. this._identifier = this._createIdentifier();
  357. }
  358. get modules() {
  359. return this._orderedConcatenationList
  360. .filter(info => info.type === "concatenated")
  361. .map(info => info.module);
  362. }
  363. identifier() {
  364. return this._identifier;
  365. }
  366. readableIdentifier(requestShortener) {
  367. return (
  368. this.rootModule.readableIdentifier(requestShortener) +
  369. ` + ${this._numberOfConcatenatedModules - 1} modules`
  370. );
  371. }
  372. libIdent(options) {
  373. return this.rootModule.libIdent(options);
  374. }
  375. nameForCondition() {
  376. return this.rootModule.nameForCondition();
  377. }
  378. build(options, compilation, resolver, fs, callback) {
  379. throw new Error("Cannot build this module. It should be already built.");
  380. }
  381. size() {
  382. // Guess size from embedded modules
  383. return this._orderedConcatenationList.reduce((sum, info) => {
  384. switch (info.type) {
  385. case "concatenated":
  386. return sum + info.module.size();
  387. case "external":
  388. return sum + 5;
  389. }
  390. return sum;
  391. }, 0);
  392. }
  393. /**
  394. * @param {Module} rootModule the root of the concatenation
  395. * @param {Set<Module>} modulesSet a set of modules which should be concatenated
  396. * @param {Compilation} compilation the compilation context
  397. * @returns {ConcatenationEntry[]} concatenation list
  398. */
  399. static createConcatenationList(rootModule, modulesSet, compilation) {
  400. const list = [];
  401. const set = new Set();
  402. /**
  403. * @param {Module} module a module
  404. * @returns {(function(): Module)[]} imported modules in order
  405. */
  406. const getConcatenatedImports = module => {
  407. /** @type {WeakMap<DependencyReference, Dependency>} */
  408. const map = new WeakMap();
  409. const references = module.dependencies
  410. .filter(dep => dep instanceof HarmonyImportDependency)
  411. .map(dep => {
  412. const ref = compilation.getDependencyReference(module, dep);
  413. if (ref) map.set(ref, dep);
  414. return ref;
  415. })
  416. .filter(ref => ref);
  417. DependencyReference.sort(references);
  418. // TODO webpack 5: remove this hack, see also DependencyReference
  419. return references.map(ref => {
  420. const dep = map.get(ref);
  421. return () => compilation.getDependencyReference(module, dep).module;
  422. });
  423. };
  424. const enterModule = getModule => {
  425. const module = getModule();
  426. if (!module) return;
  427. if (set.has(module)) return;
  428. set.add(module);
  429. if (modulesSet.has(module)) {
  430. const imports = getConcatenatedImports(module);
  431. imports.forEach(enterModule);
  432. list.push({
  433. type: "concatenated",
  434. module
  435. });
  436. } else {
  437. list.push({
  438. type: "external",
  439. get module() {
  440. // We need to use a getter here, because the module in the dependency
  441. // could be replaced by some other process (i. e. also replaced with a
  442. // concatenated module)
  443. return getModule();
  444. }
  445. });
  446. }
  447. };
  448. enterModule(() => rootModule);
  449. return list;
  450. }
  451. _createIdentifier() {
  452. let orderedConcatenationListIdentifiers = "";
  453. for (let i = 0; i < this._orderedConcatenationList.length; i++) {
  454. if (this._orderedConcatenationList[i].type === "concatenated") {
  455. orderedConcatenationListIdentifiers += this._orderedConcatenationList[
  456. i
  457. ].module.identifier();
  458. orderedConcatenationListIdentifiers += " ";
  459. }
  460. }
  461. const hash = createHash("md4");
  462. hash.update(orderedConcatenationListIdentifiers);
  463. return this.rootModule.identifier() + " " + hash.digest("hex");
  464. }
  465. source(dependencyTemplates, runtimeTemplate) {
  466. const requestShortener = runtimeTemplate.requestShortener;
  467. // Metainfo for each module
  468. const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => {
  469. switch (info.type) {
  470. case "concatenated": {
  471. const exportMap = new Map();
  472. const reexportMap = new Map();
  473. for (const dep of info.module.dependencies) {
  474. if (dep instanceof HarmonyExportSpecifierDependency) {
  475. if (!exportMap.has(dep.name)) {
  476. exportMap.set(dep.name, dep.id);
  477. }
  478. } else if (dep instanceof HarmonyExportExpressionDependency) {
  479. if (!exportMap.has("default")) {
  480. exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__");
  481. }
  482. } else if (
  483. dep instanceof HarmonyExportImportedSpecifierDependency
  484. ) {
  485. const exportName = dep.name;
  486. const importName = dep.id;
  487. const importedModule = dep._module;
  488. if (exportName && importName) {
  489. if (!reexportMap.has(exportName)) {
  490. reexportMap.set(exportName, {
  491. module: importedModule,
  492. exportName: importName,
  493. dependency: dep
  494. });
  495. }
  496. } else if (exportName) {
  497. if (!reexportMap.has(exportName)) {
  498. reexportMap.set(exportName, {
  499. module: importedModule,
  500. exportName: true,
  501. dependency: dep
  502. });
  503. }
  504. } else if (importedModule) {
  505. for (const name of importedModule.buildMeta.providedExports) {
  506. if (dep.activeExports.has(name) || name === "default") {
  507. continue;
  508. }
  509. if (!reexportMap.has(name)) {
  510. reexportMap.set(name, {
  511. module: importedModule,
  512. exportName: name,
  513. dependency: dep
  514. });
  515. }
  516. }
  517. }
  518. }
  519. }
  520. return {
  521. type: "concatenated",
  522. module: info.module,
  523. index: idx,
  524. ast: undefined,
  525. internalSource: undefined,
  526. source: undefined,
  527. globalScope: undefined,
  528. moduleScope: undefined,
  529. internalNames: new Map(),
  530. globalExports: new Set(),
  531. exportMap: exportMap,
  532. reexportMap: reexportMap,
  533. hasNamespaceObject: false,
  534. namespaceObjectSource: null
  535. };
  536. }
  537. case "external":
  538. return {
  539. type: "external",
  540. module: info.module,
  541. index: idx,
  542. name: undefined,
  543. interopNamespaceObjectUsed: false,
  544. interopNamespaceObjectName: undefined,
  545. interopDefaultAccessUsed: false,
  546. interopDefaultAccessName: undefined
  547. };
  548. default:
  549. throw new Error(`Unsupported concatenation entry type ${info.type}`);
  550. }
  551. });
  552. // Create mapping from module to info
  553. const moduleToInfoMap = new Map();
  554. for (const m of modulesWithInfo) {
  555. moduleToInfoMap.set(m.module, m);
  556. }
  557. // Configure template decorators for dependencies
  558. const innerDependencyTemplates = new Map(dependencyTemplates);
  559. innerDependencyTemplates.set(
  560. HarmonyImportSpecifierDependency,
  561. new HarmonyImportSpecifierDependencyConcatenatedTemplate(
  562. dependencyTemplates.get(HarmonyImportSpecifierDependency),
  563. moduleToInfoMap
  564. )
  565. );
  566. innerDependencyTemplates.set(
  567. HarmonyImportSideEffectDependency,
  568. new HarmonyImportSideEffectDependencyConcatenatedTemplate(
  569. dependencyTemplates.get(HarmonyImportSideEffectDependency),
  570. moduleToInfoMap
  571. )
  572. );
  573. innerDependencyTemplates.set(
  574. HarmonyExportSpecifierDependency,
  575. new HarmonyExportSpecifierDependencyConcatenatedTemplate(
  576. dependencyTemplates.get(HarmonyExportSpecifierDependency),
  577. this.rootModule
  578. )
  579. );
  580. innerDependencyTemplates.set(
  581. HarmonyExportExpressionDependency,
  582. new HarmonyExportExpressionDependencyConcatenatedTemplate(
  583. dependencyTemplates.get(HarmonyExportExpressionDependency),
  584. this.rootModule
  585. )
  586. );
  587. innerDependencyTemplates.set(
  588. HarmonyExportImportedSpecifierDependency,
  589. new HarmonyExportImportedSpecifierDependencyConcatenatedTemplate(
  590. dependencyTemplates.get(HarmonyExportImportedSpecifierDependency),
  591. this.rootModule,
  592. moduleToInfoMap
  593. )
  594. );
  595. innerDependencyTemplates.set(
  596. HarmonyCompatibilityDependency,
  597. new HarmonyCompatibilityDependencyConcatenatedTemplate(
  598. dependencyTemplates.get(HarmonyCompatibilityDependency),
  599. this.rootModule,
  600. moduleToInfoMap
  601. )
  602. );
  603. // Must use full identifier in our cache here to ensure that the source
  604. // is updated should our dependencies list change.
  605. // TODO webpack 5 refactor
  606. innerDependencyTemplates.set(
  607. "hash",
  608. innerDependencyTemplates.get("hash") + this.identifier()
  609. );
  610. // Generate source code and analyse scopes
  611. // Prepare a ReplaceSource for the final source
  612. for (const info of modulesWithInfo) {
  613. if (info.type === "concatenated") {
  614. const m = info.module;
  615. const source = m.source(innerDependencyTemplates, runtimeTemplate);
  616. const code = source.source();
  617. let ast;
  618. try {
  619. ast = Parser.parse(code, {
  620. sourceType: "module"
  621. });
  622. } catch (err) {
  623. if (
  624. err.loc &&
  625. typeof err.loc === "object" &&
  626. typeof err.loc.line === "number"
  627. ) {
  628. const lineNumber = err.loc.line;
  629. const lines = code.split("\n");
  630. err.message +=
  631. "\n| " +
  632. lines
  633. .slice(Math.max(0, lineNumber - 3), lineNumber + 2)
  634. .join("\n| ");
  635. }
  636. throw err;
  637. }
  638. const scopeManager = eslintScope.analyze(ast, {
  639. ecmaVersion: 6,
  640. sourceType: "module",
  641. optimistic: true,
  642. ignoreEval: true,
  643. impliedStrict: true
  644. });
  645. const globalScope = scopeManager.acquire(ast);
  646. const moduleScope = globalScope.childScopes[0];
  647. const resultSource = new ReplaceSource(source);
  648. info.ast = ast;
  649. info.internalSource = source;
  650. info.source = resultSource;
  651. info.globalScope = globalScope;
  652. info.moduleScope = moduleScope;
  653. }
  654. }
  655. // List of all used names to avoid conflicts
  656. const allUsedNames = new Set([
  657. "__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name
  658. "abstract",
  659. "arguments",
  660. "async",
  661. "await",
  662. "boolean",
  663. "break",
  664. "byte",
  665. "case",
  666. "catch",
  667. "char",
  668. "class",
  669. "const",
  670. "continue",
  671. "debugger",
  672. "default",
  673. "delete",
  674. "do",
  675. "double",
  676. "else",
  677. "enum",
  678. "eval",
  679. "export",
  680. "extends",
  681. "false",
  682. "final",
  683. "finally",
  684. "float",
  685. "for",
  686. "function",
  687. "goto",
  688. "if",
  689. "implements",
  690. "import",
  691. "in",
  692. "instanceof",
  693. "int",
  694. "interface",
  695. "let",
  696. "long",
  697. "native",
  698. "new",
  699. "null",
  700. "package",
  701. "private",
  702. "protected",
  703. "public",
  704. "return",
  705. "short",
  706. "static",
  707. "super",
  708. "switch",
  709. "synchronized",
  710. "this",
  711. "throw",
  712. "throws",
  713. "transient",
  714. "true",
  715. "try",
  716. "typeof",
  717. "var",
  718. "void",
  719. "volatile",
  720. "while",
  721. "with",
  722. "yield",
  723. "module",
  724. "__dirname",
  725. "__filename",
  726. "exports",
  727. "Array",
  728. "Date",
  729. "eval",
  730. "function",
  731. "hasOwnProperty",
  732. "Infinity",
  733. "isFinite",
  734. "isNaN",
  735. "isPrototypeOf",
  736. "length",
  737. "Math",
  738. "NaN",
  739. "name",
  740. "Number",
  741. "Object",
  742. "prototype",
  743. "String",
  744. "toString",
  745. "undefined",
  746. "valueOf",
  747. "alert",
  748. "all",
  749. "anchor",
  750. "anchors",
  751. "area",
  752. "assign",
  753. "blur",
  754. "button",
  755. "checkbox",
  756. "clearInterval",
  757. "clearTimeout",
  758. "clientInformation",
  759. "close",
  760. "closed",
  761. "confirm",
  762. "constructor",
  763. "crypto",
  764. "decodeURI",
  765. "decodeURIComponent",
  766. "defaultStatus",
  767. "document",
  768. "element",
  769. "elements",
  770. "embed",
  771. "embeds",
  772. "encodeURI",
  773. "encodeURIComponent",
  774. "escape",
  775. "event",
  776. "fileUpload",
  777. "focus",
  778. "form",
  779. "forms",
  780. "frame",
  781. "innerHeight",
  782. "innerWidth",
  783. "layer",
  784. "layers",
  785. "link",
  786. "location",
  787. "mimeTypes",
  788. "navigate",
  789. "navigator",
  790. "frames",
  791. "frameRate",
  792. "hidden",
  793. "history",
  794. "image",
  795. "images",
  796. "offscreenBuffering",
  797. "open",
  798. "opener",
  799. "option",
  800. "outerHeight",
  801. "outerWidth",
  802. "packages",
  803. "pageXOffset",
  804. "pageYOffset",
  805. "parent",
  806. "parseFloat",
  807. "parseInt",
  808. "password",
  809. "pkcs11",
  810. "plugin",
  811. "prompt",
  812. "propertyIsEnum",
  813. "radio",
  814. "reset",
  815. "screenX",
  816. "screenY",
  817. "scroll",
  818. "secure",
  819. "select",
  820. "self",
  821. "setInterval",
  822. "setTimeout",
  823. "status",
  824. "submit",
  825. "taint",
  826. "text",
  827. "textarea",
  828. "top",
  829. "unescape",
  830. "untaint",
  831. "window",
  832. "onblur",
  833. "onclick",
  834. "onerror",
  835. "onfocus",
  836. "onkeydown",
  837. "onkeypress",
  838. "onkeyup",
  839. "onmouseover",
  840. "onload",
  841. "onmouseup",
  842. "onmousedown",
  843. "onsubmit"
  844. ]);
  845. // Set of already checked scopes
  846. const alreadyCheckedScopes = new Set();
  847. // get all global names
  848. for (const info of modulesWithInfo) {
  849. const superClassExpressions = [];
  850. // ignore symbols from moduleScope
  851. if (info.moduleScope) {
  852. alreadyCheckedScopes.add(info.moduleScope);
  853. // The super class expression in class scopes behaves weird
  854. // We store ranges of all super class expressions to make
  855. // renaming to work correctly
  856. for (const childScope of info.moduleScope.childScopes) {
  857. if (childScope.type !== "class") continue;
  858. if (!childScope.block.superClass) continue;
  859. superClassExpressions.push({
  860. range: childScope.block.superClass.range,
  861. variables: childScope.variables
  862. });
  863. }
  864. }
  865. // add global symbols
  866. if (info.globalScope) {
  867. for (const reference of info.globalScope.through) {
  868. const name = reference.identifier.name;
  869. if (
  870. /^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test(
  871. name
  872. )
  873. ) {
  874. for (const expr of superClassExpressions) {
  875. if (
  876. expr.range[0] <= reference.identifier.range[0] &&
  877. expr.range[1] >= reference.identifier.range[1]
  878. ) {
  879. for (const variable of expr.variables) {
  880. allUsedNames.add(variable.name);
  881. }
  882. }
  883. }
  884. addScopeSymbols1(
  885. reference.from,
  886. allUsedNames,
  887. alreadyCheckedScopes
  888. );
  889. } else {
  890. allUsedNames.add(name);
  891. }
  892. }
  893. }
  894. // add exported globals
  895. if (info.type === "concatenated") {
  896. const variables = new Set();
  897. for (const variable of info.moduleScope.variables) {
  898. variables.add(variable.name);
  899. }
  900. for (const [, variable] of info.exportMap) {
  901. if (!variables.has(variable)) {
  902. info.globalExports.add(variable);
  903. }
  904. }
  905. }
  906. }
  907. // generate names for symbols
  908. for (const info of modulesWithInfo) {
  909. switch (info.type) {
  910. case "concatenated": {
  911. const namespaceObjectName = this.findNewName(
  912. "namespaceObject",
  913. allUsedNames,
  914. null,
  915. info.module.readableIdentifier(requestShortener)
  916. );
  917. allUsedNames.add(namespaceObjectName);
  918. info.internalNames.set(namespaceObjectName, namespaceObjectName);
  919. info.exportMap.set(true, namespaceObjectName);
  920. for (const variable of info.moduleScope.variables) {
  921. const name = variable.name;
  922. if (allUsedNames.has(name)) {
  923. const references = getAllReferences(variable);
  924. const symbolsInReferences = new Set();
  925. const alreadyCheckedInnerScopes = new Set();
  926. for (const ref of references) {
  927. addScopeSymbols2(
  928. ref.from,
  929. symbolsInReferences,
  930. alreadyCheckedInnerScopes,
  931. alreadyCheckedScopes
  932. );
  933. }
  934. const newName = this.findNewName(
  935. name,
  936. allUsedNames,
  937. symbolsInReferences,
  938. info.module.readableIdentifier(requestShortener)
  939. );
  940. allUsedNames.add(newName);
  941. info.internalNames.set(name, newName);
  942. const source = info.source;
  943. const allIdentifiers = new Set(
  944. references.map(r => r.identifier).concat(variable.identifiers)
  945. );
  946. for (const identifier of allIdentifiers) {
  947. const r = identifier.range;
  948. const path = getPathInAst(info.ast, identifier);
  949. if (
  950. path &&
  951. path.length > 1 &&
  952. path[1].type === "Property" &&
  953. path[1].shorthand
  954. ) {
  955. source.insert(r[1], `: ${newName}`);
  956. } else {
  957. source.replace(r[0], r[1] - 1, newName);
  958. }
  959. }
  960. } else {
  961. allUsedNames.add(name);
  962. info.internalNames.set(name, name);
  963. }
  964. }
  965. break;
  966. }
  967. case "external": {
  968. const externalName = this.findNewName(
  969. "",
  970. allUsedNames,
  971. null,
  972. info.module.readableIdentifier(requestShortener)
  973. );
  974. allUsedNames.add(externalName);
  975. info.name = externalName;
  976. if (
  977. info.module.buildMeta.exportsType === "named" ||
  978. !info.module.buildMeta.exportsType
  979. ) {
  980. const externalNameInterop = this.findNewName(
  981. "namespaceObject",
  982. allUsedNames,
  983. null,
  984. info.module.readableIdentifier(requestShortener)
  985. );
  986. allUsedNames.add(externalNameInterop);
  987. info.interopNamespaceObjectName = externalNameInterop;
  988. }
  989. if (!info.module.buildMeta.exportsType) {
  990. const externalNameInterop = this.findNewName(
  991. "default",
  992. allUsedNames,
  993. null,
  994. info.module.readableIdentifier(requestShortener)
  995. );
  996. allUsedNames.add(externalNameInterop);
  997. info.interopDefaultAccessName = externalNameInterop;
  998. }
  999. break;
  1000. }
  1001. }
  1002. }
  1003. // Find and replace referenced to modules
  1004. for (const info of modulesWithInfo) {
  1005. if (info.type === "concatenated") {
  1006. for (const reference of info.globalScope.through) {
  1007. const name = reference.identifier.name;
  1008. const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec(
  1009. name
  1010. );
  1011. if (match) {
  1012. const referencedModule = modulesWithInfo[+match[1]];
  1013. let exportName;
  1014. if (match[2] === "ns") {
  1015. exportName = true;
  1016. } else {
  1017. const exportData = match[2];
  1018. exportName = Buffer.from(exportData, "hex").toString("utf-8");
  1019. }
  1020. const asCall = !!match[3];
  1021. const strictHarmonyModule = !!match[4];
  1022. const finalName = getFinalName(
  1023. referencedModule,
  1024. exportName,
  1025. moduleToInfoMap,
  1026. requestShortener,
  1027. asCall,
  1028. strictHarmonyModule
  1029. );
  1030. const r = reference.identifier.range;
  1031. const source = info.source;
  1032. source.replace(r[0], r[1] - 1, finalName);
  1033. }
  1034. }
  1035. }
  1036. }
  1037. const result = new ConcatSource();
  1038. // add harmony compatibility flag (must be first because of possible circular dependencies)
  1039. const usedExports = this.rootModule.usedExports;
  1040. if (usedExports === true) {
  1041. result.add(
  1042. runtimeTemplate.defineEsModuleFlagStatement({
  1043. exportsArgument: this.exportsArgument
  1044. })
  1045. );
  1046. }
  1047. // define required namespace objects (must be before evaluation modules)
  1048. for (const info of modulesWithInfo) {
  1049. if (info.namespaceObjectSource) {
  1050. result.add(info.namespaceObjectSource);
  1051. }
  1052. }
  1053. // evaluate modules in order
  1054. for (const info of modulesWithInfo) {
  1055. switch (info.type) {
  1056. case "concatenated":
  1057. result.add(
  1058. `\n// CONCATENATED MODULE: ${info.module.readableIdentifier(
  1059. requestShortener
  1060. )}\n`
  1061. );
  1062. result.add(info.source);
  1063. break;
  1064. case "external":
  1065. result.add(
  1066. `\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
  1067. requestShortener
  1068. )}\n`
  1069. );
  1070. result.add(
  1071. `var ${info.name} = __webpack_require__(${JSON.stringify(
  1072. info.module.id
  1073. )});\n`
  1074. );
  1075. if (info.interopNamespaceObjectUsed) {
  1076. if (info.module.buildMeta.exportsType === "named") {
  1077. result.add(
  1078. `var ${
  1079. info.interopNamespaceObjectName
  1080. } = /*#__PURE__*/__webpack_require__.t(${info.name}, 2);\n`
  1081. );
  1082. } else if (!info.module.buildMeta.exportsType) {
  1083. result.add(
  1084. `var ${
  1085. info.interopNamespaceObjectName
  1086. } = /*#__PURE__*/__webpack_require__.t(${info.name});\n`
  1087. );
  1088. }
  1089. }
  1090. if (info.interopDefaultAccessUsed) {
  1091. result.add(
  1092. `var ${
  1093. info.interopDefaultAccessName
  1094. } = /*#__PURE__*/__webpack_require__.n(${info.name});\n`
  1095. );
  1096. }
  1097. break;
  1098. default:
  1099. throw new Error(`Unsupported concatenation entry type ${info.type}`);
  1100. }
  1101. }
  1102. return result;
  1103. }
  1104. findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
  1105. let name = oldName;
  1106. if (name === "__WEBPACK_MODULE_DEFAULT_EXPORT__") name = "";
  1107. // Remove uncool stuff
  1108. extraInfo = extraInfo.replace(
  1109. /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
  1110. ""
  1111. );
  1112. const splittedInfo = extraInfo.split("/");
  1113. while (splittedInfo.length) {
  1114. name = splittedInfo.pop() + (name ? "_" + name : "");
  1115. const nameIdent = Template.toIdentifier(name);
  1116. if (
  1117. !usedNamed1.has(nameIdent) &&
  1118. (!usedNamed2 || !usedNamed2.has(nameIdent))
  1119. )
  1120. return nameIdent;
  1121. }
  1122. let i = 0;
  1123. let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
  1124. while (
  1125. usedNamed1.has(nameWithNumber) ||
  1126. (usedNamed2 && usedNamed2.has(nameWithNumber))
  1127. ) {
  1128. i++;
  1129. nameWithNumber = Template.toIdentifier(`${name}_${i}`);
  1130. }
  1131. return nameWithNumber;
  1132. }
  1133. /**
  1134. * @param {Hash} hash the hash used to track dependencies
  1135. * @returns {void}
  1136. */
  1137. updateHash(hash) {
  1138. for (const info of this._orderedConcatenationList) {
  1139. switch (info.type) {
  1140. case "concatenated":
  1141. info.module.updateHash(hash);
  1142. break;
  1143. case "external":
  1144. hash.update(`${info.module.id}`);
  1145. break;
  1146. }
  1147. }
  1148. super.updateHash(hash);
  1149. }
  1150. }
  1151. class HarmonyImportSpecifierDependencyConcatenatedTemplate {
  1152. constructor(originalTemplate, modulesMap) {
  1153. this.originalTemplate = originalTemplate;
  1154. this.modulesMap = modulesMap;
  1155. }
  1156. getHarmonyInitOrder(dep) {
  1157. const module = dep._module;
  1158. const info = this.modulesMap.get(module);
  1159. if (!info) {
  1160. return this.originalTemplate.getHarmonyInitOrder(dep);
  1161. }
  1162. return NaN;
  1163. }
  1164. harmonyInit(dep, source, runtimeTemplate, dependencyTemplates) {
  1165. const module = dep._module;
  1166. const info = this.modulesMap.get(module);
  1167. if (!info) {
  1168. this.originalTemplate.harmonyInit(
  1169. dep,
  1170. source,
  1171. runtimeTemplate,
  1172. dependencyTemplates
  1173. );
  1174. return;
  1175. }
  1176. }
  1177. apply(dep, source, runtime, dependencyTemplates) {
  1178. const module = dep._module;
  1179. const info = this.modulesMap.get(module);
  1180. if (!info) {
  1181. this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
  1182. return;
  1183. }
  1184. let content;
  1185. const callFlag = dep.call ? "_call" : "";
  1186. const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
  1187. ? "_strict"
  1188. : "";
  1189. if (dep._id === null) {
  1190. content = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
  1191. } else if (dep.namespaceObjectAsContext) {
  1192. content = `__WEBPACK_MODULE_REFERENCE__${
  1193. info.index
  1194. }_ns${strictFlag}__[${JSON.stringify(dep._id)}]`;
  1195. } else {
  1196. const exportData = Buffer.from(dep._id, "utf-8").toString("hex");
  1197. content = `__WEBPACK_MODULE_REFERENCE__${
  1198. info.index
  1199. }_${exportData}${callFlag}${strictFlag}__`;
  1200. }
  1201. if (dep.shorthand) {
  1202. content = dep.name + ": " + content;
  1203. }
  1204. source.replace(dep.range[0], dep.range[1] - 1, content);
  1205. }
  1206. }
  1207. class HarmonyImportSideEffectDependencyConcatenatedTemplate {
  1208. constructor(originalTemplate, modulesMap) {
  1209. this.originalTemplate = originalTemplate;
  1210. this.modulesMap = modulesMap;
  1211. }
  1212. getHarmonyInitOrder(dep) {
  1213. const module = dep._module;
  1214. const info = this.modulesMap.get(module);
  1215. if (!info) {
  1216. return this.originalTemplate.getHarmonyInitOrder(dep);
  1217. }
  1218. return NaN;
  1219. }
  1220. harmonyInit(dep, source, runtime, dependencyTemplates) {
  1221. const module = dep._module;
  1222. const info = this.modulesMap.get(module);
  1223. if (!info) {
  1224. this.originalTemplate.harmonyInit(
  1225. dep,
  1226. source,
  1227. runtime,
  1228. dependencyTemplates
  1229. );
  1230. return;
  1231. }
  1232. }
  1233. apply(dep, source, runtime, dependencyTemplates) {
  1234. const module = dep._module;
  1235. const info = this.modulesMap.get(module);
  1236. if (!info) {
  1237. this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
  1238. return;
  1239. }
  1240. }
  1241. }
  1242. class HarmonyExportSpecifierDependencyConcatenatedTemplate {
  1243. constructor(originalTemplate, rootModule) {
  1244. this.originalTemplate = originalTemplate;
  1245. this.rootModule = rootModule;
  1246. }
  1247. getHarmonyInitOrder(dep) {
  1248. if (dep.originModule === this.rootModule) {
  1249. return this.originalTemplate.getHarmonyInitOrder(dep);
  1250. }
  1251. return NaN;
  1252. }
  1253. harmonyInit(dep, source, runtime, dependencyTemplates) {
  1254. if (dep.originModule === this.rootModule) {
  1255. this.originalTemplate.harmonyInit(
  1256. dep,
  1257. source,
  1258. runtime,
  1259. dependencyTemplates
  1260. );
  1261. return;
  1262. }
  1263. }
  1264. apply(dep, source, runtime, dependencyTemplates) {
  1265. if (dep.originModule === this.rootModule) {
  1266. this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
  1267. }
  1268. }
  1269. }
  1270. class HarmonyExportExpressionDependencyConcatenatedTemplate {
  1271. constructor(originalTemplate, rootModule) {
  1272. this.originalTemplate = originalTemplate;
  1273. this.rootModule = rootModule;
  1274. }
  1275. apply(dep, source, runtime, dependencyTemplates) {
  1276. let content =
  1277. "/* harmony default export */ var __WEBPACK_MODULE_DEFAULT_EXPORT__ = ";
  1278. if (dep.originModule === this.rootModule) {
  1279. const used = dep.originModule.isUsed("default");
  1280. const exportsName = dep.originModule.exportsArgument;
  1281. if (used) content += `${exportsName}[${JSON.stringify(used)}] = `;
  1282. }
  1283. if (dep.range) {
  1284. source.replace(
  1285. dep.rangeStatement[0],
  1286. dep.range[0] - 1,
  1287. content + "(" + dep.prefix
  1288. );
  1289. source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
  1290. return;
  1291. }
  1292. source.replace(
  1293. dep.rangeStatement[0],
  1294. dep.rangeStatement[1] - 1,
  1295. content + dep.prefix
  1296. );
  1297. }
  1298. }
  1299. class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
  1300. constructor(originalTemplate, rootModule, modulesMap) {
  1301. this.originalTemplate = originalTemplate;
  1302. this.rootModule = rootModule;
  1303. this.modulesMap = modulesMap;
  1304. }
  1305. getExports(dep) {
  1306. const importModule = dep._module;
  1307. if (dep.id) {
  1308. // export { named } from "module"
  1309. return [
  1310. {
  1311. name: dep.name,
  1312. id: dep.id,
  1313. module: importModule
  1314. }
  1315. ];
  1316. }
  1317. if (dep.name) {
  1318. // export * as abc from "module"
  1319. return [
  1320. {
  1321. name: dep.name,
  1322. id: true,
  1323. module: importModule
  1324. }
  1325. ];
  1326. }
  1327. // export * from "module"
  1328. return importModule.buildMeta.providedExports
  1329. .filter(exp => exp !== "default" && !dep.activeExports.has(exp))
  1330. .map(exp => {
  1331. return {
  1332. name: exp,
  1333. id: exp,
  1334. module: importModule
  1335. };
  1336. });
  1337. }
  1338. getHarmonyInitOrder(dep) {
  1339. const module = dep._module;
  1340. const info = this.modulesMap.get(module);
  1341. if (!info) {
  1342. return this.originalTemplate.getHarmonyInitOrder(dep);
  1343. }
  1344. return NaN;
  1345. }
  1346. harmonyInit(dep, source, runtime, dependencyTemplates) {
  1347. const module = dep._module;
  1348. const info = this.modulesMap.get(module);
  1349. if (!info) {
  1350. this.originalTemplate.harmonyInit(
  1351. dep,
  1352. source,
  1353. runtime,
  1354. dependencyTemplates
  1355. );
  1356. return;
  1357. }
  1358. }
  1359. apply(dep, source, runtime, dependencyTemplates) {
  1360. if (dep.originModule === this.rootModule) {
  1361. if (this.modulesMap.get(dep._module)) {
  1362. const exportDefs = this.getExports(dep);
  1363. for (const def of exportDefs) {
  1364. const info = this.modulesMap.get(def.module);
  1365. const used = dep.originModule.isUsed(def.name);
  1366. if (!used) {
  1367. source.insert(
  1368. -1,
  1369. `/* unused concated harmony import ${def.name} */\n`
  1370. );
  1371. continue;
  1372. }
  1373. let finalName;
  1374. const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
  1375. ? "_strict"
  1376. : "";
  1377. if (def.id === true) {
  1378. finalName = `__WEBPACK_MODULE_REFERENCE__${
  1379. info.index
  1380. }_ns${strictFlag}__`;
  1381. } else {
  1382. const exportData = Buffer.from(def.id, "utf-8").toString("hex");
  1383. finalName = `__WEBPACK_MODULE_REFERENCE__${
  1384. info.index
  1385. }_${exportData}${strictFlag}__`;
  1386. }
  1387. const exportsName = this.rootModule.exportsArgument;
  1388. const content =
  1389. `/* concated harmony reexport ${def.name} */` +
  1390. `__webpack_require__.d(${exportsName}, ` +
  1391. `${JSON.stringify(used)}, ` +
  1392. `function() { return ${finalName}; });\n`;
  1393. source.insert(-1, content);
  1394. }
  1395. } else {
  1396. this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
  1397. }
  1398. }
  1399. }
  1400. }
  1401. class HarmonyCompatibilityDependencyConcatenatedTemplate {
  1402. constructor(originalTemplate, rootModule, modulesMap) {
  1403. this.originalTemplate = originalTemplate;
  1404. this.rootModule = rootModule;
  1405. this.modulesMap = modulesMap;
  1406. }
  1407. apply(dep, source, runtime, dependencyTemplates) {
  1408. // do nothing
  1409. }
  1410. }
  1411. module.exports = ConcatenatedModule;