mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
don't overwrite the classdesc tag's value when the class and constructor tags are also present (#806)
This commit is contained in:
parent
0daeb2e947
commit
f135456396
@ -259,18 +259,20 @@ var baseTags = exports.baseTags = {
|
||||
onTagged: function(doclet, tag) {
|
||||
doclet.addTag('kind', 'class');
|
||||
|
||||
// handle special case where both @class and @constructor tags exist in same doclet
|
||||
if (tag.originalTitle === 'class') {
|
||||
// multiple words after @class?
|
||||
var looksLikeDesc = (tag.value || '').match(/\S+\s+\S+/);
|
||||
if ( looksLikeDesc || /@construct(s|or)\b/i.test(doclet.comment) ) {
|
||||
// treat the @class tag as a @classdesc tag instead
|
||||
doclet.classdesc = tag.value;
|
||||
return;
|
||||
}
|
||||
// We treat the @class tag as a @classdesc tag if all of the following are true:
|
||||
// - Both @class and @constructor tags are present
|
||||
// - There's no @classdesc tag
|
||||
// - There are multiple words after @class
|
||||
if (tag.value &&
|
||||
tag.originalTitle === 'class' &&
|
||||
/@construct(?:s|or)\b/i.test(doclet.comment) &&
|
||||
!/@classdesc\b/i.test(doclet.comment) &&
|
||||
tag.value.match(/\S+\s+\S+/)) {
|
||||
doclet.addTag('classdesc', tag.value);
|
||||
}
|
||||
else {
|
||||
setDocletNameToValue(doclet, tag);
|
||||
}
|
||||
|
||||
setDocletNameToValue(doclet, tag);
|
||||
},
|
||||
synonyms: ['constructor']
|
||||
},
|
||||
|
||||
11
test/fixtures/classdesctag.js
vendored
11
test/fixtures/classdesctag.js
vendored
@ -1,7 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Asdf.
|
||||
* @class
|
||||
* @classdesc A description of the class.
|
||||
*/
|
||||
function Foo () {
|
||||
}
|
||||
function Foo() {}
|
||||
|
||||
/**
|
||||
* @classdesc A description of the class.
|
||||
* @class Bar
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
describe("@classdesc tag", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/classdesctag.js'),
|
||||
doc = docSet.getByLongname('Foo')[0];
|
||||
'use strict';
|
||||
|
||||
it('adds a classdesc property to the doclet with the description', function() {
|
||||
expect(doc.classdesc).toBe('A description of the class.');
|
||||
describe('@classdesc tag', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/classdesctag.js');
|
||||
var foo = docSet.getByLongname('Foo')[0];
|
||||
var bar = docSet.getByLongname('Bar')[0];
|
||||
|
||||
it('should add a classdesc property to the doclet with the description', function() {
|
||||
expect(foo.classdesc).toBe('A description of the class.');
|
||||
});
|
||||
|
||||
it('should work when the @class and @constructor tags are also present, and @class has a value', function() {
|
||||
expect(bar.classdesc).toBe('A description of the class.');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user