diff --git a/lib/jsdoc/src/astnode.js b/lib/jsdoc/src/astnode.js index ab7b70fe..0e5eda71 100644 --- a/lib/jsdoc/src/astnode.js +++ b/lib/jsdoc/src/astnode.js @@ -189,10 +189,13 @@ var nodeToValue = exports.nodeToValue = function(node) { parent = node.parent.parent; // for class expressions, we want the name of the variable the class is assigned to if (parent.type === Syntax.ClassExpression) { - parent = parent.parent; + str = nodeToValue(parent.parent); + } + // otherwise, use the class's name + else { + str = nodeToValue(parent.id); } - str = nodeToValue(parent.id); if (node.kind !== 'constructor') { str += node.static ? name.SCOPE.PUNC.STATIC : name.SCOPE.PUNC.INSTANCE; str += nodeToValue(node.key); diff --git a/test/fixtures/classtag2.js b/test/fixtures/classtag2.js index 2f6be0cf..333b70b3 100644 --- a/test/fixtures/classtag2.js +++ b/test/fixtures/classtag2.js @@ -27,3 +27,22 @@ const Subscriber = class Foo { /** Check whether the subscriber has a callback. */ hasCallback() {} } + +/** + * Subclass namespace. + * @namespace + */ +let subclasses = {}; + +/** + * Expiring subscription subclass. + * @class + */ +subclasses.ExpiringSubscription = class ExpiringSubscription { + /** + * Describe the constructor here. + * + * @param {string} name - The name of the subscription. + */ + constructor(name) {} +} diff --git a/test/specs/tags/classtag.js b/test/specs/tags/classtag.js index b5c90b17..b5aa1e05 100644 --- a/test/specs/tags/classtag.js +++ b/test/specs/tags/classtag.js @@ -21,6 +21,7 @@ describe('@class tag', function() { var expire = docSet2.getByLongname('Subscription#expire')[0]; var subscriber = docSet2.getByLongname('Subscriber')[0]; var hasCallback = docSet2.getByLongname('Subscriber#hasCallback')[0]; + var expiringSubscription = docSet2.getByLongname('subclasses.ExpiringSubscription')[0]; it('When a symbol is a class declaration, the doclet does not require the @class tag', function() { expect(subscription.kind).toBe('class'); @@ -57,6 +58,12 @@ describe('@class tag', function() { expect(hasCallback.name).toBe('hasCallback'); expect(hasCallback.memberof).toBe('Subscriber'); }); + + it('When a class expression is assigned to an object property, it is parsed correctly', function() { + expect(expiringSubscription.kind).toBe('class'); + expect(expiringSubscription.name).toBe('ExpiringSubscription'); + expect(expiringSubscription.params[0].name).toBe('name'); + }); }); } });