UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

40 lines (38 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const errors = require("./../../errors"); const manipulation_1 = require("./../../manipulation"); const common_1 = require("./../common"); const base_1 = require("./../base"); const function_1 = require("./../function"); const base_2 = require("./base"); exports.GetAccessorDeclarationBase = base_1.TextInsertableNode(base_1.DecoratableNode(base_2.AbstractableNode(base_1.ScopedNode(base_1.StaticableNode(base_1.BodiedNode(function_1.FunctionLikeDeclaration(base_1.PropertyNamedNode(common_1.Node)))))))); class GetAccessorDeclaration extends exports.GetAccessorDeclarationBase { /** * Gets the corresponding set accessor if one exists. */ getSetAccessor() { const parent = this.getParentIfKindOrThrow(ts.SyntaxKind.ClassDeclaration); const thisName = this.getName(); for (const prop of parent.getInstanceProperties()) { if (prop.getName() === thisName && prop.getKind() === ts.SyntaxKind.SetAccessor) return prop; } return undefined; } /** * Gets the corresponding set accessor or throws if not exists. */ getSetAccessorOrThrow() { return errors.throwIfNullOrUndefined(this.getSetAccessor(), () => `Expected to find a corresponding set accessor for ${this.getName()}.`); } /** * Removes the get accessor. */ remove() { manipulation_1.removeClassMember(this); } } exports.GetAccessorDeclaration = GetAccessorDeclaration; //# sourceMappingURL=GetAccessorDeclaration.js.map