ImportEagerDependency.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const makeSerializable = require("../util/makeSerializable");
  7. const ImportDependency = require("./ImportDependency");
  8. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  9. /** @typedef {import("../Dependency")} Dependency */
  10. /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
  11. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  12. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  13. class ImportEagerDependency extends ImportDependency {
  14. /**
  15. * @param {string} request the request
  16. * @param {[number, number]} range expression range
  17. * @param {string[][]=} referencedExports list of referenced exports
  18. */
  19. constructor(request, range, referencedExports) {
  20. super(request, range, referencedExports);
  21. }
  22. get type() {
  23. return "import() eager";
  24. }
  25. get category() {
  26. return "esm";
  27. }
  28. }
  29. makeSerializable(
  30. ImportEagerDependency,
  31. "webpack/lib/dependencies/ImportEagerDependency"
  32. );
  33. ImportEagerDependency.Template = class ImportEagerDependencyTemplate extends (
  34. ImportDependency.Template
  35. ) {
  36. /**
  37. * @param {Dependency} dependency the dependency for which the template should be applied
  38. * @param {ReplaceSource} source the current replace source which can be modified
  39. * @param {DependencyTemplateContext} templateContext the context object
  40. * @returns {void}
  41. */
  42. apply(
  43. dependency,
  44. source,
  45. { runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
  46. ) {
  47. const dep = /** @type {ImportEagerDependency} */ (dependency);
  48. const content = runtimeTemplate.moduleNamespacePromise({
  49. chunkGraph,
  50. module: moduleGraph.getModule(dep),
  51. request: dep.request,
  52. strict: module.buildMeta.strictHarmonyModule,
  53. message: "import() eager",
  54. runtimeRequirements
  55. });
  56. source.replace(dep.range[0], dep.range[1] - 1, content);
  57. }
  58. };
  59. module.exports = ImportEagerDependency;