Skip to content

Commit 2074b57

Browse files
committed
Always add the @extends derived from the class's extends keyword
1 parent 216e5da commit 2074b57

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,25 @@ exports.astNodeVisitor = {
136136
lines[0] += ' @classdesc';
137137
}
138138
if (node.superClass) {
139+
// Remove the `@extends` tag because JSDoc does not does not handle generic type. (`@extends {Base<Type>}`)
140+
const extendsIndex = lines.findIndex(line => line.includes('@extends'));
141+
if (extendsIndex !== -1) {
142+
lines.splice(extendsIndex, 1);
143+
}
139144
// Add class inheritance information because JSDoc does not honor
140145
// the ES6 class's `extends` keyword
141-
if (leadingComment.value.indexOf('@extends') === -1) {
142-
lines.push(lines[lines.length - 1]);
143-
const identifier = identifiers[node.superClass.name];
144-
if (identifier) {
145-
const absolutePath = path.resolve(path.dirname(currentSourceName), identifier.value);
146-
const moduleId = path.relative(path.join(process.cwd(), moduleRoot), absolutePath).replace(/\.js$/, '');
147-
if (getModuleInfo(moduleId, parser)) {
148-
const exportName = identifier.defaultImport ? getDefaultExportName(moduleId, parser) : node.superClass.name;
149-
const delimiter = identifier.defaultImport ? '~' : getDelimiter(moduleId, exportName, parser);
150-
lines[lines.length - 2] = ' * @extends ' + `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
151-
}
152-
} else {
153-
lines[lines.length - 2] = ' * @extends ' + node.superClass.name;
146+
lines.push(lines[lines.length - 1]);
147+
const identifier = identifiers[node.superClass.name];
148+
if (identifier) {
149+
const absolutePath = path.resolve(path.dirname(currentSourceName), identifier.value);
150+
const moduleId = path.relative(path.join(process.cwd(), moduleRoot), absolutePath).replace(/\.js$/, '');
151+
if (getModuleInfo(moduleId, parser)) {
152+
const exportName = identifier.defaultImport ? getDefaultExportName(moduleId, parser) : node.superClass.name;
153+
const delimiter = identifier.defaultImport ? '~' : getDelimiter(moduleId, exportName, parser);
154+
lines[lines.length - 2] = ' * @extends ' + `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
154155
}
156+
} else {
157+
lines[lines.length - 2] = ' * @extends ' + node.superClass.name;
155158
}
156159
leadingComment.value = lines.join('\n');
157160
}
@@ -222,4 +225,4 @@ exports.handlers = {
222225
// Build inheritance chain after adding @extends annotations
223226
addInherited(e.doclets, indexAll(e.doclets));
224227
}
225-
}
228+
}

0 commit comments

Comments
 (0)