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.

48 lines
1.2 KiB

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. const HarmonyImportDependency = require("./HarmonyImportDependency");
  8. class HarmonyAcceptDependency extends NullDependency {
  9. constructor(range, dependencies, hasCallback) {
  10. super();
  11. this.range = range;
  12. this.dependencies = dependencies;
  13. this.hasCallback = hasCallback;
  14. }
  15. get type() {
  16. return "accepted harmony modules";
  17. }
  18. }
  19. HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate {
  20. apply(dep, source, runtime) {
  21. const content = dep.dependencies
  22. .filter(dependency =>
  23. HarmonyImportDependency.Template.isImportEmitted(dependency, source)
  24. )
  25. .map(dependency => dependency.getImportStatement(true, runtime))
  26. .join("");
  27. if (dep.hasCallback) {
  28. source.insert(
  29. dep.range[0],
  30. `function(__WEBPACK_OUTDATED_DEPENDENCIES__) { ${content}(`
  31. );
  32. source.insert(
  33. dep.range[1],
  34. ")(__WEBPACK_OUTDATED_DEPENDENCIES__); }.bind(this)"
  35. );
  36. return;
  37. }
  38. source.insert(dep.range[1] - 0.5, `, function() { ${content} }`);
  39. }
  40. };
  41. module.exports = HarmonyAcceptDependency;