ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
38 lines (36 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const manipulation_1 = require("./../../manipulation");
const base_1 = require("./../base");
const common_1 = require("./../common");
exports.TypeParameterDeclarationBase = base_1.NamedNode(common_1.Node);
class TypeParameterDeclaration extends exports.TypeParameterDeclarationBase {
/**
* Gets the constraint node.
*/
getConstraintNode() {
return this.compilerNode.constraint == null ? undefined : this.global.compilerFactory.getNodeFromCompilerNode(this.compilerNode.constraint, this.sourceFile);
}
/**
* Removes this type parameter.
*/
remove() {
const parentSyntaxList = this.getParentSyntaxListOrThrow();
const typeParameters = parentSyntaxList.getChildrenOfKind(ts.SyntaxKind.TypeParameter);
if (typeParameters.length === 1)
removeAllTypeParameters();
else
manipulation_1.removeCommaSeparatedChild(this);
function removeAllTypeParameters() {
const children = [
parentSyntaxList.getPreviousSiblingIfKindOrThrow(ts.SyntaxKind.FirstBinaryOperator),
parentSyntaxList,
parentSyntaxList.getNextSiblingIfKindOrThrow(ts.SyntaxKind.GreaterThanToken)
];
manipulation_1.removeChildren({ children });
}
}
}
exports.TypeParameterDeclaration = TypeParameterDeclaration;
//# sourceMappingURL=TypeParameterDeclaration.js.map