ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
57 lines (56 loc) • 2.54 kB
JavaScript
;
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 typescript_1 = 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 of the type parameter.
*/
TypeParameterDeclaration.prototype.getConstraintNode = function () {
return this.getNodeFromCompilerNodeIfExists(this.compilerNode.constraint);
};
/**
* Gets the default node of the type parameter.
*/
TypeParameterDeclaration.prototype.getDefaultNode = function () {
return this.getNodeFromCompilerNodeIfExists(this.compilerNode.default);
};
/**
* Removes this type parameter.
*/
TypeParameterDeclaration.prototype.remove = function () {
var parentSyntaxList = this.getParentSyntaxListOrThrow();
var typeParameters = parentSyntaxList.getChildrenOfKind(typescript_1.SyntaxKind.TypeParameter);
if (typeParameters.length === 1)
removeAllTypeParameters();
else
manipulation_1.removeCommaSeparatedChild(this);
function removeAllTypeParameters() {
var children = [
parentSyntaxList.getPreviousSiblingIfKindOrThrow(typescript_1.SyntaxKind.FirstBinaryOperator),
parentSyntaxList,
parentSyntaxList.getNextSiblingIfKindOrThrow(typescript_1.SyntaxKind.GreaterThanToken)
];
manipulation_1.removeChildren({ children: children });
}
};
return TypeParameterDeclaration;
}(exports.TypeParameterDeclarationBase));
exports.TypeParameterDeclaration = TypeParameterDeclaration;