HarmonyExportImportedSpecifierDependency.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ConditionalInitFragment = require("../ConditionalInitFragment");
  7. const Dependency = require("../Dependency");
  8. const { UsageState } = require("../ExportsInfo");
  9. const HarmonyLinkingError = require("../HarmonyLinkingError");
  10. const InitFragment = require("../InitFragment");
  11. const RuntimeGlobals = require("../RuntimeGlobals");
  12. const Template = require("../Template");
  13. const { countIterable } = require("../util/IterableHelpers");
  14. const { first, combine } = require("../util/SetHelpers");
  15. const makeSerializable = require("../util/makeSerializable");
  16. const propertyAccess = require("../util/propertyAccess");
  17. const { propertyName } = require("../util/propertyName");
  18. const {
  19. getRuntimeKey,
  20. keyToRuntime,
  21. filterRuntime
  22. } = require("../util/runtime");
  23. const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
  24. const HarmonyImportDependency = require("./HarmonyImportDependency");
  25. const processExportInfo = require("./processExportInfo");
  26. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  27. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  28. /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
  29. /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
  30. /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
  31. /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
  32. /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
  33. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  34. /** @typedef {import("../ExportsInfo")} ExportsInfo */
  35. /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
  36. /** @typedef {import("../ExportsInfo").UsedName} UsedName */
  37. /** @typedef {import("../Generator").GenerateContext} GenerateContext */
  38. /** @typedef {import("../Module")} Module */
  39. /** @typedef {import("../Module").BuildMeta} BuildMeta */
  40. /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
  41. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  42. /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
  43. /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
  44. /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
  45. /** @typedef {import("../WebpackError")} WebpackError */
  46. /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
  47. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  48. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  49. /** @typedef {import("../util/Hash")} Hash */
  50. /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
  51. /** @typedef {import("./processExportInfo").ReferencedExports} ReferencedExports */
  52. /** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
  53. const { ExportPresenceModes } = HarmonyImportDependency;
  54. const idsSymbol = Symbol("HarmonyExportImportedSpecifierDependency.ids");
  55. class NormalReexportItem {
  56. /**
  57. * @param {string} name export name
  58. * @param {string[]} ids reexported ids from other module
  59. * @param {ExportInfo} exportInfo export info from other module
  60. * @param {boolean} checked true, if it should be checked at runtime if this export exists
  61. * @param {boolean} hidden true, if it is hidden behind another active export in the same module
  62. */
  63. constructor(name, ids, exportInfo, checked, hidden) {
  64. this.name = name;
  65. this.ids = ids;
  66. this.exportInfo = exportInfo;
  67. this.checked = checked;
  68. this.hidden = hidden;
  69. }
  70. }
  71. /** @typedef {Set<string>} ExportModeIgnored */
  72. /** @typedef {Set<string>} ExportModeHidden */
  73. class ExportMode {
  74. /**
  75. * @param {ExportModeType} type type of the mode
  76. */
  77. constructor(type) {
  78. /** @type {ExportModeType} */
  79. this.type = type;
  80. // for "normal-reexport":
  81. /** @type {NormalReexportItem[] | null} */
  82. this.items = null;
  83. // for "reexport-named-default" | "reexport-fake-namespace-object" | "reexport-namespace-object"
  84. /** @type {string | null} */
  85. this.name = null;
  86. /** @type {ExportInfo | null} */
  87. this.partialNamespaceExportInfo = null;
  88. // for "dynamic-reexport":
  89. /** @type {ExportModeIgnored | null} */
  90. this.ignored = null;
  91. // for "dynamic-reexport" | "empty-star":
  92. /** @type {ExportModeHidden | undefined | null} */
  93. this.hidden = null;
  94. // for "missing":
  95. /** @type {string | null} */
  96. this.userRequest = null;
  97. // for "reexport-fake-namespace-object":
  98. /** @type {number} */
  99. this.fakeType = 0;
  100. }
  101. }
  102. /**
  103. * @param {ModuleGraph} moduleGraph module graph
  104. * @param {TODO} dependencies dependencies
  105. * @param {TODO=} additionalDependency additional dependency
  106. * @returns {TODO} result
  107. */
  108. const determineExportAssignments = (
  109. moduleGraph,
  110. dependencies,
  111. additionalDependency
  112. ) => {
  113. const names = new Set();
  114. /** @type {number[]} */
  115. const dependencyIndices = [];
  116. if (additionalDependency) {
  117. dependencies = dependencies.concat(additionalDependency);
  118. }
  119. for (const dep of dependencies) {
  120. const i = dependencyIndices.length;
  121. dependencyIndices[i] = names.size;
  122. const otherImportedModule = moduleGraph.getModule(dep);
  123. if (otherImportedModule) {
  124. const exportsInfo = moduleGraph.getExportsInfo(otherImportedModule);
  125. for (const exportInfo of exportsInfo.exports) {
  126. if (
  127. exportInfo.provided === true &&
  128. exportInfo.name !== "default" &&
  129. !names.has(exportInfo.name)
  130. ) {
  131. names.add(exportInfo.name);
  132. dependencyIndices[i] = names.size;
  133. }
  134. }
  135. }
  136. }
  137. dependencyIndices.push(names.size);
  138. return { names: Array.from(names), dependencyIndices };
  139. };
  140. const findDependencyForName = (
  141. { names, dependencyIndices },
  142. name,
  143. dependencies
  144. ) => {
  145. const dependenciesIt = dependencies[Symbol.iterator]();
  146. const dependencyIndicesIt = dependencyIndices[Symbol.iterator]();
  147. let dependenciesItResult = dependenciesIt.next();
  148. let dependencyIndicesItResult = dependencyIndicesIt.next();
  149. if (dependencyIndicesItResult.done) return;
  150. for (let i = 0; i < names.length; i++) {
  151. while (i >= dependencyIndicesItResult.value) {
  152. dependenciesItResult = dependenciesIt.next();
  153. dependencyIndicesItResult = dependencyIndicesIt.next();
  154. if (dependencyIndicesItResult.done) return;
  155. }
  156. if (names[i] === name) return dependenciesItResult.value;
  157. }
  158. return undefined;
  159. };
  160. /**
  161. * @param {ModuleGraph} moduleGraph the module graph
  162. * @param {HarmonyExportImportedSpecifierDependency} dep the dependency
  163. * @param {string} runtimeKey the runtime key
  164. * @returns {ExportMode} the export mode
  165. */
  166. const getMode = (moduleGraph, dep, runtimeKey) => {
  167. const importedModule = moduleGraph.getModule(dep);
  168. if (!importedModule) {
  169. const mode = new ExportMode("missing");
  170. mode.userRequest = dep.userRequest;
  171. return mode;
  172. }
  173. const name = dep.name;
  174. const runtime = keyToRuntime(runtimeKey);
  175. const parentModule = /** @type {Module} */ (moduleGraph.getParentModule(dep));
  176. const exportsInfo = moduleGraph.getExportsInfo(parentModule);
  177. if (
  178. name
  179. ? exportsInfo.getUsed(name, runtime) === UsageState.Unused
  180. : exportsInfo.isUsed(runtime) === false
  181. ) {
  182. const mode = new ExportMode("unused");
  183. mode.name = name || "*";
  184. return mode;
  185. }
  186. const importedExportsType = importedModule.getExportsType(
  187. moduleGraph,
  188. /** @type {BuildMeta} */ (parentModule.buildMeta).strictHarmonyModule
  189. );
  190. const ids = dep.getIds(moduleGraph);
  191. // Special handling for reexporting the default export
  192. // from non-namespace modules
  193. if (name && ids.length > 0 && ids[0] === "default") {
  194. switch (importedExportsType) {
  195. case "dynamic": {
  196. const mode = new ExportMode("reexport-dynamic-default");
  197. mode.name = name;
  198. return mode;
  199. }
  200. case "default-only":
  201. case "default-with-named": {
  202. const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
  203. const mode = new ExportMode("reexport-named-default");
  204. mode.name = name;
  205. mode.partialNamespaceExportInfo = exportInfo;
  206. return mode;
  207. }
  208. }
  209. }
  210. // reexporting with a fixed name
  211. if (name) {
  212. let mode;
  213. const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
  214. if (ids.length > 0) {
  215. // export { name as name }
  216. switch (importedExportsType) {
  217. case "default-only":
  218. mode = new ExportMode("reexport-undefined");
  219. mode.name = name;
  220. break;
  221. default:
  222. mode = new ExportMode("normal-reexport");
  223. mode.items = [
  224. new NormalReexportItem(name, ids, exportInfo, false, false)
  225. ];
  226. break;
  227. }
  228. } else {
  229. // export * as name
  230. switch (importedExportsType) {
  231. case "default-only":
  232. mode = new ExportMode("reexport-fake-namespace-object");
  233. mode.name = name;
  234. mode.partialNamespaceExportInfo = exportInfo;
  235. mode.fakeType = 0;
  236. break;
  237. case "default-with-named":
  238. mode = new ExportMode("reexport-fake-namespace-object");
  239. mode.name = name;
  240. mode.partialNamespaceExportInfo = exportInfo;
  241. mode.fakeType = 2;
  242. break;
  243. case "dynamic":
  244. default:
  245. mode = new ExportMode("reexport-namespace-object");
  246. mode.name = name;
  247. mode.partialNamespaceExportInfo = exportInfo;
  248. }
  249. }
  250. return mode;
  251. }
  252. // Star reexporting
  253. const { ignoredExports, exports, checked, hidden } = dep.getStarReexports(
  254. moduleGraph,
  255. runtime,
  256. exportsInfo,
  257. importedModule
  258. );
  259. if (!exports) {
  260. // We have too few info about the modules
  261. // Delegate the logic to the runtime code
  262. const mode = new ExportMode("dynamic-reexport");
  263. mode.ignored = ignoredExports;
  264. mode.hidden = hidden;
  265. return mode;
  266. }
  267. if (exports.size === 0) {
  268. const mode = new ExportMode("empty-star");
  269. mode.hidden = hidden;
  270. return mode;
  271. }
  272. const mode = new ExportMode("normal-reexport");
  273. mode.items = Array.from(
  274. exports,
  275. exportName =>
  276. new NormalReexportItem(
  277. exportName,
  278. [exportName],
  279. exportsInfo.getReadOnlyExportInfo(exportName),
  280. /** @type {Set<string>} */
  281. (checked).has(exportName),
  282. false
  283. )
  284. );
  285. if (hidden !== undefined) {
  286. for (const exportName of hidden) {
  287. mode.items.push(
  288. new NormalReexportItem(
  289. exportName,
  290. [exportName],
  291. exportsInfo.getReadOnlyExportInfo(exportName),
  292. false,
  293. true
  294. )
  295. );
  296. }
  297. }
  298. return mode;
  299. };
  300. /** @typedef {string[]} Ids */
  301. /** @typedef {Set<string>} Exports */
  302. /** @typedef {Set<string>} Checked */
  303. /** @typedef {Set<string>} Hidden */
  304. /** @typedef {Set<string>} IgnoredExports */
  305. class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
  306. /**
  307. * @param {string} request the request string
  308. * @param {number} sourceOrder the order in the original source file
  309. * @param {Ids} ids the requested export name of the imported module
  310. * @param {string | null} name the export name of for this module
  311. * @param {Set<string>} activeExports other named exports in the module
  312. * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
  313. * @param {number} exportPresenceMode mode of checking export names
  314. * @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
  315. * @param {ImportAttributes=} attributes import attributes
  316. */
  317. constructor(
  318. request,
  319. sourceOrder,
  320. ids,
  321. name,
  322. activeExports,
  323. otherStarExports,
  324. exportPresenceMode,
  325. allStarExports,
  326. attributes
  327. ) {
  328. super(request, sourceOrder, attributes);
  329. this.ids = ids;
  330. this.name = name;
  331. this.activeExports = activeExports;
  332. this.otherStarExports = otherStarExports;
  333. this.exportPresenceMode = exportPresenceMode;
  334. this.allStarExports = allStarExports;
  335. }
  336. /**
  337. * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
  338. */
  339. couldAffectReferencingModule() {
  340. return Dependency.TRANSITIVE;
  341. }
  342. // TODO webpack 6 remove
  343. get id() {
  344. throw new Error("id was renamed to ids and type changed to string[]");
  345. }
  346. // TODO webpack 6 remove
  347. getId() {
  348. throw new Error("id was renamed to ids and type changed to string[]");
  349. }
  350. // TODO webpack 6 remove
  351. setId() {
  352. throw new Error("id was renamed to ids and type changed to string[]");
  353. }
  354. get type() {
  355. return "harmony export imported specifier";
  356. }
  357. /**
  358. * @param {ModuleGraph} moduleGraph the module graph
  359. * @returns {Ids} the imported id
  360. */
  361. getIds(moduleGraph) {
  362. return moduleGraph.getMeta(this)[idsSymbol] || this.ids;
  363. }
  364. /**
  365. * @param {ModuleGraph} moduleGraph the module graph
  366. * @param {Ids} ids the imported ids
  367. * @returns {void}
  368. */
  369. setIds(moduleGraph, ids) {
  370. /** @type {TODO} */
  371. (moduleGraph.getMeta(this))[idsSymbol] = ids;
  372. }
  373. /**
  374. * @param {ModuleGraph} moduleGraph the module graph
  375. * @param {RuntimeSpec} runtime the runtime
  376. * @returns {ExportMode} the export mode
  377. */
  378. getMode(moduleGraph, runtime) {
  379. return moduleGraph.dependencyCacheProvide(
  380. this,
  381. getRuntimeKey(runtime),
  382. getMode
  383. );
  384. }
  385. /**
  386. * @param {ModuleGraph} moduleGraph the module graph
  387. * @param {RuntimeSpec} runtime the runtime
  388. * @param {ExportsInfo} exportsInfo exports info about the current module (optional)
  389. * @param {Module} importedModule the imported module (optional)
  390. * @returns {{exports?: Exports, checked?: Checked, ignoredExports: IgnoredExports, hidden?: Hidden}} information
  391. */
  392. getStarReexports(
  393. moduleGraph,
  394. runtime,
  395. exportsInfo = moduleGraph.getExportsInfo(
  396. /** @type {Module} */ (moduleGraph.getParentModule(this))
  397. ),
  398. importedModule = /** @type {Module} */ (moduleGraph.getModule(this))
  399. ) {
  400. const importedExportsInfo = moduleGraph.getExportsInfo(importedModule);
  401. const noExtraExports =
  402. importedExportsInfo.otherExportsInfo.provided === false;
  403. const noExtraImports =
  404. exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused;
  405. const ignoredExports = new Set(["default", ...this.activeExports]);
  406. let hiddenExports;
  407. const otherStarExports =
  408. this._discoverActiveExportsFromOtherStarExports(moduleGraph);
  409. if (otherStarExports !== undefined) {
  410. hiddenExports = new Set();
  411. for (let i = 0; i < otherStarExports.namesSlice; i++) {
  412. hiddenExports.add(otherStarExports.names[i]);
  413. }
  414. for (const e of ignoredExports) hiddenExports.delete(e);
  415. }
  416. if (!noExtraExports && !noExtraImports) {
  417. return {
  418. ignoredExports,
  419. hidden: hiddenExports
  420. };
  421. }
  422. /** @type {Exports} */
  423. const exports = new Set();
  424. /** @type {Checked} */
  425. const checked = new Set();
  426. /** @type {Hidden | undefined} */
  427. const hidden = hiddenExports !== undefined ? new Set() : undefined;
  428. if (noExtraImports) {
  429. for (const exportInfo of exportsInfo.orderedExports) {
  430. const name = exportInfo.name;
  431. if (ignoredExports.has(name)) continue;
  432. if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
  433. const importedExportInfo =
  434. importedExportsInfo.getReadOnlyExportInfo(name);
  435. if (importedExportInfo.provided === false) continue;
  436. if (hiddenExports !== undefined && hiddenExports.has(name)) {
  437. /** @type {Set<string>} */
  438. (hidden).add(name);
  439. continue;
  440. }
  441. exports.add(name);
  442. if (importedExportInfo.provided === true) continue;
  443. checked.add(name);
  444. }
  445. } else if (noExtraExports) {
  446. for (const importedExportInfo of importedExportsInfo.orderedExports) {
  447. const name = importedExportInfo.name;
  448. if (ignoredExports.has(name)) continue;
  449. if (importedExportInfo.provided === false) continue;
  450. const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
  451. if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
  452. if (hiddenExports !== undefined && hiddenExports.has(name)) {
  453. /** @type {ExportModeHidden} */
  454. (hidden).add(name);
  455. continue;
  456. }
  457. exports.add(name);
  458. if (importedExportInfo.provided === true) continue;
  459. checked.add(name);
  460. }
  461. }
  462. return { ignoredExports, exports, checked, hidden };
  463. }
  464. /**
  465. * @param {ModuleGraph} moduleGraph module graph
  466. * @returns {null | false | GetConditionFn} function to determine if the connection is active
  467. */
  468. getCondition(moduleGraph) {
  469. return (connection, runtime) => {
  470. const mode = this.getMode(moduleGraph, runtime);
  471. return mode.type !== "unused" && mode.type !== "empty-star";
  472. };
  473. }
  474. /**
  475. * @param {ModuleGraph} moduleGraph the module graph
  476. * @returns {ConnectionState} how this dependency connects the module to referencing modules
  477. */
  478. getModuleEvaluationSideEffectsState(moduleGraph) {
  479. return false;
  480. }
  481. /**
  482. * Returns list of exports referenced by this dependency
  483. * @param {ModuleGraph} moduleGraph module graph
  484. * @param {RuntimeSpec} runtime the runtime for which the module is analysed
  485. * @returns {(string[] | ReferencedExport)[]} referenced exports
  486. */
  487. getReferencedExports(moduleGraph, runtime) {
  488. const mode = this.getMode(moduleGraph, runtime);
  489. switch (mode.type) {
  490. case "missing":
  491. case "unused":
  492. case "empty-star":
  493. case "reexport-undefined":
  494. return Dependency.NO_EXPORTS_REFERENCED;
  495. case "reexport-dynamic-default":
  496. return Dependency.EXPORTS_OBJECT_REFERENCED;
  497. case "reexport-named-default": {
  498. if (!mode.partialNamespaceExportInfo)
  499. return Dependency.EXPORTS_OBJECT_REFERENCED;
  500. /** @type {ReferencedExports} */
  501. const referencedExports = [];
  502. processExportInfo(
  503. runtime,
  504. referencedExports,
  505. [],
  506. /** @type {ExportInfo} */ (mode.partialNamespaceExportInfo)
  507. );
  508. return referencedExports;
  509. }
  510. case "reexport-namespace-object":
  511. case "reexport-fake-namespace-object": {
  512. if (!mode.partialNamespaceExportInfo)
  513. return Dependency.EXPORTS_OBJECT_REFERENCED;
  514. /** @type {ReferencedExports} */
  515. const referencedExports = [];
  516. processExportInfo(
  517. runtime,
  518. referencedExports,
  519. [],
  520. /** @type {ExportInfo} */ (mode.partialNamespaceExportInfo),
  521. mode.type === "reexport-fake-namespace-object"
  522. );
  523. return referencedExports;
  524. }
  525. case "dynamic-reexport":
  526. return Dependency.EXPORTS_OBJECT_REFERENCED;
  527. case "normal-reexport": {
  528. /** @type {ReferencedExports} */
  529. const referencedExports = [];
  530. for (const {
  531. ids,
  532. exportInfo,
  533. hidden
  534. } of /** @type {NormalReexportItem[]} */ (mode.items)) {
  535. if (hidden) continue;
  536. processExportInfo(runtime, referencedExports, ids, exportInfo, false);
  537. }
  538. return referencedExports;
  539. }
  540. default:
  541. throw new Error(`Unknown mode ${mode.type}`);
  542. }
  543. }
  544. /**
  545. * @param {ModuleGraph} moduleGraph the module graph
  546. * @returns {{ names: string[], namesSlice: number, dependencyIndices: number[], dependencyIndex: number } | undefined} exported names and their origin dependency
  547. */
  548. _discoverActiveExportsFromOtherStarExports(moduleGraph) {
  549. if (!this.otherStarExports) return;
  550. const i =
  551. "length" in this.otherStarExports
  552. ? this.otherStarExports.length
  553. : countIterable(this.otherStarExports);
  554. if (i === 0) return;
  555. if (this.allStarExports) {
  556. const { names, dependencyIndices } = moduleGraph.cached(
  557. determineExportAssignments,
  558. this.allStarExports.dependencies
  559. );
  560. return {
  561. names,
  562. namesSlice: dependencyIndices[i - 1],
  563. dependencyIndices,
  564. dependencyIndex: i
  565. };
  566. }
  567. const { names, dependencyIndices } = moduleGraph.cached(
  568. determineExportAssignments,
  569. this.otherStarExports,
  570. this
  571. );
  572. return {
  573. names,
  574. namesSlice: dependencyIndices[i - 1],
  575. dependencyIndices,
  576. dependencyIndex: i
  577. };
  578. }
  579. /**
  580. * Returns the exported names
  581. * @param {ModuleGraph} moduleGraph module graph
  582. * @returns {ExportsSpec | undefined} export names
  583. */
  584. getExports(moduleGraph) {
  585. const mode = this.getMode(moduleGraph, undefined);
  586. switch (mode.type) {
  587. case "missing":
  588. return;
  589. case "dynamic-reexport": {
  590. const from =
  591. /** @type {ModuleGraphConnection} */
  592. (moduleGraph.getConnection(this));
  593. return {
  594. exports: true,
  595. from,
  596. canMangle: false,
  597. excludeExports: mode.hidden
  598. ? combine(
  599. /** @type {ExportModeIgnored} */ (mode.ignored),
  600. mode.hidden
  601. )
  602. : /** @type {ExportModeIgnored} */ (mode.ignored),
  603. hideExports: mode.hidden,
  604. dependencies: [from.module]
  605. };
  606. }
  607. case "empty-star":
  608. return {
  609. exports: [],
  610. hideExports: mode.hidden,
  611. dependencies: [/** @type {Module} */ (moduleGraph.getModule(this))]
  612. };
  613. // falls through
  614. case "normal-reexport": {
  615. const from =
  616. /** @type {ModuleGraphConnection} */
  617. (moduleGraph.getConnection(this));
  618. return {
  619. exports: Array.from(
  620. /** @type {NormalReexportItem[]} */ (mode.items),
  621. item => ({
  622. name: item.name,
  623. from,
  624. export: item.ids,
  625. hidden: item.hidden
  626. })
  627. ),
  628. priority: 1,
  629. dependencies: [from.module]
  630. };
  631. }
  632. case "reexport-dynamic-default": {
  633. const from =
  634. /** @type {ModuleGraphConnection} */
  635. (moduleGraph.getConnection(this));
  636. return {
  637. exports: [
  638. {
  639. name: /** @type {string} */ (mode.name),
  640. from,
  641. export: ["default"]
  642. }
  643. ],
  644. priority: 1,
  645. dependencies: [from.module]
  646. };
  647. }
  648. case "reexport-undefined":
  649. return {
  650. exports: [/** @type {string} */ (mode.name)],
  651. dependencies: [/** @type {Module} */ (moduleGraph.getModule(this))]
  652. };
  653. case "reexport-fake-namespace-object": {
  654. const from =
  655. /** @type {ModuleGraphConnection} */
  656. (moduleGraph.getConnection(this));
  657. return {
  658. exports: [
  659. {
  660. name: /** @type {string} */ (mode.name),
  661. from,
  662. export: null,
  663. exports: [
  664. {
  665. name: "default",
  666. canMangle: false,
  667. from,
  668. export: null
  669. }
  670. ]
  671. }
  672. ],
  673. priority: 1,
  674. dependencies: [from.module]
  675. };
  676. }
  677. case "reexport-namespace-object": {
  678. const from =
  679. /** @type {ModuleGraphConnection} */
  680. (moduleGraph.getConnection(this));
  681. return {
  682. exports: [
  683. {
  684. name: /** @type {string} */ (mode.name),
  685. from,
  686. export: null
  687. }
  688. ],
  689. priority: 1,
  690. dependencies: [from.module]
  691. };
  692. }
  693. case "reexport-named-default": {
  694. const from =
  695. /** @type {ModuleGraphConnection} */
  696. (moduleGraph.getConnection(this));
  697. return {
  698. exports: [
  699. {
  700. name: /** @type {string} */ (mode.name),
  701. from,
  702. export: ["default"]
  703. }
  704. ],
  705. priority: 1,
  706. dependencies: [from.module]
  707. };
  708. }
  709. default:
  710. throw new Error(`Unknown mode ${mode.type}`);
  711. }
  712. }
  713. /**
  714. * @param {ModuleGraph} moduleGraph module graph
  715. * @returns {number} effective mode
  716. */
  717. _getEffectiveExportPresenceLevel(moduleGraph) {
  718. if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
  719. return this.exportPresenceMode;
  720. const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
  721. return /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule
  722. ? ExportPresenceModes.ERROR
  723. : ExportPresenceModes.WARN;
  724. }
  725. /**
  726. * Returns warnings
  727. * @param {ModuleGraph} moduleGraph module graph
  728. * @returns {WebpackError[] | null | undefined} warnings
  729. */
  730. getWarnings(moduleGraph) {
  731. const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
  732. if (exportsPresence === ExportPresenceModes.WARN) {
  733. return this._getErrors(moduleGraph);
  734. }
  735. return null;
  736. }
  737. /**
  738. * Returns errors
  739. * @param {ModuleGraph} moduleGraph module graph
  740. * @returns {WebpackError[] | null | undefined} errors
  741. */
  742. getErrors(moduleGraph) {
  743. const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
  744. if (exportsPresence === ExportPresenceModes.ERROR) {
  745. return this._getErrors(moduleGraph);
  746. }
  747. return null;
  748. }
  749. /**
  750. * @param {ModuleGraph} moduleGraph module graph
  751. * @returns {WebpackError[] | undefined} errors
  752. */
  753. _getErrors(moduleGraph) {
  754. const ids = this.getIds(moduleGraph);
  755. let errors = this.getLinkingErrors(
  756. moduleGraph,
  757. ids,
  758. `(reexported as '${this.name}')`
  759. );
  760. if (ids.length === 0 && this.name === null) {
  761. const potentialConflicts =
  762. this._discoverActiveExportsFromOtherStarExports(moduleGraph);
  763. if (potentialConflicts && potentialConflicts.namesSlice > 0) {
  764. const ownNames = new Set(
  765. potentialConflicts.names.slice(
  766. potentialConflicts.namesSlice,
  767. potentialConflicts.dependencyIndices[
  768. potentialConflicts.dependencyIndex
  769. ]
  770. )
  771. );
  772. const importedModule = moduleGraph.getModule(this);
  773. if (importedModule) {
  774. const exportsInfo = moduleGraph.getExportsInfo(importedModule);
  775. /** @type {Map<string, string[]>} */
  776. const conflicts = new Map();
  777. for (const exportInfo of exportsInfo.orderedExports) {
  778. if (exportInfo.provided !== true) continue;
  779. if (exportInfo.name === "default") continue;
  780. if (this.activeExports.has(exportInfo.name)) continue;
  781. if (ownNames.has(exportInfo.name)) continue;
  782. const conflictingDependency = findDependencyForName(
  783. potentialConflicts,
  784. exportInfo.name,
  785. this.allStarExports
  786. ? this.allStarExports.dependencies
  787. : [...this.otherStarExports, this]
  788. );
  789. if (!conflictingDependency) continue;
  790. const target = exportInfo.getTerminalBinding(moduleGraph);
  791. if (!target) continue;
  792. const conflictingModule =
  793. /** @type {Module} */
  794. (moduleGraph.getModule(conflictingDependency));
  795. if (conflictingModule === importedModule) continue;
  796. const conflictingExportInfo = moduleGraph.getExportInfo(
  797. conflictingModule,
  798. exportInfo.name
  799. );
  800. const conflictingTarget =
  801. conflictingExportInfo.getTerminalBinding(moduleGraph);
  802. if (!conflictingTarget) continue;
  803. if (target === conflictingTarget) continue;
  804. const list = conflicts.get(conflictingDependency.request);
  805. if (list === undefined) {
  806. conflicts.set(conflictingDependency.request, [exportInfo.name]);
  807. } else {
  808. list.push(exportInfo.name);
  809. }
  810. }
  811. for (const [request, exports] of conflicts) {
  812. if (!errors) errors = [];
  813. errors.push(
  814. new HarmonyLinkingError(
  815. `The requested module '${
  816. this.request
  817. }' contains conflicting star exports for the ${
  818. exports.length > 1 ? "names" : "name"
  819. } ${exports
  820. .map(e => `'${e}'`)
  821. .join(", ")} with the previous requested module '${request}'`
  822. )
  823. );
  824. }
  825. }
  826. }
  827. }
  828. return errors;
  829. }
  830. /**
  831. * @param {ObjectSerializerContext} context context
  832. */
  833. serialize(context) {
  834. const { write, setCircularReference } = context;
  835. setCircularReference(this);
  836. write(this.ids);
  837. write(this.name);
  838. write(this.activeExports);
  839. write(this.otherStarExports);
  840. write(this.exportPresenceMode);
  841. write(this.allStarExports);
  842. super.serialize(context);
  843. }
  844. /**
  845. * @param {ObjectDeserializerContext} context context
  846. */
  847. deserialize(context) {
  848. const { read, setCircularReference } = context;
  849. setCircularReference(this);
  850. this.ids = read();
  851. this.name = read();
  852. this.activeExports = read();
  853. this.otherStarExports = read();
  854. this.exportPresenceMode = read();
  855. this.allStarExports = read();
  856. super.deserialize(context);
  857. }
  858. }
  859. makeSerializable(
  860. HarmonyExportImportedSpecifierDependency,
  861. "webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency"
  862. );
  863. module.exports = HarmonyExportImportedSpecifierDependency;
  864. HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedSpecifierDependencyTemplate extends (
  865. HarmonyImportDependency.Template
  866. ) {
  867. /**
  868. * @param {Dependency} dependency the dependency for which the template should be applied
  869. * @param {ReplaceSource} source the current replace source which can be modified
  870. * @param {DependencyTemplateContext} templateContext the context object
  871. * @returns {void}
  872. */
  873. apply(dependency, source, templateContext) {
  874. const { moduleGraph, runtime, concatenationScope } = templateContext;
  875. const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (
  876. dependency
  877. );
  878. const mode = dep.getMode(moduleGraph, runtime);
  879. if (concatenationScope) {
  880. switch (mode.type) {
  881. case "reexport-undefined":
  882. concatenationScope.registerRawExport(
  883. /** @type {NonNullable<ExportMode["name"]>} */ (mode.name),
  884. "/* reexport non-default export from non-harmony */ undefined"
  885. );
  886. }
  887. return;
  888. }
  889. if (mode.type !== "unused" && mode.type !== "empty-star") {
  890. super.apply(dependency, source, templateContext);
  891. this._addExportFragments(
  892. templateContext.initFragments,
  893. dep,
  894. mode,
  895. templateContext.module,
  896. moduleGraph,
  897. runtime,
  898. templateContext.runtimeTemplate,
  899. templateContext.runtimeRequirements
  900. );
  901. }
  902. }
  903. /**
  904. * @param {InitFragment<GenerateContext>[]} initFragments target array for init fragments
  905. * @param {HarmonyExportImportedSpecifierDependency} dep dependency
  906. * @param {ExportMode} mode the export mode
  907. * @param {Module} module the current module
  908. * @param {ModuleGraph} moduleGraph the module graph
  909. * @param {RuntimeSpec} runtime the runtime
  910. * @param {RuntimeTemplate} runtimeTemplate the runtime template
  911. * @param {RuntimeRequirements} runtimeRequirements runtime requirements
  912. * @returns {void}
  913. */
  914. _addExportFragments(
  915. initFragments,
  916. dep,
  917. mode,
  918. module,
  919. moduleGraph,
  920. runtime,
  921. runtimeTemplate,
  922. runtimeRequirements
  923. ) {
  924. const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
  925. const importVar = dep.getImportVar(moduleGraph);
  926. switch (mode.type) {
  927. case "missing":
  928. case "empty-star":
  929. initFragments.push(
  930. new InitFragment(
  931. "/* empty/unused harmony star reexport */\n",
  932. InitFragment.STAGE_HARMONY_EXPORTS,
  933. 1
  934. )
  935. );
  936. break;
  937. case "unused":
  938. initFragments.push(
  939. new InitFragment(
  940. `${Template.toNormalComment(
  941. `unused harmony reexport ${mode.name}`
  942. )}\n`,
  943. InitFragment.STAGE_HARMONY_EXPORTS,
  944. 1
  945. )
  946. );
  947. break;
  948. case "reexport-dynamic-default":
  949. initFragments.push(
  950. this.getReexportFragment(
  951. module,
  952. "reexport default from dynamic",
  953. moduleGraph
  954. .getExportsInfo(module)
  955. .getUsedName(/** @type {string} */ (mode.name), runtime),
  956. importVar,
  957. null,
  958. runtimeRequirements
  959. )
  960. );
  961. break;
  962. case "reexport-fake-namespace-object":
  963. initFragments.push(
  964. ...this.getReexportFakeNamespaceObjectFragments(
  965. module,
  966. moduleGraph
  967. .getExportsInfo(module)
  968. .getUsedName(/** @type {string} */ (mode.name), runtime),
  969. importVar,
  970. mode.fakeType,
  971. runtimeRequirements
  972. )
  973. );
  974. break;
  975. case "reexport-undefined":
  976. initFragments.push(
  977. this.getReexportFragment(
  978. module,
  979. "reexport non-default export from non-harmony",
  980. moduleGraph
  981. .getExportsInfo(module)
  982. .getUsedName(/** @type {string} */ (mode.name), runtime),
  983. "undefined",
  984. "",
  985. runtimeRequirements
  986. )
  987. );
  988. break;
  989. case "reexport-named-default":
  990. initFragments.push(
  991. this.getReexportFragment(
  992. module,
  993. "reexport default export from named module",
  994. moduleGraph
  995. .getExportsInfo(module)
  996. .getUsedName(/** @type {string} */ (mode.name), runtime),
  997. importVar,
  998. "",
  999. runtimeRequirements
  1000. )
  1001. );
  1002. break;
  1003. case "reexport-namespace-object":
  1004. initFragments.push(
  1005. this.getReexportFragment(
  1006. module,
  1007. "reexport module object",
  1008. moduleGraph
  1009. .getExportsInfo(module)
  1010. .getUsedName(/** @type {string} */ (mode.name), runtime),
  1011. importVar,
  1012. "",
  1013. runtimeRequirements
  1014. )
  1015. );
  1016. break;
  1017. case "normal-reexport":
  1018. for (const {
  1019. name,
  1020. ids,
  1021. checked,
  1022. hidden
  1023. } of /** @type {NormalReexportItem[]} */ (mode.items)) {
  1024. if (hidden) continue;
  1025. if (checked) {
  1026. const connection = moduleGraph.getConnection(dep);
  1027. const key = `harmony reexport (checked) ${importVar} ${name}`;
  1028. const runtimeCondition = dep.weak
  1029. ? false
  1030. : connection
  1031. ? filterRuntime(runtime, r => connection.isTargetActive(r))
  1032. : true;
  1033. initFragments.push(
  1034. new ConditionalInitFragment(
  1035. `/* harmony reexport (checked) */ ${this.getConditionalReexportStatement(
  1036. module,
  1037. name,
  1038. importVar,
  1039. ids,
  1040. runtimeRequirements
  1041. )}`,
  1042. moduleGraph.isAsync(importedModule)
  1043. ? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
  1044. : InitFragment.STAGE_HARMONY_IMPORTS,
  1045. dep.sourceOrder,
  1046. key,
  1047. runtimeCondition
  1048. )
  1049. );
  1050. } else {
  1051. initFragments.push(
  1052. this.getReexportFragment(
  1053. module,
  1054. "reexport safe",
  1055. moduleGraph.getExportsInfo(module).getUsedName(name, runtime),
  1056. importVar,
  1057. moduleGraph
  1058. .getExportsInfo(importedModule)
  1059. .getUsedName(ids, runtime),
  1060. runtimeRequirements
  1061. )
  1062. );
  1063. }
  1064. }
  1065. break;
  1066. case "dynamic-reexport": {
  1067. const ignored = mode.hidden
  1068. ? combine(
  1069. /** @type {ExportModeIgnored} */
  1070. (mode.ignored),
  1071. mode.hidden
  1072. )
  1073. : /** @type {ExportModeIgnored} */ (mode.ignored);
  1074. const modern =
  1075. runtimeTemplate.supportsConst() &&
  1076. runtimeTemplate.supportsArrowFunction();
  1077. let content =
  1078. "/* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};\n" +
  1079. `/* harmony reexport (unknown) */ for(${
  1080. modern ? "const" : "var"
  1081. } __WEBPACK_IMPORT_KEY__ in ${importVar}) `;
  1082. // Filter out exports which are defined by other exports
  1083. // and filter out default export because it cannot be reexported with *
  1084. if (ignored.size > 1) {
  1085. content += `if(${JSON.stringify(
  1086. Array.from(ignored)
  1087. )}.indexOf(__WEBPACK_IMPORT_KEY__) < 0) `;
  1088. } else if (ignored.size === 1) {
  1089. content += `if(__WEBPACK_IMPORT_KEY__ !== ${JSON.stringify(
  1090. first(ignored)
  1091. )}) `;
  1092. }
  1093. content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = ";
  1094. content += modern
  1095. ? `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`
  1096. : `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
  1097. runtimeRequirements.add(RuntimeGlobals.exports);
  1098. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1099. const exportsName = module.exportsArgument;
  1100. initFragments.push(
  1101. new InitFragment(
  1102. `${content}\n/* harmony reexport (unknown) */ ${RuntimeGlobals.definePropertyGetters}(${exportsName}, __WEBPACK_REEXPORT_OBJECT__);\n`,
  1103. moduleGraph.isAsync(importedModule)
  1104. ? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
  1105. : InitFragment.STAGE_HARMONY_IMPORTS,
  1106. dep.sourceOrder
  1107. )
  1108. );
  1109. break;
  1110. }
  1111. default:
  1112. throw new Error(`Unknown mode ${mode.type}`);
  1113. }
  1114. }
  1115. /**
  1116. * @param {Module} module the current module
  1117. * @param {string} comment comment
  1118. * @param {UsedName} key key
  1119. * @param {string} name name
  1120. * @param {string | string[] | null | false} valueKey value key
  1121. * @param {RuntimeRequirements} runtimeRequirements runtime requirements
  1122. * @returns {HarmonyExportInitFragment} harmony export init fragment
  1123. */
  1124. getReexportFragment(
  1125. module,
  1126. comment,
  1127. key,
  1128. name,
  1129. valueKey,
  1130. runtimeRequirements
  1131. ) {
  1132. const returnValue = this.getReturnValue(name, valueKey);
  1133. runtimeRequirements.add(RuntimeGlobals.exports);
  1134. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1135. const map = new Map();
  1136. map.set(key, `/* ${comment} */ ${returnValue}`);
  1137. return new HarmonyExportInitFragment(module.exportsArgument, map);
  1138. }
  1139. /**
  1140. * @param {Module} module module
  1141. * @param {string | string[] | false} key key
  1142. * @param {string} name name
  1143. * @param {number} fakeType fake type
  1144. * @param {RuntimeRequirements} runtimeRequirements runtime requirements
  1145. * @returns {[InitFragment<GenerateContext>, HarmonyExportInitFragment]} init fragments
  1146. */
  1147. getReexportFakeNamespaceObjectFragments(
  1148. module,
  1149. key,
  1150. name,
  1151. fakeType,
  1152. runtimeRequirements
  1153. ) {
  1154. runtimeRequirements.add(RuntimeGlobals.exports);
  1155. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1156. runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
  1157. const map = new Map();
  1158. map.set(
  1159. key,
  1160. `/* reexport fake namespace object from non-harmony */ ${name}_namespace_cache || (${name}_namespace_cache = ${
  1161. RuntimeGlobals.createFakeNamespaceObject
  1162. }(${name}${fakeType ? `, ${fakeType}` : ""}))`
  1163. );
  1164. return [
  1165. new InitFragment(
  1166. `var ${name}_namespace_cache;\n`,
  1167. InitFragment.STAGE_CONSTANTS,
  1168. -1,
  1169. `${name}_namespace_cache`
  1170. ),
  1171. new HarmonyExportInitFragment(module.exportsArgument, map)
  1172. ];
  1173. }
  1174. /**
  1175. * @param {Module} module module
  1176. * @param {string} key key
  1177. * @param {string} name name
  1178. * @param {string | string[] | false} valueKey value key
  1179. * @param {RuntimeRequirements} runtimeRequirements runtime requirements
  1180. * @returns {string} result
  1181. */
  1182. getConditionalReexportStatement(
  1183. module,
  1184. key,
  1185. name,
  1186. valueKey,
  1187. runtimeRequirements
  1188. ) {
  1189. if (valueKey === false) {
  1190. return "/* unused export */\n";
  1191. }
  1192. const exportsName = module.exportsArgument;
  1193. const returnValue = this.getReturnValue(name, valueKey);
  1194. runtimeRequirements.add(RuntimeGlobals.exports);
  1195. runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
  1196. runtimeRequirements.add(RuntimeGlobals.hasOwnProperty);
  1197. return `if(${RuntimeGlobals.hasOwnProperty}(${name}, ${JSON.stringify(
  1198. valueKey[0]
  1199. )})) ${
  1200. RuntimeGlobals.definePropertyGetters
  1201. }(${exportsName}, { ${propertyName(
  1202. key
  1203. )}: function() { return ${returnValue}; } });\n`;
  1204. }
  1205. /**
  1206. * @param {string} name name
  1207. * @param {null | false | string | string[]} valueKey value key
  1208. * @returns {string | undefined} value
  1209. */
  1210. getReturnValue(name, valueKey) {
  1211. if (valueKey === null) {
  1212. return `${name}_default.a`;
  1213. }
  1214. if (valueKey === "") {
  1215. return name;
  1216. }
  1217. if (valueKey === false) {
  1218. return "/* unused export */ undefined";
  1219. }
  1220. return `${name}${propertyAccess(valueKey)}`;
  1221. }
  1222. };
  1223. class HarmonyStarExportsList {
  1224. constructor() {
  1225. /** @type {HarmonyExportImportedSpecifierDependency[]} */
  1226. this.dependencies = [];
  1227. }
  1228. /**
  1229. * @param {HarmonyExportImportedSpecifierDependency} dep dependency
  1230. * @returns {void}
  1231. */
  1232. push(dep) {
  1233. this.dependencies.push(dep);
  1234. }
  1235. slice() {
  1236. return this.dependencies.slice();
  1237. }
  1238. /**
  1239. * @param {ObjectSerializerContext} context context
  1240. */
  1241. serialize({ write, setCircularReference }) {
  1242. setCircularReference(this);
  1243. write(this.dependencies);
  1244. }
  1245. /**
  1246. * @param {ObjectDeserializerContext} context context
  1247. */
  1248. deserialize({ read, setCircularReference }) {
  1249. setCircularReference(this);
  1250. this.dependencies = read();
  1251. }
  1252. }
  1253. makeSerializable(
  1254. HarmonyStarExportsList,
  1255. "webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency",
  1256. "HarmonyStarExportsList"
  1257. );
  1258. module.exports.HarmonyStarExportsList = HarmonyStarExportsList;