mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix crash when assigning a class expression to an object property (#988)
This commit is contained in:
parent
b6e5051d2f
commit
cfb04e390d
@ -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);
|
||||
|
||||
19
test/fixtures/classtag2.js
vendored
19
test/fixtures/classtag2.js
vendored
@ -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) {}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user