Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

HarmonyAcceptDependency.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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;