parse-error.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _exportNames = {
  6. ParseErrorEnum: true,
  7. Errors: true
  8. };
  9. exports.Errors = void 0;
  10. exports.ParseErrorEnum = ParseErrorEnum;
  11. var _location = require("./util/location");
  12. var _credentials = require("./parse-error/credentials");
  13. Object.keys(_credentials).forEach(function (key) {
  14. if (key === "default" || key === "__esModule") return;
  15. if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  16. if (key in exports && exports[key] === _credentials[key]) return;
  17. Object.defineProperty(exports, key, {
  18. enumerable: true,
  19. get: function () {
  20. return _credentials[key];
  21. }
  22. });
  23. });
  24. var _moduleErrors = require("./parse-error/module-errors");
  25. var _standardErrors = require("./parse-error/standard-errors");
  26. var _strictModeErrors = require("./parse-error/strict-mode-errors");
  27. var _pipelineOperatorErrors = require("./parse-error/pipeline-operator-errors");
  28. const _excluded = ["toMessage"],
  29. _excluded2 = ["message"];
  30. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  31. function toParseErrorConstructor(_ref) {
  32. let {
  33. toMessage
  34. } = _ref,
  35. properties = _objectWithoutPropertiesLoose(_ref, _excluded);
  36. return function constructor({
  37. loc,
  38. details
  39. }) {
  40. return (0, _credentials.instantiate)(SyntaxError, Object.assign({}, properties, {
  41. loc
  42. }), {
  43. clone(overrides = {}) {
  44. const loc = overrides.loc || {};
  45. return constructor({
  46. loc: new _location.Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index),
  47. details: Object.assign({}, this.details, overrides.details)
  48. });
  49. },
  50. details: {
  51. value: details,
  52. enumerable: false
  53. },
  54. message: {
  55. get() {
  56. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  57. },
  58. set(value) {
  59. Object.defineProperty(this, "message", {
  60. value
  61. });
  62. }
  63. },
  64. pos: {
  65. reflect: "loc.index",
  66. enumerable: true
  67. },
  68. missingPlugin: "missingPlugin" in details && {
  69. reflect: "details.missingPlugin",
  70. enumerable: true
  71. }
  72. });
  73. };
  74. }
  75. function ParseErrorEnum(argument, syntaxPlugin) {
  76. if (Array.isArray(argument)) {
  77. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  78. }
  79. const ParseErrorConstructors = {};
  80. for (const reasonCode of Object.keys(argument)) {
  81. const template = argument[reasonCode];
  82. const _ref2 = typeof template === "string" ? {
  83. message: () => template
  84. } : typeof template === "function" ? {
  85. message: template
  86. } : template,
  87. {
  88. message
  89. } = _ref2,
  90. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
  91. const toMessage = typeof message === "string" ? () => message : message;
  92. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  93. code: _credentials.ParseErrorCode.SyntaxError,
  94. reasonCode,
  95. toMessage
  96. }, syntaxPlugin ? {
  97. syntaxPlugin
  98. } : {}, rest));
  99. }
  100. return ParseErrorConstructors;
  101. }
  102. const Errors = Object.assign({}, ParseErrorEnum(_moduleErrors.default), ParseErrorEnum(_standardErrors.default), ParseErrorEnum(_strictModeErrors.default), ParseErrorEnum`pipelineOperator`(_pipelineOperatorErrors.default));
  103. exports.Errors = Errors;
  104. //# sourceMappingURL=parse-error.js.map