URLContextDependency.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Haijie Xie @hai-x
  4. */
  5. "use strict";
  6. const makeSerializable = require("../util/makeSerializable");
  7. const ContextDependency = require("./ContextDependency");
  8. const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
  9. /** @import { ContextOptions } from "../ContextModule" */
  10. /** @import { Range } from "../javascript/JavascriptParser" */
  11. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range]>} ObjectDeserializerContext */
  12. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range]>} ObjectSerializerContext */
  13. /** @typedef {ContextOptions & { request: string }} ContextDependencyOptions */
  14. class URLContextDependency extends ContextDependency {
  15. /**
  16. * Creates an instance of URLContextDependency.
  17. * @param {ContextDependencyOptions} options options
  18. * @param {Range} range range
  19. * @param {Range} valueRange value range
  20. */
  21. constructor(options, range, valueRange) {
  22. super(options);
  23. this.range = range;
  24. this.valueRange = valueRange;
  25. }
  26. get type() {
  27. return "new URL() context";
  28. }
  29. get category() {
  30. return "url";
  31. }
  32. /**
  33. * Serializes this instance into the provided serializer context.
  34. * @param {ObjectSerializerContext} context context
  35. */
  36. serialize(context) {
  37. context.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. this.valueRange = context.read();
  46. super.deserialize(context.rest);
  47. }
  48. }
  49. makeSerializable(
  50. URLContextDependency,
  51. "webpack/lib/dependencies/URLContextDependency"
  52. );
  53. URLContextDependency.Template = ContextDependencyTemplateAsRequireCall;
  54. module.exports = URLContextDependency;