a zip code crypto-currency system good for red ONLY

HarmonyExportSpecifierDependency.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, position, immutable) {
  9. super();
  10. this.originModule = originModule;
  11. this.id = id;
  12. this.name = name;
  13. this.position = position;
  14. this.immutable = immutable;
  15. }
  16. get type() {
  17. return "harmony export specifier";
  18. }
  19. getExports() {
  20. return {
  21. exports: [this.name]
  22. };
  23. }
  24. }
  25. HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate {
  26. apply(dep, source) {
  27. const content = this.getPrefix(dep) + this.getContent(dep);
  28. source.insert(dep.position, content);
  29. }
  30. getPrefix(dep) {
  31. return dep.position > 0 ? "\n" : "";
  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 || "exports";
  39. if(dep.immutable) {
  40. return `/* harmony export (immutable) */ ${exportsName}[${JSON.stringify(used)}] = ${dep.id};\n`;
  41. }
  42. return `/* harmony export (binding) */ __webpack_require__.d(${exportsName}, ${JSON.stringify(used)}, function() { return ${dep.id}; });\n`;
  43. }
  44. };
  45. module.exports = HarmonyExportSpecifierDependency;