a zip code crypto-currency system good for red ONLY

AMDRequireDependenciesBlockParserPlugin.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const AMDRequireItemDependency = require("./AMDRequireItemDependency");
  7. const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
  8. const AMDRequireContextDependency = require("./AMDRequireContextDependency");
  9. const AMDRequireDependenciesBlock = require("./AMDRequireDependenciesBlock");
  10. const UnsupportedDependency = require("./UnsupportedDependency");
  11. const LocalModuleDependency = require("./LocalModuleDependency");
  12. const ContextDependencyHelpers = require("./ContextDependencyHelpers");
  13. const LocalModulesHelpers = require("./LocalModulesHelpers");
  14. const ConstDependency = require("./ConstDependency");
  15. const getFunctionExpression = require("./getFunctionExpression");
  16. const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
  17. class AMDRequireDependenciesBlockParserPlugin {
  18. constructor(options) {
  19. this.options = options;
  20. }
  21. processFunctionArgument(parser, expression) {
  22. let bindThis = true;
  23. const fnData = getFunctionExpression(expression);
  24. if(fnData) {
  25. parser.inScope(fnData.fn.params.filter((i) => {
  26. return ["require", "module", "exports"].indexOf(i.name) < 0;
  27. }), () => {
  28. if(fnData.fn.body.type === "BlockStatement")
  29. parser.walkStatement(fnData.fn.body);
  30. else
  31. parser.walkExpression(fnData.fn.body);
  32. });
  33. parser.walkExpressions(fnData.expressions);
  34. if(fnData.needThis === false) {
  35. bindThis = false;
  36. }
  37. } else {
  38. parser.walkExpression(expression);
  39. }
  40. return bindThis;
  41. }
  42. apply(parser) {
  43. const options = this.options;
  44. parser.plugin("call require", (expr) => {
  45. let param;
  46. let dep;
  47. let result;
  48. const old = parser.state.current;
  49. if(expr.arguments.length >= 1) {
  50. param = parser.evaluateExpression(expr.arguments[0]);
  51. dep = new AMDRequireDependenciesBlock(
  52. expr,
  53. param.range,
  54. (expr.arguments.length > 1) ? expr.arguments[1].range : null,
  55. (expr.arguments.length > 2) ? expr.arguments[2].range : null,
  56. parser.state.module,
  57. expr.loc
  58. );
  59. parser.state.current = dep;
  60. }
  61. if(expr.arguments.length === 1) {
  62. parser.inScope([], () => {
  63. result = parser.applyPluginsBailResult("call require:amd:array", expr, param);
  64. });
  65. parser.state.current = old;
  66. if(!result) return;
  67. parser.state.current.addBlock(dep);
  68. return true;
  69. }
  70. if(expr.arguments.length === 2 || expr.arguments.length === 3) {
  71. try {
  72. parser.inScope([], () => {
  73. result = parser.applyPluginsBailResult("call require:amd:array", expr, param);
  74. });
  75. if(!result) {
  76. dep = new UnsupportedDependency("unsupported", expr.range);
  77. old.addDependency(dep);
  78. if(parser.state.module)
  79. parser.state.module.errors.push(new UnsupportedFeatureWarning(parser.state.module, "Cannot statically analyse 'require(..., ...)' in line " + expr.loc.start.line));
  80. dep = null;
  81. return true;
  82. }
  83. dep.functionBindThis = this.processFunctionArgument(parser, expr.arguments[1]);
  84. if(expr.arguments.length === 3) {
  85. dep.errorCallbackBindThis = this.processFunctionArgument(parser, expr.arguments[2]);
  86. }
  87. } finally {
  88. parser.state.current = old;
  89. if(dep)
  90. parser.state.current.addBlock(dep);
  91. }
  92. return true;
  93. }
  94. });
  95. parser.plugin("call require:amd:array", (expr, param) => {
  96. if(param.isArray()) {
  97. param.items.forEach((param) => {
  98. const result = parser.applyPluginsBailResult("call require:amd:item", expr, param);
  99. if(result === undefined) {
  100. parser.applyPluginsBailResult("call require:amd:context", expr, param);
  101. }
  102. });
  103. return true;
  104. } else if(param.isConstArray()) {
  105. const deps = [];
  106. param.array.forEach((request) => {
  107. let dep, localModule;
  108. if(request === "require") {
  109. dep = "__webpack_require__";
  110. } else if(["exports", "module"].indexOf(request) >= 0) {
  111. dep = request;
  112. } else if(localModule = LocalModulesHelpers.getLocalModule(parser.state, request)) { // eslint-disable-line no-cond-assign
  113. dep = new LocalModuleDependency(localModule);
  114. dep.loc = expr.loc;
  115. parser.state.current.addDependency(dep);
  116. } else {
  117. dep = new AMDRequireItemDependency(request);
  118. dep.loc = expr.loc;
  119. dep.optional = !!parser.scope.inTry;
  120. parser.state.current.addDependency(dep);
  121. }
  122. deps.push(dep);
  123. });
  124. const dep = new AMDRequireArrayDependency(deps, param.range);
  125. dep.loc = expr.loc;
  126. dep.optional = !!parser.scope.inTry;
  127. parser.state.current.addDependency(dep);
  128. return true;
  129. }
  130. });
  131. parser.plugin("call require:amd:item", (expr, param) => {
  132. if(param.isConditional()) {
  133. param.options.forEach((param) => {
  134. const result = parser.applyPluginsBailResult("call require:amd:item", expr, param);
  135. if(result === undefined) {
  136. parser.applyPluginsBailResult("call require:amd:context", expr, param);
  137. }
  138. });
  139. return true;
  140. } else if(param.isString()) {
  141. let dep, localModule;
  142. if(param.string === "require") {
  143. dep = new ConstDependency("__webpack_require__", param.string);
  144. } else if(param.string === "module") {
  145. dep = new ConstDependency(parser.state.module.moduleArgument || "module", param.range);
  146. } else if(param.string === "exports") {
  147. dep = new ConstDependency(parser.state.module.exportsArgument || "exports", param.range);
  148. } else if(localModule = LocalModulesHelpers.getLocalModule(parser.state, param.string)) { // eslint-disable-line no-cond-assign
  149. dep = new LocalModuleDependency(localModule, param.range);
  150. } else {
  151. dep = new AMDRequireItemDependency(param.string, param.range);
  152. }
  153. dep.loc = expr.loc;
  154. dep.optional = !!parser.scope.inTry;
  155. parser.state.current.addDependency(dep);
  156. return true;
  157. }
  158. });
  159. parser.plugin("call require:amd:context", (expr, param) => {
  160. const dep = ContextDependencyHelpers.create(AMDRequireContextDependency, param.range, param, expr, options);
  161. if(!dep) return;
  162. dep.loc = expr.loc;
  163. dep.optional = !!parser.scope.inTry;
  164. parser.state.current.addDependency(dep);
  165. return true;
  166. });
  167. }
  168. }
  169. module.exports = AMDRequireDependenciesBlockParserPlugin;