mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
correctly handle classes that are the default export (#1113)
This commit is contained in:
parent
224e796428
commit
1bdcc52156
@ -330,7 +330,13 @@ var getInfo = exports.getInfo = function(node) {
|
||||
// or "class" in: "export default class {}"
|
||||
case Syntax.ClassDeclaration:
|
||||
info.node = node;
|
||||
info.name = node.id ? nodeToValue(node.id) : '';
|
||||
// if this class is the default export, we need to use a special name
|
||||
if (node.parent && node.parent.type === Syntax.ExportDefaultDeclaration) {
|
||||
info.name = 'module.exports';
|
||||
}
|
||||
else {
|
||||
info.name = node.id ? nodeToValue(node.id) : '';
|
||||
}
|
||||
info.type = info.node.type;
|
||||
info.paramnames = [];
|
||||
|
||||
|
||||
@ -176,6 +176,11 @@ walkers[Syntax.ExportAllDeclaration] = function(node, parent, state, cb) {
|
||||
};
|
||||
|
||||
walkers[Syntax.ExportDefaultDeclaration] = function(node, parent, state, cb) {
|
||||
// if the declaration target is a class, move leading comments to the declaration target
|
||||
if (node.declaration && node.declaration.type === Syntax.ClassDeclaration) {
|
||||
moveComments(node, node.declaration);
|
||||
}
|
||||
|
||||
if (node.declaration) {
|
||||
cb(node.declaration, node, state);
|
||||
}
|
||||
|
||||
4
test/fixtures/exportdefault.js
vendored
Normal file
4
test/fixtures/exportdefault.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/** @module test */
|
||||
|
||||
/** Test value */
|
||||
export default 'foo';
|
||||
7
test/fixtures/exportdefaultclass.js
vendored
Normal file
7
test/fixtures/exportdefaultclass.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/** @module test */
|
||||
|
||||
/** Test class */
|
||||
export default class Foo {
|
||||
/** Test constructor */
|
||||
constructor() {}
|
||||
}
|
||||
11
test/specs/documentation/exportdefault.js
Normal file
11
test/specs/documentation/exportdefault.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
describe('export default', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/exportdefault.js');
|
||||
var member = docSet.getByLongname('module:test')[1];
|
||||
|
||||
it('should use the correct kind and description for the default export', function() {
|
||||
expect(member.kind).toBe('member');
|
||||
expect(member.description).toBe('Test value');
|
||||
});
|
||||
});
|
||||
11
test/specs/documentation/exportdefaultclass.js
Normal file
11
test/specs/documentation/exportdefaultclass.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
describe('export default class', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/exportdefaultclass.js');
|
||||
var klass = docSet.getByLongname('module:test')[2];
|
||||
|
||||
it('should combine the classdesc and constructor description into a single doclet', function() {
|
||||
expect(klass.classdesc).toBe('Test class');
|
||||
expect(klass.description).toBe('Test constructor');
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user