a zip code crypto-currency system good for red ONLY

MainTemplate.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ConcatSource = require("webpack-sources").ConcatSource;
  7. const OriginalSource = require("webpack-sources").OriginalSource;
  8. const PrefixSource = require("webpack-sources").PrefixSource;
  9. const Template = require("./Template");
  10. // require function shortcuts:
  11. // __webpack_require__.s = the module id of the entry point
  12. // __webpack_require__.c = the module cache
  13. // __webpack_require__.m = the module functions
  14. // __webpack_require__.p = the bundle public path
  15. // __webpack_require__.i = the identity function used for harmony imports
  16. // __webpack_require__.e = the chunk ensure function
  17. // __webpack_require__.d = the exported propery define getter function
  18. // __webpack_require__.o = Object.prototype.hasOwnProperty.call
  19. // __webpack_require__.n = compatibility get default export
  20. // __webpack_require__.h = the webpack hash
  21. // __webpack_require__.oe = the uncatched error handler for the webpack runtime
  22. // __webpack_require__.nc = the script nonce
  23. module.exports = class MainTemplate extends Template {
  24. constructor(outputOptions) {
  25. super(outputOptions);
  26. this.plugin("startup", (source, chunk, hash) => {
  27. const buf = [];
  28. if(chunk.entryModule) {
  29. buf.push("// Load entry module and return exports");
  30. buf.push(`return ${this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id))}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`);
  31. }
  32. return this.asString(buf);
  33. });
  34. this.plugin("render", (bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
  35. const source = new ConcatSource();
  36. source.add("/******/ (function(modules) { // webpackBootstrap\n");
  37. source.add(new PrefixSource("/******/", bootstrapSource));
  38. source.add("/******/ })\n");
  39. source.add("/************************************************************************/\n");
  40. source.add("/******/ (");
  41. const modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
  42. source.add(this.applyPluginsWaterfall("modules", modules, chunk, hash, moduleTemplate, dependencyTemplates));
  43. source.add(")");
  44. return source;
  45. });
  46. this.plugin("local-vars", (source, chunk, hash) => {
  47. return this.asString([
  48. source,
  49. "// The module cache",
  50. "var installedModules = {};"
  51. ]);
  52. });
  53. this.plugin("require", (source, chunk, hash) => {
  54. return this.asString([
  55. source,
  56. "// Check if module is in cache",
  57. "if(installedModules[moduleId]) {",
  58. this.indent("return installedModules[moduleId].exports;"),
  59. "}",
  60. "// Create a new module (and put it into the cache)",
  61. "var module = installedModules[moduleId] = {",
  62. this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
  63. "};",
  64. "",
  65. this.asString(outputOptions.strictModuleExceptionHandling ? [
  66. "// Execute the module function",
  67. "var threw = true;",
  68. "try {",
  69. this.indent([
  70. `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
  71. "threw = false;"
  72. ]),
  73. "} finally {",
  74. this.indent([
  75. "if(threw) delete installedModules[moduleId];"
  76. ]),
  77. "}"
  78. ] : [
  79. "// Execute the module function",
  80. `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
  81. ]),
  82. "",
  83. "// Flag the module as loaded",
  84. "module.l = true;",
  85. "",
  86. "// Return the exports of the module",
  87. "return module.exports;"
  88. ]);
  89. });
  90. this.plugin("module-obj", (source, chunk, hash, varModuleId) => {
  91. return this.asString([
  92. "i: moduleId,",
  93. "l: false,",
  94. "exports: {}"
  95. ]);
  96. });
  97. this.plugin("require-extensions", (source, chunk, hash) => {
  98. const buf = [];
  99. if(chunk.chunks.length > 0) {
  100. buf.push("// This file contains only the entry chunk.");
  101. buf.push("// The chunk loading function for additional chunks");
  102. buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
  103. buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
  104. buf.push("};");
  105. }
  106. buf.push("");
  107. buf.push("// expose the modules object (__webpack_modules__)");
  108. buf.push(`${this.requireFn}.m = modules;`);
  109. buf.push("");
  110. buf.push("// expose the module cache");
  111. buf.push(`${this.requireFn}.c = installedModules;`);
  112. buf.push("");
  113. buf.push("// define getter function for harmony exports");
  114. buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
  115. buf.push(this.indent([
  116. `if(!${this.requireFn}.o(exports, name)) {`,
  117. this.indent([
  118. "Object.defineProperty(exports, name, {",
  119. this.indent([
  120. "configurable: false,",
  121. "enumerable: true,",
  122. "get: getter"
  123. ]),
  124. "});"
  125. ]),
  126. "}"
  127. ]));
  128. buf.push("};");
  129. buf.push("");
  130. buf.push("// getDefaultExport function for compatibility with non-harmony modules");
  131. buf.push(this.requireFn + ".n = function(module) {");
  132. buf.push(this.indent([
  133. "var getter = module && module.__esModule ?",
  134. this.indent([
  135. "function getDefault() { return module['default']; } :",
  136. "function getModuleExports() { return module; };"
  137. ]),
  138. `${this.requireFn}.d(getter, 'a', getter);`,
  139. "return getter;"
  140. ]));
  141. buf.push("};");
  142. buf.push("");
  143. buf.push("// Object.prototype.hasOwnProperty.call");
  144. buf.push(`${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`);
  145. const publicPath = this.getPublicPath({
  146. hash: hash
  147. });
  148. buf.push("");
  149. buf.push("// __webpack_public_path__");
  150. buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
  151. return this.asString(buf);
  152. });
  153. this.requireFn = "__webpack_require__";
  154. }
  155. render(hash, chunk, moduleTemplate, dependencyTemplates) {
  156. const buf = [];
  157. buf.push(this.applyPluginsWaterfall("bootstrap", "", chunk, hash, moduleTemplate, dependencyTemplates));
  158. buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
  159. buf.push("");
  160. buf.push("// The require function");
  161. buf.push(`function ${this.requireFn}(moduleId) {`);
  162. buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
  163. buf.push("}");
  164. buf.push("");
  165. buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
  166. buf.push("");
  167. buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
  168. let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
  169. if(chunk.hasEntryModule()) {
  170. source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
  171. }
  172. if(!source) throw new Error("Compiler error: MainTemplate plugin 'render' should return something");
  173. chunk.rendered = true;
  174. return new ConcatSource(source, ";");
  175. }
  176. renderRequireFunctionForModule(hash, chunk, varModuleId) {
  177. return this.applyPluginsWaterfall("module-require", this.requireFn, chunk, hash, varModuleId);
  178. }
  179. renderAddModule(hash, chunk, varModuleId, varModule) {
  180. return this.applyPluginsWaterfall("add-module", `modules[${varModuleId}] = ${varModule};`, chunk, hash, varModuleId, varModule);
  181. }
  182. renderCurrentHashCode(hash, length) {
  183. length = length || Infinity;
  184. return this.applyPluginsWaterfall("current-hash", JSON.stringify(hash.substr(0, length)), length);
  185. }
  186. entryPointInChildren(chunk) {
  187. const checkChildren = (chunk, alreadyCheckedChunks) => {
  188. return chunk.chunks.some((child) => {
  189. if(alreadyCheckedChunks.indexOf(child) >= 0) return;
  190. alreadyCheckedChunks.push(child);
  191. return child.hasEntryModule() || checkChildren(child, alreadyCheckedChunks);
  192. });
  193. };
  194. return checkChildren(chunk, []);
  195. }
  196. getPublicPath(options) {
  197. return this.applyPluginsWaterfall("asset-path", this.outputOptions.publicPath || "", options);
  198. }
  199. updateHash(hash) {
  200. hash.update("maintemplate");
  201. hash.update("3");
  202. hash.update(this.outputOptions.publicPath + "");
  203. this.applyPlugins("hash", hash);
  204. }
  205. updateHashForChunk(hash, chunk) {
  206. this.updateHash(hash);
  207. this.applyPlugins("hash-for-chunk", hash, chunk);
  208. }
  209. useChunkHash(chunk) {
  210. const paths = this.applyPluginsWaterfall("global-hash-paths", []);
  211. return !this.applyPluginsBailResult("global-hash", chunk, paths);
  212. }
  213. };