Default exported classes have same prettyname as modules
This commit is contained in:
@@ -106,6 +106,20 @@ function includeTypes(doclet) {
|
||||
}
|
||||
}
|
||||
|
||||
const defaultExports = {};
|
||||
const path = require('path');
|
||||
const moduleRoot = path.join(process.cwd(), 'src');
|
||||
|
||||
// Tag default exported Identifiers because their name should be the same as the module name.
|
||||
exports.astNodeVisitor = {
|
||||
visitNode: function(node, e, parser, currentSourceName) {
|
||||
if (node.type === 'Identifier' && node.parent.type === 'ExportDefaultDeclaration') {
|
||||
const modulePath = path.relative(moduleRoot, currentSourceName).replace(/\.js$/, '');
|
||||
defaultExports['module:' + modulePath + '~' + node.name] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.handlers = {
|
||||
|
||||
newDoclet: function(e) {
|
||||
@@ -169,6 +183,15 @@ exports.handlers = {
|
||||
delete doclet.undocumented;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
processingComplete(e) {
|
||||
const byLongname = e.doclets.index.longname;
|
||||
for (const name in defaultExports) {
|
||||
byLongname[name].forEach(function(doclet) {
|
||||
doclet.isDefaultExport = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -188,14 +188,10 @@ function attachModuleSymbols(doclets, modules) {
|
||||
});
|
||||
}
|
||||
|
||||
function getPrettyName(longname) {
|
||||
const fullname = longname.replace('module:', '');
|
||||
const parts = fullname.split(/[~\.]/);
|
||||
if (parts.length > 1) {
|
||||
const pathParts = parts[0].split('/');
|
||||
if (parts[parts.length - 1] === pathParts[pathParts.length - 1]) {
|
||||
return parts[0];
|
||||
}
|
||||
function getPrettyName(doclet) {
|
||||
const fullname = doclet.longname.replace('module:', '');
|
||||
if (doclet.isDefaultExport) {
|
||||
return fullname.split('~')[0];
|
||||
}
|
||||
return fullname;
|
||||
}
|
||||
@@ -218,8 +214,8 @@ function buildNav(members) {
|
||||
// merge namespaces and classes, then sort
|
||||
const merged = members.modules.concat(members.classes);
|
||||
merged.sort(function(a, b) {
|
||||
const prettyNameA = getPrettyName(a.longname).toLowerCase();
|
||||
const prettyNameB = getPrettyName(b.longname).toLowerCase();
|
||||
const prettyNameA = getPrettyName(a).toLowerCase();
|
||||
const prettyNameB = getPrettyName(b).toLowerCase();
|
||||
if (prettyNameA > prettyNameB) {
|
||||
return 1;
|
||||
}
|
||||
@@ -235,7 +231,7 @@ function buildNav(members) {
|
||||
nav.push({
|
||||
type: 'class',
|
||||
longname: v.longname,
|
||||
prettyname: getPrettyName(v.longname),
|
||||
prettyname: getPrettyName(v),
|
||||
name: v.name,
|
||||
module: find({
|
||||
kind: 'module',
|
||||
@@ -286,7 +282,7 @@ function buildNav(members) {
|
||||
nav.push({
|
||||
type: 'module',
|
||||
longname: v.longname,
|
||||
prettyname: getPrettyName(v.longname),
|
||||
prettyname: getPrettyName(v),
|
||||
name: v.name,
|
||||
members: members,
|
||||
methods: methods,
|
||||
|
||||
Reference in New Issue
Block a user