UNPKG

2.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ParserMessage = void 0;
4/**
5 * Represents an error or warning that occurred during parsing.
6 */
7var ParserMessage = /** @class */ (function () {
8 function ParserMessage(parameters) {
9 this.messageId = parameters.messageId;
10 this.unformattedText = parameters.messageText;
11 this.textRange = parameters.textRange;
12 this.tokenSequence = parameters.tokenSequence;
13 this.docNode = parameters.docNode;
14 this._text = undefined;
15 }
16 /**
17 * Generates a line/column prefix. Example with line=2 and column=5
18 * and message="An error occurred":
19 * ```
20 * "(2,5): An error occurred"
21 * ```
22 */
23 ParserMessage._formatMessageText = function (message, range) {
24 if (!message) {
25 message = 'An unknown error occurred';
26 }
27 if (range.pos !== 0 || range.end !== 0) {
28 // NOTE: This currently a potentially expensive operation, since TSDoc currently doesn't
29 // have a full newline analysis for the input buffer.
30 var location_1 = range.getLocation(range.pos);
31 if (location_1.line) {
32 return "(" + location_1.line + "," + location_1.column + "): " + message;
33 }
34 }
35 return message;
36 };
37 Object.defineProperty(ParserMessage.prototype, "text", {
38 /**
39 * The message text.
40 */
41 get: function () {
42 if (this._text === undefined) {
43 // NOTE: This currently a potentially expensive operation, since TSDoc currently doesn't
44 // have a full newline analysis for the input buffer.
45 this._text = ParserMessage._formatMessageText(this.unformattedText, this.textRange);
46 }
47 return this._text;
48 },
49 enumerable: false,
50 configurable: true
51 });
52 ParserMessage.prototype.toString = function () {
53 return this.text;
54 };
55 return ParserMessage;
56}());
57exports.ParserMessage = ParserMessage;
58//# sourceMappingURL=ParserMessage.js.map
\No newline at end of file