You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
768 B

4 years ago
  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 LocalModuleDependency extends NullDependency {
  8. constructor(localModule, range, callNew) {
  9. super();
  10. localModule.flagUsed();
  11. this.localModule = localModule;
  12. this.range = range;
  13. this.callNew = callNew;
  14. }
  15. }
  16. LocalModuleDependency.Template = class LocalModuleDependencyTemplate {
  17. apply(dep, source) {
  18. if (!dep.range) return;
  19. const moduleInstance = dep.callNew
  20. ? `new (function () { return ${dep.localModule.variableName()}; })()`
  21. : dep.localModule.variableName();
  22. source.replace(dep.range[0], dep.range[1] - 1, moduleInstance);
  23. }
  24. };
  25. module.exports = LocalModuleDependency;