a zip code crypto-currency system good for red ONLY

ImportParserPlugin.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ImportEagerContextDependency = require("./ImportEagerContextDependency");
  7. const ImportWeakDependency = require("./ImportWeakDependency");
  8. const ImportWeakContextDependency = require("./ImportWeakContextDependency");
  9. const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
  10. const ImportLazyContextDependency = require("./ImportLazyContextDependency");
  11. const ImportDependenciesBlock = require("./ImportDependenciesBlock");
  12. const ImportEagerDependency = require("./ImportEagerDependency");
  13. const ContextDependencyHelpers = require("./ContextDependencyHelpers");
  14. const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
  15. class ImportParserPlugin {
  16. constructor(options) {
  17. this.options = options;
  18. }
  19. apply(parser) {
  20. const options = this.options;
  21. parser.plugin(["call System.import", "import-call"], (expr) => {
  22. if(expr.arguments.length !== 1)
  23. throw new Error("Incorrect number of arguments provided to 'import(module: string) -> Promise'.");
  24. const param = parser.evaluateExpression(expr.arguments[0]);
  25. let chunkName = null;
  26. let mode = "lazy";
  27. const importOptions = parser.getCommentOptions(expr.range);
  28. if(importOptions) {
  29. if(typeof importOptions.webpackChunkName !== "undefined") {
  30. if(typeof importOptions.webpackChunkName !== "string")
  31. parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`));
  32. else
  33. chunkName = importOptions.webpackChunkName;
  34. }
  35. if(typeof importOptions.webpackMode !== "undefined") {
  36. if(typeof importOptions.webpackMode !== "string")
  37. parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`));
  38. else
  39. mode = importOptions.webpackMode;
  40. }
  41. }
  42. if(param.isString()) {
  43. if(mode !== "lazy" && mode !== "eager" && mode !== "weak") {
  44. parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`));
  45. }
  46. if(mode === "eager") {
  47. const dep = new ImportEagerDependency(param.string, expr.range);
  48. parser.state.current.addDependency(dep);
  49. } else if(mode === "weak") {
  50. const dep = new ImportWeakDependency(param.string, expr.range);
  51. parser.state.current.addDependency(dep);
  52. } else {
  53. const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
  54. parser.state.current.addBlock(depBlock);
  55. }
  56. return true;
  57. } else {
  58. if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager" && mode !== "weak") {
  59. parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`));
  60. }
  61. let Dep = ImportLazyContextDependency;
  62. if(mode === "eager") {
  63. Dep = ImportEagerContextDependency;
  64. } else if(mode === "weak") {
  65. Dep = ImportWeakContextDependency;
  66. } else if(mode === "lazy-once") {
  67. Dep = ImportLazyOnceContextDependency;
  68. }
  69. const dep = ContextDependencyHelpers.create(Dep, expr.range, param, expr, options, chunkName);
  70. if(!dep) return;
  71. dep.loc = expr.loc;
  72. dep.optional = !!parser.scope.inTry;
  73. parser.state.current.addDependency(dep);
  74. return true;
  75. }
  76. });
  77. }
  78. }
  79. module.exports = ImportParserPlugin;