StaticExportsDependency.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 NullDependency = require("./NullDependency");
  8. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  9. /** @typedef {import("../Dependency").ExportSpec} ExportSpec */
  10. /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
  11. /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
  12. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  13. /** @typedef {import("../util/Hash")} Hash */
  14. class StaticExportsDependency extends NullDependency {
  15. /**
  16. * @param {string[] | true} exports export names
  17. * @param {boolean} canMangle true, if mangling exports names is allowed
  18. */
  19. constructor(exports, canMangle) {
  20. super();
  21. this.exports = exports;
  22. this.canMangle = canMangle;
  23. }
  24. get type() {
  25. return "static exports";
  26. }
  27. /**
  28. * Returns the exported names
  29. * @param {ModuleGraph} moduleGraph module graph
  30. * @returns {ExportsSpec | undefined} export names
  31. */
  32. getExports(moduleGraph) {
  33. return {
  34. exports: this.exports,
  35. canMangle: this.canMangle,
  36. dependencies: undefined
  37. };
  38. }
  39. serialize(context) {
  40. const { write } = context;
  41. write(this.exports);
  42. write(this.canMangle);
  43. super.serialize(context);
  44. }
  45. deserialize(context) {
  46. const { read } = context;
  47. this.exports = read();
  48. this.canMangle = read();
  49. super.deserialize(context);
  50. }
  51. }
  52. makeSerializable(
  53. StaticExportsDependency,
  54. "webpack/lib/dependencies/StaticExportsDependency"
  55. );
  56. module.exports = StaticExportsDependency;