UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

59 lines (57 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const manipulation_1 = require("./../../manipulation"); const callBaseFill_1 = require("./../callBaseFill"); const common_1 = require("./../common"); const base_1 = require("./../base"); exports.EnumMemberBase = base_1.DocumentationableNode(base_1.InitializerExpressionableNode(base_1.PropertyNamedNode(common_1.Node))); class EnumMember extends exports.EnumMemberBase { /** * Fills the node from a structure. * @param structure - Structure to fill. */ fill(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. */ getValue() { return this.global.typeChecker.getConstantValue(this); } /** * Sets the enum value. * @param value - Enum value. */ setValue(value) { let text; if (typeof value === "string") { const stringChar = this.global.manipulationSettings.getStringChar(); text = stringChar + value + stringChar; } else { text = value.toString(); } this.setInitializer(text); return this; } /** * Removes this enum member. */ remove() { const childrenToRemove = [this]; const commaToken = this.getNextSiblingIfKind(ts.SyntaxKind.CommaToken); if (commaToken != null) childrenToRemove.push(commaToken); manipulation_1.removeChildrenWithFormatting({ children: childrenToRemove, getSiblingFormatting: () => manipulation_1.FormattingKind.Newline }); } } exports.EnumMember = EnumMember; //# sourceMappingURL=EnumMember.js.map