CommonJsRequireContextDependency.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 CommonJsRequireContextDependency extends ContextDependency {
  10. constructor(options, range, valueRange, inShorthand, context) {
  11. super(options, context);
  12. this.range = range;
  13. this.valueRange = valueRange;
  14. // inShorthand must be serialized by subclasses that use it
  15. this.inShorthand = inShorthand;
  16. }
  17. get type() {
  18. return "cjs require context";
  19. }
  20. serialize(context) {
  21. const { write } = context;
  22. write(this.range);
  23. write(this.valueRange);
  24. write(this.inShorthand);
  25. super.serialize(context);
  26. }
  27. deserialize(context) {
  28. const { read } = context;
  29. this.range = read();
  30. this.valueRange = read();
  31. this.inShorthand = read();
  32. super.deserialize(context);
  33. }
  34. }
  35. makeSerializable(
  36. CommonJsRequireContextDependency,
  37. "webpack/lib/dependencies/CommonJsRequireContextDependency"
  38. );
  39. CommonJsRequireContextDependency.Template =
  40. ContextDependencyTemplateAsRequireCall;
  41. module.exports = CommonJsRequireContextDependency;