UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

55 lines (54 loc) 2.56 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 manipulation_1 = require("./../../manipulation"); var common_1 = require("./../common"); var HeritageClause = /** @class */ (function (_super) { __extends(HeritageClause, _super); function HeritageClause() { return _super !== null && _super.apply(this, arguments) || this; } /** * Gets all the types for the heritage clause. */ HeritageClause.prototype.getTypes = function () { var _this = this; if (this.compilerNode.types == null) return []; return this.compilerNode.types.map(function (t) { return _this.global.compilerFactory.getNodeFromCompilerNode(t, _this.sourceFile); }); }; /** * Gets the heritage clause token. */ HeritageClause.prototype.getToken = function () { return this.compilerNode.token; }; HeritageClause.prototype.removeExpression = function (expressionNodeOrIndex) { var expressions = this.getTypes(); var expressionNodeToRemove = typeof expressionNodeOrIndex === "number" ? getExpressionFromIndex(expressionNodeOrIndex) : expressionNodeOrIndex; if (expressions.length === 1) { var heritageClauses = this.getParentSyntaxListOrThrow().getChildren(); if (heritageClauses.length === 1) manipulation_1.removeChildren({ children: [heritageClauses[0].getParentSyntaxListOrThrow()], removePrecedingSpaces: true }); else manipulation_1.removeChildren({ children: [this], removePrecedingSpaces: true }); } else manipulation_1.removeCommaSeparatedChild(expressionNodeToRemove, { removePrecedingSpaces: expressionNodeToRemove !== expressions[0] }); return this; function getExpressionFromIndex(index) { return expressions[manipulation_1.verifyAndGetIndex(index, expressions.length - 1)]; } }; return HeritageClause; }(common_1.Node)); exports.HeritageClause = HeritageClause;