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.

54 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. class HarmonyExportSpecifierDependency extends NullDependency {
  8. constructor(originModule, id, name) {
  9. super();
  10. this.originModule = originModule;
  11. this.id = id;
  12. this.name = name;
  13. }
  14. get type() {
  15. return "harmony export specifier";
  16. }
  17. getExports() {
  18. return {
  19. exports: [this.name],
  20. dependencies: undefined
  21. };
  22. }
  23. }
  24. HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate {
  25. apply(dep, source) {}
  26. getHarmonyInitOrder(dep) {
  27. return 0;
  28. }
  29. harmonyInit(dep, source, runtime) {
  30. const content = this.getContent(dep);
  31. source.insert(-1, content);
  32. }
  33. getContent(dep) {
  34. const used = dep.originModule.isUsed(dep.name);
  35. if (!used) {
  36. return `/* unused harmony export ${dep.name || "namespace"} */\n`;
  37. }
  38. const exportsName = dep.originModule.exportsArgument;
  39. return `/* harmony export (binding) */ __webpack_require__.d(${exportsName}, ${JSON.stringify(
  40. used
  41. )}, function() { return ${dep.id}; });\n`;
  42. }
  43. };
  44. module.exports = HarmonyExportSpecifierDependency;