Skip to content

Commit

Permalink
fix crash when assigning a class expression to an object property (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Apr 22, 2015
1 parent b6e5051 commit cfb04e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/jsdoc/src/astnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/classtag2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
7 changes: 7 additions & 0 deletions test/specs/tags/classtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});
});
}
});

0 comments on commit cfb04e3

Please sign in to comment.