UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

72 lines (71 loc) 2.71 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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ts = require("typescript"); var manipulation_1 = require("./../../manipulation"); var callBaseFill_1 = require("./../callBaseFill"); var common_1 = require("./../common"); var base_1 = require("./../base"); exports.EnumMemberBase = base_1.DocumentationableNode(base_1.InitializerExpressionableNode(base_1.PropertyNamedNode(common_1.Node))); var EnumMember = /** @class */ (function (_super) { __extends(EnumMember, _super); function EnumMember() { return _super !== null && _super.apply(this, arguments) || this; } /** * Fills the node from a structure. * @param structure - Structure to fill. */ EnumMember.prototype.fill = function (structure) { callBaseFill_1.callBaseFill(exports.EnumMemberBase.prototype, this, structure); if (structure.value != null) this.setValue(structure.value); return this; }; /** * Gets the constant value of the enum. */ EnumMember.prototype.getValue = function () { return this.global.typeChecker.getConstantValue(this); }; /** * Sets the enum value. * @param value - Enum value. */ EnumMember.prototype.setValue = function (value) { var text; if (typeof value === "string") { var quoteType = this.global.manipulationSettings.getQuoteType(); text = quoteType + value + quoteType; } else { text = value.toString(); } this.setInitializer(text); return this; }; /** * Removes this enum member. */ EnumMember.prototype.remove = function () { var childrenToRemove = [this]; var commaToken = this.getNextSiblingIfKind(ts.SyntaxKind.CommaToken); if (commaToken != null) childrenToRemove.push(commaToken); manipulation_1.removeChildrenWithFormatting({ children: childrenToRemove, getSiblingFormatting: function () { return manipulation_1.FormattingKind.Newline; } }); }; return EnumMember; }(exports.EnumMemberBase)); exports.EnumMember = EnumMember;