a zip code crypto-currency system good for red ONLY

HarmonyImportDependency.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. var ModuleDependency = require("./ModuleDependency");
  7. class HarmonyImportDependency extends ModuleDependency {
  8. constructor(request, importedVar, range) {
  9. super(request);
  10. this.range = range;
  11. this.importedVar = importedVar;
  12. }
  13. get type() {
  14. return "harmony import";
  15. }
  16. getReference() {
  17. if(!this.module) return null;
  18. return {
  19. module: this.module,
  20. importedNames: false
  21. };
  22. }
  23. updateHash(hash) {
  24. super.updateHash(hash);
  25. hash.update((this.module && (!this.module.meta || this.module.meta.harmonyModule)) + "");
  26. }
  27. }
  28. HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate {
  29. apply(dep, source, outputOptions, requestShortener) {
  30. const content = makeImportStatement(true, dep, outputOptions, requestShortener);
  31. source.replace(dep.range[0], dep.range[1] - 1, "");
  32. source.insert(-1, content);
  33. }
  34. };
  35. function getOptionalComment(pathinfo, shortenedRequest) {
  36. if(!pathinfo) {
  37. return "";
  38. }
  39. return `/*! ${shortenedRequest} */ `;
  40. }
  41. function makeImportStatement(declare, dep, outputOptions, requestShortener) {
  42. const comment = getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
  43. const declaration = declare ? "var " : "";
  44. const newline = declare ? "\n" : " ";
  45. if(!dep.module) {
  46. const stringifiedError = JSON.stringify(`Cannot find module "${dep.request}"`);
  47. return `throw new Error(${stringifiedError});${newline}`;
  48. }
  49. if(dep.importedVar) {
  50. const isHarmonyModule = dep.module.meta && dep.module.meta.harmonyModule;
  51. const content = `/* harmony import */ ${declaration}${dep.importedVar} = __webpack_require__(${comment}${JSON.stringify(dep.module.id)});${newline}`;
  52. if(isHarmonyModule) {
  53. return content;
  54. }
  55. return `${content}/* harmony import */ ${declaration}${dep.importedVar}_default = __webpack_require__.n(${dep.importedVar});${newline}`;
  56. }
  57. return "";
  58. }
  59. HarmonyImportDependency.makeImportStatement = makeImportStatement;
  60. module.exports = HarmonyImportDependency;