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