ImportContextDependency.js 1.6 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 ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
  9. /** @typedef {import("../javascript/JavascriptParser").Range} Range */
  10. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  11. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  12. class ImportContextDependency extends ContextDependency {
  13. /**
  14. * @param {TODO} options options
  15. * @param {Range} range range
  16. * @param {Range} valueRange value range
  17. */
  18. constructor(options, range, valueRange) {
  19. super(options);
  20. this.range = range;
  21. this.valueRange = valueRange;
  22. }
  23. get type() {
  24. return `import() context ${this.options.mode}`;
  25. }
  26. get category() {
  27. return "esm";
  28. }
  29. /**
  30. * @param {ObjectSerializerContext} context context
  31. */
  32. serialize(context) {
  33. const { write } = context;
  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.valueRange = read();
  43. super.deserialize(context);
  44. }
  45. }
  46. makeSerializable(
  47. ImportContextDependency,
  48. "webpack/lib/dependencies/ImportContextDependency"
  49. );
  50. ImportContextDependency.Template = ContextDependencyTemplateAsRequireCall;
  51. module.exports = ImportContextDependency;