HarmonyExportHeaderDependency.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 NullDependency = require("./NullDependency");
  8. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  9. /** @typedef {import("../Dependency")} Dependency */
  10. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  11. class HarmonyExportHeaderDependency extends NullDependency {
  12. constructor(range, rangeStatement) {
  13. super();
  14. this.range = range;
  15. this.rangeStatement = rangeStatement;
  16. }
  17. get type() {
  18. return "harmony export header";
  19. }
  20. serialize(context) {
  21. const { write } = context;
  22. write(this.range);
  23. write(this.rangeStatement);
  24. super.serialize(context);
  25. }
  26. deserialize(context) {
  27. const { read } = context;
  28. this.range = read();
  29. this.rangeStatement = read();
  30. super.deserialize(context);
  31. }
  32. }
  33. makeSerializable(
  34. HarmonyExportHeaderDependency,
  35. "webpack/lib/dependencies/HarmonyExportHeaderDependency"
  36. );
  37. HarmonyExportHeaderDependency.Template = class HarmonyExportDependencyTemplate extends (
  38. NullDependency.Template
  39. ) {
  40. /**
  41. * @param {Dependency} dependency the dependency for which the template should be applied
  42. * @param {ReplaceSource} source the current replace source which can be modified
  43. * @param {DependencyTemplateContext} templateContext the context object
  44. * @returns {void}
  45. */
  46. apply(dependency, source, templateContext) {
  47. const dep = /** @type {HarmonyExportHeaderDependency} */ (dependency);
  48. const content = "";
  49. const replaceUntil = dep.range
  50. ? dep.range[0] - 1
  51. : dep.rangeStatement[1] - 1;
  52. source.replace(dep.rangeStatement[0], replaceUntil, content);
  53. }
  54. };
  55. module.exports = HarmonyExportHeaderDependency;