UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

42 lines (40 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const errors = require("./../../../errors"); function DeclarationNamedNode(Base) { return class extends Base { getNameIdentifierOrThrow() { const nameNode = this.getNameIdentifier(); if (nameNode == null) throw new errors.InvalidOperationError("Expected a name node."); return nameNode; } getNameIdentifier() { const compilerNameNode = this.compilerNode.name; if (compilerNameNode == null) return undefined; switch (compilerNameNode.kind) { case ts.SyntaxKind.Identifier: return this.global.compilerFactory.getNodeFromCompilerNode(compilerNameNode, this.sourceFile); /* istanbul ignore next */ default: throw errors.getNotImplementedForSyntaxKindError(compilerNameNode.kind); } } getName() { const nameNode = this.getNameIdentifier(); return nameNode == null ? undefined : nameNode.getText(); } rename(text) { errors.throwIfNotStringOrWhitespace(text, "text"); const nameNode = this.getNameIdentifier(); if (nameNode == null) throw errors.getNotImplementedForSyntaxKindError(this.getKind()); nameNode.rename(text); return this; } }; } exports.DeclarationNamedNode = DeclarationNamedNode; //# sourceMappingURL=DeclarationNamedNode.js.map