UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

94 lines (93 loc) 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var utils_1 = require("../../../utils"); var DiagnosticMessageChain_1 = require("./DiagnosticMessageChain"); /** * Diagnostic. */ var Diagnostic = /** @class */ (function () { /** @private */ function Diagnostic(context, compilerObject) { this._context = context; this._compilerObject = compilerObject; // memoize this.getSourceFile(); } Object.defineProperty(Diagnostic.prototype, "compilerObject", { /** * Gets the underlying compiler diagnostic. */ get: function () { return this._compilerObject; }, enumerable: true, configurable: true }); /** * Gets the source file. */ Diagnostic.prototype.getSourceFile = function () { if (this._context == null) return undefined; var file = this.compilerObject.file; return file == null ? undefined : this._context.compilerFactory.getSourceFile(file, { markInProject: false }); }; /** * Gets the message text. */ Diagnostic.prototype.getMessageText = function () { var messageText = this._compilerObject.messageText; if (typeof messageText === "string") return messageText; if (this._context == null) return new DiagnosticMessageChain_1.DiagnosticMessageChain(messageText); else return this._context.compilerFactory.getDiagnosticMessageChain(messageText); }; /** * Gets the line number. */ Diagnostic.prototype.getLineNumber = function () { var sourceFile = this.getSourceFile(); var start = this.getStart(); if (sourceFile == null || start == null) return undefined; return sourceFile.getLineNumberAtPos(start); }; /** * Gets the start. */ Diagnostic.prototype.getStart = function () { return this.compilerObject.start; }; /** * Gets the length. */ Diagnostic.prototype.getLength = function () { return this.compilerObject.length; }; /** * Gets the diagnostic category. */ Diagnostic.prototype.getCategory = function () { return this.compilerObject.category; }; /** * Gets the code of the diagnostic. */ Diagnostic.prototype.getCode = function () { return this.compilerObject.code; }; /** * Gets the source. */ Diagnostic.prototype.getSource = function () { return this.compilerObject.source; }; tslib_1.__decorate([ utils_1.Memoize ], Diagnostic.prototype, "getSourceFile", null); return Diagnostic; }()); exports.Diagnostic = Diagnostic;