dgeni-packages
Version:
A collection of dgeni packages for generating documentation from source code
47 lines • 2.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MethodMemberDoc = void 0;
const getTypeParametersText_1 = require("../services/TsParser/getTypeParametersText");
const MemberDoc_1 = require("./MemberDoc");
const ParameterContainer_1 = require("./ParameterContainer");
class MethodMemberDoc extends MemberDoc_1.MemberDoc {
constructor(host, containerDoc, symbol, declaration, overloads = []) {
super(host, containerDoc, symbol, declaration);
this.overloads = overloads;
this.name = this.computeName();
this.parameterDocs = (0, ParameterContainer_1.getParameters)(this);
this.parameters = this.parameterDocs.map(p => p.paramText);
this.anchor = this.computeAnchor();
this.id = `${this.containerDoc.id}.${this.anchor}`;
this.aliases = this.computeAliases();
this.typeParameters = (0, getTypeParametersText_1.getTypeParametersText)(this.declaration);
// fix up parameter ids and aliases, now that we have computed the id for this doc
this.parameterDocs.forEach(param => {
param.id = `${this.id}~${param.name}`;
param.aliases = this.aliases.map(alias => `${alias}~${param.name}`);
});
}
computeName() {
return this.symbol.name === '__new' ? 'new ' :
this.symbol.name === '__constructor' ? 'constructor' :
this.symbol.name === '__call' ? '' :
this.symbol.name;
}
computeAnchor() {
// if the member is a "call" type then it has no name
const anchorName = this.name.trim() || 'call';
const isOverload = !this.declaration.body;
const overloadIndex = isOverload ? this.symbol.getDeclarations().indexOf(this.declaration) : -1;
// if there is more than one declaration then we need to distinguish them
return `${anchorName}${overloadIndex >= 0 ? `_${overloadIndex}` : ''}()`;
}
computeAliases() {
const aliases = [this.anchor];
this.containerDoc.aliases.forEach(alias => {
aliases.push(`${alias}.${this.anchor}`);
});
return aliases;
}
}
exports.MethodMemberDoc = MethodMemberDoc;
//# sourceMappingURL=MethodMemberDoc.js.map