Skip to content

Commit a2c2c3e

Browse files
authored
Merge pull request #4 from fredj/extends_generic_type
Remove the generic type from the extends tag
2 parents 216e5da + f75ebca commit a2c2c3e

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
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+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsdoc-plugin-typescript",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Plugin to make TypeScript's JSDoc type annotations work with JSDoc",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)