mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
use the correct longname for constructors of ES2015 classes with @alias tags (#1395)
This commit is contained in:
parent
9c97ba7495
commit
d7c7fea358
@ -90,14 +90,32 @@ function setCurrentModule(doclet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setModuleScopeMemberOf(doclet) {
|
function setModuleScopeMemberOf(parser, doclet) {
|
||||||
|
var parentDoclet;
|
||||||
|
var skipMemberof;
|
||||||
|
|
||||||
// handle module symbols that are _not_ assigned to module.exports
|
// handle module symbols that are _not_ assigned to module.exports
|
||||||
if (currentModule && currentModule.longname !== doclet.name) {
|
if (currentModule && currentModule.longname !== doclet.name) {
|
||||||
if (!doclet.scope) {
|
if (!doclet.scope) {
|
||||||
// is this a method definition? if so, get the scope from the node directly
|
// is this a method definition? if so, we usually get the scope from the node directly
|
||||||
if (doclet.meta && doclet.meta.code && doclet.meta.code.node &&
|
if (doclet.meta && doclet.meta.code && doclet.meta.code.node &&
|
||||||
doclet.meta.code.node.type === Syntax.MethodDefinition) {
|
doclet.meta.code.node.type === Syntax.MethodDefinition) {
|
||||||
if (doclet.meta.code.node.static) {
|
// special case for constructors of classes that have @alias tags
|
||||||
|
if (doclet.meta.code.node.kind === 'constructor') {
|
||||||
|
parentDoclet = parser._getDocletById(
|
||||||
|
doclet.meta.code.node.parent.parent.nodeId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (parentDoclet && parentDoclet.alias) {
|
||||||
|
// the constructor should use the same name as the class
|
||||||
|
doclet.addTag('alias', parentDoclet.alias);
|
||||||
|
doclet.addTag('name', parentDoclet.alias);
|
||||||
|
|
||||||
|
// and we shouldn't try to set a memberof value
|
||||||
|
skipMemberof = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (doclet.meta.code.node.static) {
|
||||||
doclet.addTag('static');
|
doclet.addTag('static');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -117,8 +135,8 @@ function setModuleScopeMemberOf(doclet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the doclet isn't a memberof anything yet, and it's not a global, it must be a memberof
|
// if the doclet isn't a memberof anything yet, and it's not a global, it must be a memberof
|
||||||
// the current module
|
// the current module (unless we were told to skip adding memberof)
|
||||||
if (!doclet.memberof && doclet.scope !== SCOPE_NAMES.GLOBAL) {
|
if (!doclet.memberof && doclet.scope !== SCOPE_NAMES.GLOBAL && !skipMemberof) {
|
||||||
doclet.addTag('memberof', currentModule.longname);
|
doclet.addTag('memberof', currentModule.longname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,7 +282,7 @@ function addSymbolMemberof(parser, doclet, astNode) {
|
|||||||
}
|
}
|
||||||
// otherwise, add the defaults for a module (if we're currently in a module)
|
// otherwise, add the defaults for a module (if we're currently in a module)
|
||||||
else {
|
else {
|
||||||
setModuleScopeMemberOf(doclet);
|
setModuleScopeMemberOf(parser, doclet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +347,7 @@ exports.attachTo = function(parser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add the default scope/memberof for a module (if we're in a module)
|
// add the default scope/memberof for a module (if we're in a module)
|
||||||
setModuleScopeMemberOf(newDoclet);
|
setModuleScopeMemberOf(parser, newDoclet);
|
||||||
newDoclet.postProcess();
|
newDoclet.postProcess();
|
||||||
|
|
||||||
// if we _still_ don't have a scope, use the default
|
// if we _still_ don't have a scope, use the default
|
||||||
|
|||||||
8
test/fixtures/alias6.js
vendored
Normal file
8
test/fixtures/alias6.js
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @module example */
|
||||||
|
|
||||||
|
/** @alias module:example */
|
||||||
|
class Foo {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
@ -73,6 +73,15 @@ describe('aliases', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('When a symbol is a constructor of a class with an alias, the constructor should get the correct longname', function() {
|
||||||
|
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias6.js');
|
||||||
|
var constructor = docSet.getByLongname('module:example')[2];
|
||||||
|
|
||||||
|
expect(constructor.undocumented).toBe(true);
|
||||||
|
expect(constructor.name).toBe('module:example');
|
||||||
|
expect(constructor.alias).toBe('module:example');
|
||||||
|
});
|
||||||
|
|
||||||
it('When a symbol is documented as a static member of <global>, its scope is "global" and not "static".', function() {
|
it('When a symbol is documented as a static member of <global>, its scope is "global" and not "static".', function() {
|
||||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js');
|
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js');
|
||||||
var log = docSet.getByLongname('log')[0];
|
var log = docSet.getByLongname('log')[0];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user