fix crash when assigning a class expression to an object property (#988)

This commit is contained in:
Jeff Williams 2015-04-21 17:34:03 -07:00
parent b6e5051d2f
commit cfb04e390d
3 changed files with 31 additions and 2 deletions

View File

@ -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);

View File

@ -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) {}
}

View File

@ -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');
});
});
}
});