UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

57 lines (56 loc) 2.61 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 base_1 = require("./../base"); var common_1 = require("./../common"); exports.TypeParameterDeclarationBase = base_1.NamedNode(common_1.Node); var TypeParameterDeclaration = /** @class */ (function (_super) { __extends(TypeParameterDeclaration, _super); function TypeParameterDeclaration() { return _super !== null && _super.apply(this, arguments) || this; } /** * Gets the constraint node. */ TypeParameterDeclaration.prototype.getConstraintNode = function () { return this.compilerNode.constraint == null ? undefined : this.global.compilerFactory.getNodeFromCompilerNode(this.compilerNode.constraint, this.sourceFile); }; /** * Gets the default node. */ TypeParameterDeclaration.prototype.getDefaultNode = function () { return this.compilerNode.default == null ? undefined : this.global.compilerFactory.getNodeFromCompilerNode(this.compilerNode.default, this.sourceFile); }; /** * Removes this type parameter. */ TypeParameterDeclaration.prototype.remove = function () { var parentSyntaxList = this.getParentSyntaxListOrThrow(); var typeParameters = parentSyntaxList.getChildrenOfKind(ts.SyntaxKind.TypeParameter); if (typeParameters.length === 1) removeAllTypeParameters(); else manipulation_1.removeCommaSeparatedChild(this); function removeAllTypeParameters() { var children = [ parentSyntaxList.getPreviousSiblingIfKindOrThrow(ts.SyntaxKind.FirstBinaryOperator), parentSyntaxList, parentSyntaxList.getNextSiblingIfKindOrThrow(ts.SyntaxKind.GreaterThanToken) ]; manipulation_1.removeChildren({ children: children }); } }; return TypeParameterDeclaration; }(exports.TypeParameterDeclarationBase)); exports.TypeParameterDeclaration = TypeParameterDeclaration;