AMDRequireArrayDependency.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Dependency = require("../Dependency");
  7. class AMDRequireArrayDependency extends Dependency {
  8. constructor(depsArray, range) {
  9. super();
  10. this.depsArray = depsArray;
  11. this.range = range;
  12. }
  13. get type() {
  14. return "amd require array";
  15. }
  16. }
  17. AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate {
  18. apply(dep, source, runtime) {
  19. const content = this.getContent(dep, runtime);
  20. source.replace(dep.range[0], dep.range[1] - 1, content);
  21. }
  22. getContent(dep, runtime) {
  23. const requires = dep.depsArray.map(dependency => {
  24. return this.contentForDependency(dependency, runtime);
  25. });
  26. return `[${requires.join(", ")}]`;
  27. }
  28. contentForDependency(dep, runtime) {
  29. if (typeof dep === "string") {
  30. return dep;
  31. }
  32. if (dep.localModule) {
  33. return dep.localModule.variableName();
  34. } else {
  35. return runtime.moduleExports({
  36. module: dep.module,
  37. request: dep.request
  38. });
  39. }
  40. }
  41. };
  42. module.exports = AMDRequireArrayDependency;