UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const path = require("path");
  7. const AMDRequireDependency = require("./AMDRequireDependency");
  8. const AMDRequireItemDependency = require("./AMDRequireItemDependency");
  9. const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
  10. const AMDRequireContextDependency = require("./AMDRequireContextDependency");
  11. const AMDDefineDependency = require("./AMDDefineDependency");
  12. const UnsupportedDependency = require("./UnsupportedDependency");
  13. const LocalModuleDependency = require("./LocalModuleDependency");
  14. const NullFactory = require("../NullFactory");
  15. const AMDRequireDependenciesBlockParserPlugin = require("./AMDRequireDependenciesBlockParserPlugin");
  16. const AMDDefineDependencyParserPlugin = require("./AMDDefineDependencyParserPlugin");
  17. const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
  18. const ParserHelpers = require("../ParserHelpers");
  19. class AMDPlugin {
  20. constructor(options, amdOptions) {
  21. this.amdOptions = amdOptions;
  22. this.options = options;
  23. }
  24. apply(compiler) {
  25. const options = this.options;
  26. const amdOptions = this.amdOptions;
  27. compiler.plugin("compilation", (compilation, params) => {
  28. const normalModuleFactory = params.normalModuleFactory;
  29. const contextModuleFactory = params.contextModuleFactory;
  30. compilation.dependencyFactories.set(AMDRequireDependency, new NullFactory());
  31. compilation.dependencyTemplates.set(AMDRequireDependency, new AMDRequireDependency.Template());
  32. compilation.dependencyFactories.set(AMDRequireItemDependency, normalModuleFactory);
  33. compilation.dependencyTemplates.set(AMDRequireItemDependency, new AMDRequireItemDependency.Template());
  34. compilation.dependencyFactories.set(AMDRequireArrayDependency, new NullFactory());
  35. compilation.dependencyTemplates.set(AMDRequireArrayDependency, new AMDRequireArrayDependency.Template());
  36. compilation.dependencyFactories.set(AMDRequireContextDependency, contextModuleFactory);
  37. compilation.dependencyTemplates.set(AMDRequireContextDependency, new AMDRequireContextDependency.Template());
  38. compilation.dependencyFactories.set(AMDDefineDependency, new NullFactory());
  39. compilation.dependencyTemplates.set(AMDDefineDependency, new AMDDefineDependency.Template());
  40. compilation.dependencyFactories.set(UnsupportedDependency, new NullFactory());
  41. compilation.dependencyTemplates.set(UnsupportedDependency, new UnsupportedDependency.Template());
  42. compilation.dependencyFactories.set(LocalModuleDependency, new NullFactory());
  43. compilation.dependencyTemplates.set(LocalModuleDependency, new LocalModuleDependency.Template());
  44. params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
  45. if(typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
  46. return;
  47. function setExpressionToModule(outerExpr, module) {
  48. parser.plugin("expression " + outerExpr, (expr) => {
  49. const dep = new AMDRequireItemDependency(module, expr.range);
  50. dep.userRequest = outerExpr;
  51. dep.loc = expr.loc;
  52. parser.state.current.addDependency(dep);
  53. return true;
  54. });
  55. }
  56. parser.apply(
  57. new AMDRequireDependenciesBlockParserPlugin(options),
  58. new AMDDefineDependencyParserPlugin(options)
  59. );
  60. setExpressionToModule("require.amd", "!!webpack amd options");
  61. setExpressionToModule("define.amd", "!!webpack amd options");
  62. setExpressionToModule("define", "!!webpack amd define");
  63. parser.plugin("expression __webpack_amd_options__", () =>
  64. parser.state.current.addVariable("__webpack_amd_options__", JSON.stringify(amdOptions)));
  65. parser.plugin("evaluate typeof define.amd", ParserHelpers.evaluateToString(typeof amdOptions));
  66. parser.plugin("evaluate typeof require.amd", ParserHelpers.evaluateToString(typeof amdOptions));
  67. parser.plugin("evaluate Identifier define.amd", ParserHelpers.evaluateToIdentifier("define.amd", true));
  68. parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToIdentifier("require.amd", true));
  69. parser.plugin("typeof define", ParserHelpers.toConstantDependency(JSON.stringify("function")));
  70. parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
  71. parser.plugin("can-rename define", ParserHelpers.approve);
  72. parser.plugin("rename define", (expr) => {
  73. const dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
  74. dep.userRequest = "define";
  75. dep.loc = expr.loc;
  76. parser.state.current.addDependency(dep);
  77. return false;
  78. });
  79. parser.plugin("typeof require", ParserHelpers.toConstantDependency(JSON.stringify("function")));
  80. parser.plugin("evaluate typeof require", ParserHelpers.evaluateToString("function"));
  81. });
  82. });
  83. compiler.plugin("after-resolvers", () => {
  84. compiler.resolvers.normal.apply(
  85. new AliasPlugin("described-resolve", {
  86. name: "amdefine",
  87. alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
  88. }, "resolve"),
  89. new AliasPlugin("described-resolve", {
  90. name: "webpack amd options",
  91. alias: path.join(__dirname, "..", "..", "buildin", "amd-options.js")
  92. }, "resolve"),
  93. new AliasPlugin("described-resolve", {
  94. name: "webpack amd define",
  95. alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
  96. }, "resolve")
  97. );
  98. });
  99. }
  100. }
  101. module.exports = AMDPlugin;