a zip code crypto-currency system good for red ONLY

ImportWeakDependency.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ModuleDependency = require("./ModuleDependency");
  7. const webpackMissingPromiseModule = require("./WebpackMissingModule").promise;
  8. class ImportWeakDependency extends ModuleDependency {
  9. constructor(request, range) {
  10. super(request);
  11. this.range = range;
  12. this.weak = true;
  13. }
  14. get type() {
  15. return "import() weak";
  16. }
  17. }
  18. ImportWeakDependency.Template = class ImportDependencyTemplate {
  19. apply(dep, source, outputOptions, requestShortener) {
  20. const comment = this.getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
  21. const content = this.getContent(dep, comment);
  22. source.replace(dep.range[0], dep.range[1] - 1, content);
  23. }
  24. getOptionalComment(pathinfo, shortenedRequest) {
  25. if(!pathinfo) {
  26. return "";
  27. }
  28. return `/*! ${shortenedRequest} */ `;
  29. }
  30. getContent(dep, comment) {
  31. if(dep.module) {
  32. const stringifiedId = JSON.stringify(dep.module.id);
  33. return `Promise.resolve(${comment}${stringifiedId}).then(function(id) { if(!__webpack_require__.m[id]) throw new Error("Module '" + id + "' is not available (weak dependency)"); return __webpack_require__(id); })`;
  34. }
  35. return webpackMissingPromiseModule(dep.request);
  36. }
  37. };
  38. module.exports = ImportWeakDependency;