From c6c539b25de0d93c33aa8016e8976c971e8f66a9 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Thu, 9 Dec 2021 14:57:31 -0800 Subject: [PATCH] Restore class names of default-exported modules If we're parsing the following file: ``` /** module ExampleClass */ export default class ExampleClass { constructor() {} } ``` Then we'll currently generate entries for the class and the constructor under `module.exports` because of how ES6 rewrites things internally. This uses the module name for the exported class and constructor instead, which is friendlier behavior. --- lib/transform.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/transform.js b/lib/transform.js index fbf73b2..39bc2a0 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -38,6 +38,7 @@ function transform (data) { doclet = renameThisProperty(doclet) doclet = removeMemberofFromModule(doclet) doclet = convertIsEnumFlagToKind(doclet) + doclet = renameModuleExports(doclet) return doclet }) @@ -401,3 +402,15 @@ function removeEnumChildren (json) { } }) } + +/** + * Default exports lose their module name, showing up as module.exports, which + * is not very friendly. This restores the module name if we have it. + */ +function renameModuleExports(doclet) { + if (doclet.name === 'module.exports' && doclet.longname.startsWith('module:')) { + doclet.name = doclet.longname.replace('module:','') + console.log(doclet) + } + return doclet +}