don't overwrite the classdesc tag's value when the class and constructor tags are also present (#806)

This commit is contained in:
Jeff Williams 2014-11-27 11:48:11 -08:00
parent 0daeb2e947
commit f135456396
3 changed files with 34 additions and 18 deletions

View File

@ -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']
},

View File

@ -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
*/

View File

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