LocalModule.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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} ObjectDeserializerContext */
  8. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  9. class LocalModule {
  10. /**
  11. * @param {string} name name
  12. * @param {number} idx index
  13. */
  14. constructor(name, idx) {
  15. this.name = name;
  16. this.idx = idx;
  17. this.used = false;
  18. }
  19. flagUsed() {
  20. this.used = true;
  21. }
  22. /**
  23. * @returns {string} variable name
  24. */
  25. variableName() {
  26. return "__WEBPACK_LOCAL_MODULE_" + this.idx + "__";
  27. }
  28. /**
  29. * @param {ObjectSerializerContext} context context
  30. */
  31. serialize(context) {
  32. const { write } = context;
  33. write(this.name);
  34. write(this.idx);
  35. write(this.used);
  36. }
  37. /**
  38. * @param {ObjectDeserializerContext} context context
  39. */
  40. deserialize(context) {
  41. const { read } = context;
  42. this.name = read();
  43. this.idx = read();
  44. this.used = read();
  45. }
  46. }
  47. makeSerializable(LocalModule, "webpack/lib/dependencies/LocalModule");
  48. module.exports = LocalModule;