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.SetAccessorDeclarationBase = 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 SetAccessorDeclaration extends exports.SetAccessorDeclarationBase { /** * Gets the corresponding get accessor if one exists. */ getGetAccessor() { const parent = this.getParentIfKindOrThrow(ts.SyntaxKind.ClassDeclaration); const thisName = this.getName(); for (const prop of parent.getInstanceProperties()) { if (prop.getKind() === ts.SyntaxKind.GetAccessor && prop.getName() === thisName) return prop; } return undefined; } /** * Gets the corresponding get accessor or throws if not exists. */ getGetAccessorOrThrow() { return errors.throwIfNullOrUndefined(this.getGetAccessor(), () => `Expected to find a corresponding get accessor for ${this.getName()}.`); } /** * Removes the set accessor. */ remove() { manipulation_1.removeClassMember(this); } } exports.SetAccessorDeclaration = SetAccessorDeclaration; //# sourceMappingURL=SetAccessorDeclaration.js.map