ConstDependency.js 731 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const NullDependency = require("./NullDependency");
  7. class ConstDependency extends NullDependency {
  8. constructor(expression, range) {
  9. super();
  10. this.expression = expression;
  11. this.range = range;
  12. }
  13. updateHash(hash) {
  14. hash.update(this.range + "");
  15. hash.update(this.expression + "");
  16. }
  17. }
  18. ConstDependency.Template = class ConstDependencyTemplate {
  19. apply(dep, source) {
  20. if(typeof dep.range === "number") {
  21. source.insert(dep.range, dep.expression);
  22. return;
  23. }
  24. source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
  25. }
  26. };
  27. module.exports = ConstDependency;