RequireResolveContextDependency.js 1.7 KB

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