UI for Zipcoin Blue

AMDDefineDependency.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 AMDDefineDependency extends NullDependency {
  8. constructor(range, arrayRange, functionRange, objectRange, namedModule) {
  9. super();
  10. this.range = range;
  11. this.arrayRange = arrayRange;
  12. this.functionRange = functionRange;
  13. this.objectRange = objectRange;
  14. this.namedModule = namedModule;
  15. }
  16. get type() {
  17. return "amd define";
  18. }
  19. }
  20. AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
  21. get definitions() {
  22. return {
  23. f: [
  24. "var __WEBPACK_AMD_DEFINE_RESULT__;",
  25. `!(__WEBPACK_AMD_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module),
  26. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
  27. ],
  28. o: [
  29. "",
  30. "!(module.exports = #)"
  31. ],
  32. of: [
  33. "var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;",
  34. `!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#),
  35. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  36. (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
  37. __WEBPACK_AMD_DEFINE_FACTORY__),
  38. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
  39. ],
  40. af: [
  41. "var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;",
  42. `!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  43. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
  44. ],
  45. ao: [
  46. "",
  47. "!(#, module.exports = #)"
  48. ],
  49. aof: [
  50. "var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;",
  51. `!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_FACTORY__ = (#),
  52. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  53. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  54. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
  55. ],
  56. lf: [
  57. "var XXX, XXXmodule;",
  58. "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = #.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))"
  59. ],
  60. lo: [
  61. "var XXX;",
  62. "!(XXX = #)"
  63. ],
  64. lof: [
  65. "var XXX, XXXfactory, XXXmodule;",
  66. "!(XXXfactory = (#), (XXXmodule = { id: YYY, exports: {}, loaded: false }), XXX = (typeof XXXfactory === 'function' ? (XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)) : XXXfactory), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports))"
  67. ],
  68. laf: [
  69. "var __WEBPACK_AMD_DEFINE_ARRAY__, XXX;",
  70. "!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = (#.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))"
  71. ],
  72. lao: [
  73. "var XXX;",
  74. "!(#, XXX = #)"
  75. ],
  76. laof: [
  77. "var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_FACTORY__, XXX;",
  78. `!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_FACTORY__ = (#),
  79. XXX = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  80. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__))`
  81. ]
  82. };
  83. }
  84. apply(dependency, source) {
  85. const branch = this.branch(dependency);
  86. const defAndText = this.definitions[branch];
  87. const definitions = defAndText[0];
  88. const text = defAndText[1];
  89. this.replace(dependency, source, definitions, text);
  90. }
  91. localModuleVar(dependency) {
  92. return dependency.localModule && dependency.localModule.used && dependency.localModule.variableName();
  93. }
  94. branch(dependency) {
  95. const localModuleVar = this.localModuleVar(dependency) ? "l" : "";
  96. const arrayRange = dependency.arrayRange ? "a" : "";
  97. const objectRange = dependency.objectRange ? "o" : "";
  98. const functionRange = dependency.functionRange ? "f" : "";
  99. return localModuleVar + arrayRange + objectRange + functionRange;
  100. }
  101. replace(dependency, source, definition, text) {
  102. const localModuleVar = this.localModuleVar(dependency);
  103. if(localModuleVar) {
  104. text = text.replace(/XXX/g, localModuleVar.replace(/\$/g, "$$$$"));
  105. definition = definition.replace(/XXX/g, localModuleVar.replace(/\$/g, "$$$$"));
  106. }
  107. if(dependency.namedModule) {
  108. text = text.replace(/YYY/g, JSON.stringify(dependency.namedModule));
  109. }
  110. const texts = text.split("#");
  111. if(definition) source.insert(0, definition);
  112. let current = dependency.range[0];
  113. if(dependency.arrayRange) {
  114. source.replace(current, dependency.arrayRange[0] - 1, texts.shift());
  115. current = dependency.arrayRange[1];
  116. }
  117. if(dependency.objectRange) {
  118. source.replace(current, dependency.objectRange[0] - 1, texts.shift());
  119. current = dependency.objectRange[1];
  120. } else if(dependency.functionRange) {
  121. source.replace(current, dependency.functionRange[0] - 1, texts.shift());
  122. current = dependency.functionRange[1];
  123. }
  124. source.replace(current, dependency.range[1] - 1, texts.shift());
  125. if(texts.length > 0)
  126. throw new Error("Implementation error");
  127. }
  128. };
  129. module.exports = AMDDefineDependency;