ImportContextDependency.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. class ImportContextDependency extends ContextDependency {
  10. constructor(options, range, valueRange) {
  11. super(options);
  12. this.range = range;
  13. this.valueRange = valueRange;
  14. }
  15. get type() {
  16. return `import() context ${this.options.mode}`;
  17. }
  18. get category() {
  19. return "esm";
  20. }
  21. serialize(context) {
  22. const { write } = context;
  23. write(this.valueRange);
  24. super.serialize(context);
  25. }
  26. deserialize(context) {
  27. const { read } = context;
  28. this.valueRange = read();
  29. super.deserialize(context);
  30. }
  31. }
  32. makeSerializable(
  33. ImportContextDependency,
  34. "webpack/lib/dependencies/ImportContextDependency"
  35. );
  36. ImportContextDependency.Template = ContextDependencyTemplateAsRequireCall;
  37. module.exports = ImportContextDependency;