Default exported classes have same prettyname as modules

This commit is contained in:
Maximilian Krög
2020-02-27 22:50:03 +01:00
parent c2505f938e
commit 47ed2963c4
2 changed files with 31 additions and 12 deletions

View File

@@ -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;
});
}
}
};