UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

55 lines (53 loc) 1.88 kB
"use strict"; var __decorate = (this && this.__decorate) || 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 }); const utils_1 = require("./../../../utils"); const TextSpan_1 = require("./TextSpan"); /** * Document span. */ class DocumentSpan { /** * @internal */ constructor(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().getDescendantAtPos(this.getTextSpan().getStart()); } /** * Gets the compiler object. */ get compilerObject() { return this._compilerObject; } /** * Gets the source file this reference is in. */ getSourceFile() { return this.global.compilerFactory.getSourceFileFromFilePath(this.compilerObject.fileName); } /** * Gets the text span. */ getTextSpan() { return new TextSpan_1.TextSpan(this.compilerObject.textSpan); } /** * Gets the node at the start of the text span. */ getNode() { return this.node; } } __decorate([ utils_1.Memoize ], DocumentSpan.prototype, "getTextSpan", null); exports.DocumentSpan = DocumentSpan; //# sourceMappingURL=DocumentSpan.js.map