UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

58 lines (57 loc) 2.25 kB
"use strict"; var __decorate = (this && this.__decorate)/* istanbul ignore next */ || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("./../../../utils"); var TextSpan_1 = require("./TextSpan"); /** * Document span. */ var DocumentSpan = /** @class */ (function () { /** * @internal */ function DocumentSpan(global, compilerObject) { this.global = global; this._compilerObject = compilerObject; // store this node so that it's start doesn't go out of date because of manipulation (though the text span may) this.node = this.getSourceFile().getDescendantAtStartWithWidth(this.getTextSpan().getStart(), this.getTextSpan().getLength()); } Object.defineProperty(DocumentSpan.prototype, "compilerObject", { /** * Gets the compiler object. */ get: function () { return this._compilerObject; }, enumerable: true, configurable: true }); /** * Gets the source file this reference is in. */ DocumentSpan.prototype.getSourceFile = function () { return this.global.compilerFactory.getSourceFileFromFilePath(this.compilerObject.fileName); }; /** * Gets the text span. */ DocumentSpan.prototype.getTextSpan = function () { return new TextSpan_1.TextSpan(this.compilerObject.textSpan); }; /** * Gets the node at the start of the text span. */ DocumentSpan.prototype.getNode = function () { return this.node; }; __decorate([ utils_1.Memoize ], DocumentSpan.prototype, "getTextSpan", null); return DocumentSpan; }()); exports.DocumentSpan = DocumentSpan;