StaticExportsDependency.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /** @import { ExportsSpec } from "../Dependency" */
  9. /** @import ModuleGraph from "../ModuleGraph" */
  10. /** @typedef {string[] | true} Exports */
  11. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Exports, boolean]>} ObjectDeserializerContext */
  12. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Exports, boolean]>} ObjectSerializerContext */
  13. class StaticExportsDependency extends NullDependency {
  14. /**
  15. * Creates an instance of StaticExportsDependency.
  16. * @param {Exports} exports export names
  17. * @param {boolean} canMangle true, if mangling exports names is allowed
  18. */
  19. constructor(exports, canMangle) {
  20. super();
  21. /** @type {Exports} */
  22. this.exports = exports;
  23. /** @type {boolean} */
  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. * Serializes this instance into the provided serializer context.
  43. * @param {ObjectSerializerContext} context context
  44. */
  45. serialize(context) {
  46. context.write(this.exports).write(this.canMangle);
  47. super.serialize(context);
  48. }
  49. /**
  50. * Restores this instance from the provided deserializer context.
  51. * @param {ObjectDeserializerContext} context context
  52. */
  53. deserialize(context) {
  54. this.exports = context.read();
  55. const c1 = context.rest;
  56. this.canMangle = c1.read();
  57. super.deserialize(c1.rest);
  58. }
  59. }
  60. makeSerializable(
  61. StaticExportsDependency,
  62. "webpack/lib/dependencies/StaticExportsDependency"
  63. );
  64. module.exports = StaticExportsDependency;