UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

47 lines (46 loc) 2.16 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.VariableDeclarationBase = base_1.TypedNode(base_1.InitializerExpressionableNode(base_1.BindingNamedNode(common_1.Node))); var VariableDeclaration = /** @class */ (function (_super) { __extends(VariableDeclaration, _super); function VariableDeclaration() { return _super !== null && _super.apply(this, arguments) || this; } /** * Fills this node with the specified structure. * @param structure - Structure to fill. */ VariableDeclaration.prototype.fill = function (structure) { callBaseFill_1.callBaseFill(exports.VariableDeclarationBase.prototype, this, structure); return this; }; /** * Removes this variable declaration. */ VariableDeclaration.prototype.remove = function () { var variableStatement = this.getParentIfKindOrThrow(ts.SyntaxKind.VariableDeclarationList) .getParentIfKindOrThrow(ts.SyntaxKind.VariableStatement); var declarations = variableStatement.getDeclarations(); if (declarations.length === 1) variableStatement.remove(); else manipulation_1.removeCommaSeparatedChild(this, { removePrecedingSpaces: declarations[0] === this ? false : undefined }); }; return VariableDeclaration; }(exports.VariableDeclarationBase)); exports.VariableDeclaration = VariableDeclaration;