UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

84 lines (83 loc) 3.63 kB
"use strict"; var __extends = (this && this.__extends)/* istanbul ignore next */ || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __values = (this && this.__values)/* istanbul ignore next */ || function (o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; }; Object.defineProperty(exports, "__esModule", { value: true }); var typescript_1 = require("./../../typescript"); var errors = require("./../../errors"); var manipulation_1 = require("./../../manipulation"); var callBaseFill_1 = require("./../callBaseFill"); var common_1 = require("./../common"); var base_1 = require("./../base"); var function_1 = require("./../function"); var base_2 = require("./base"); exports.SetAccessorDeclarationBase = base_1.ChildOrderableNode(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))))))))); var SetAccessorDeclaration = /** @class */ (function (_super) { __extends(SetAccessorDeclaration, _super); function SetAccessorDeclaration() { return _super !== null && _super.apply(this, arguments) || this; } /** * Fills the node from a structure. * @param structure - Structure to fill. */ SetAccessorDeclaration.prototype.fill = function (structure) { callBaseFill_1.callBaseFill(exports.SetAccessorDeclarationBase.prototype, this, structure); return this; }; /** * Gets the corresponding get accessor if one exists. */ SetAccessorDeclaration.prototype.getGetAccessor = function () { var parent = this.getParentIfKindOrThrow(typescript_1.SyntaxKind.ClassDeclaration); var thisName = this.getName(); try { for (var _a = __values(parent.getInstanceProperties()), _b = _a.next(); !_b.done; _b = _a.next()) { var prop = _b.value; if (prop.getKind() === typescript_1.SyntaxKind.GetAccessor && prop.getName() === thisName) return prop; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } } return undefined; var e_1, _c; }; /** * Gets the corresponding get accessor or throws if not exists. */ SetAccessorDeclaration.prototype.getGetAccessorOrThrow = function () { var _this = this; return errors.throwIfNullOrUndefined(this.getGetAccessor(), function () { return "Expected to find a corresponding get accessor for " + _this.getName() + "."; }); }; /** * Removes the set accessor. */ SetAccessorDeclaration.prototype.remove = function () { manipulation_1.removeClassMember(this); }; return SetAccessorDeclaration; }(exports.SetAccessorDeclarationBase)); exports.SetAccessorDeclaration = SetAccessorDeclaration;