StaticExportsDependency.js 1.9 KB

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