AMDRequireContextDependency.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ContextDependency = require("./ContextDependency");
  8. /** @typedef {import("../javascript/JavascriptParser").Range} Range */
  9. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  10. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  11. /** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
  12. class AMDRequireContextDependency extends ContextDependency {
  13. /**
  14. * Creates an instance of AMDRequireContextDependency.
  15. * @param {ContextDependencyOptions} options options
  16. * @param {Range} range range
  17. * @param {Range} valueRange value range
  18. */
  19. constructor(options, range, valueRange) {
  20. super(options);
  21. this.range = range;
  22. this.valueRange = valueRange;
  23. }
  24. get type() {
  25. return "amd require context";
  26. }
  27. get category() {
  28. return "amd";
  29. }
  30. /**
  31. * Serializes this instance into the provided serializer context.
  32. * @param {ObjectSerializerContext} context context
  33. */
  34. serialize(context) {
  35. const { write } = context;
  36. write(this.range);
  37. write(this.valueRange);
  38. super.serialize(context);
  39. }
  40. /**
  41. * Restores this instance from the provided deserializer context.
  42. * @param {ObjectDeserializerContext} context context
  43. */
  44. deserialize(context) {
  45. const { read } = context;
  46. this.range = read();
  47. this.valueRange = read();
  48. super.deserialize(context);
  49. }
  50. }
  51. makeSerializable(
  52. AMDRequireContextDependency,
  53. "webpack/lib/dependencies/AMDRequireContextDependency"
  54. );
  55. AMDRequireContextDependency.Template = require("./ContextDependencyTemplateAsRequireCall");
  56. module.exports = AMDRequireContextDependency;