UNPKG

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