dgeni-packages
Version:
A collection of dgeni packages for generating documentation from source code
42 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeclarationTypeText = void 0;
const ts = require("typescript");
const getTypeText_1 = require("./getTypeText");
const nodeToString_1 = require("./nodeToString");
function getDeclarationTypeText(declaration) {
// if the declaration has an explicit type then use that
const type = getType(declaration);
if (type)
return (0, getTypeText_1.getTypeText)(type);
// if the declaration is a type parameter then just use its textual value
if (ts.isTypeParameterDeclaration(declaration)) {
return (0, nodeToString_1.nodeToString)(declaration);
}
// if the declaration is being initialized then use the initialization type
const initializer = getInitializer(declaration);
if (initializer) {
if (ts.isNewExpression(initializer)) {
return (0, nodeToString_1.nodeToString)(initializer.expression) + getTypeArgumentText(initializer);
}
else {
return (0, nodeToString_1.nodeToString)(initializer);
}
}
return '';
}
exports.getDeclarationTypeText = getDeclarationTypeText;
function getType(declaration) {
return declaration.type;
}
function getInitializer(declaration) {
return declaration.initializer;
}
function getTypeArgumentText(initializer) {
if (!initializer.typeArguments) {
return '';
}
const typeTexts = initializer.typeArguments.map(t => (0, nodeToString_1.nodeToString)(t));
return `<${typeTexts.join(', ')}>`;
}
//# sourceMappingURL=getDeclarationTypeText.js.map