LocalModule.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, number, boolean]>} ObjectDeserializerContext */
  8. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, number, boolean]>} ObjectSerializerContext */
  9. class LocalModule {
  10. /**
  11. * Creates an instance of LocalModule.
  12. * @param {string} name name
  13. * @param {number} idx index
  14. */
  15. constructor(name, idx) {
  16. /** @type {string} */
  17. this.name = name;
  18. /** @type {number} */
  19. this.idx = idx;
  20. /** @type {boolean} */
  21. this.used = false;
  22. }
  23. flagUsed() {
  24. this.used = true;
  25. }
  26. /**
  27. * Returns variable name.
  28. * @returns {string} variable name
  29. */
  30. variableName() {
  31. return `__WEBPACK_LOCAL_MODULE_${this.idx}__`;
  32. }
  33. /**
  34. * Serializes this instance into the provided serializer context.
  35. * @param {ObjectSerializerContext} context context
  36. */
  37. serialize(context) {
  38. context.write(this.name).write(this.idx).write(this.used);
  39. }
  40. /**
  41. * Restores this instance from the provided deserializer context.
  42. * @param {ObjectDeserializerContext} context context
  43. */
  44. deserialize(context) {
  45. this.name = context.read();
  46. const c1 = context.rest;
  47. this.idx = c1.read();
  48. const c2 = c1.rest;
  49. this.used = c2.read();
  50. }
  51. }
  52. makeSerializable(LocalModule, "webpack/lib/dependencies/LocalModule");
  53. module.exports = LocalModule;