From f1354563965792b8dd183f5a5331f8fcc67ea319 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 27 Nov 2014 11:48:11 -0800 Subject: [PATCH] don't overwrite the `classdesc` tag's value when the `class` and `constructor` tags are also present (#806) --- lib/jsdoc/tag/dictionary/definitions.js | 24 +++++++++++++----------- test/fixtures/classdesctag.js | 11 +++++++++-- test/specs/tags/classdesctag.js | 17 ++++++++++++----- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index 7911c239..57d8ba00 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -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'] }, diff --git a/test/fixtures/classdesctag.js b/test/fixtures/classdesctag.js index 707a79e6..ae537780 100644 --- a/test/fixtures/classdesctag.js +++ b/test/fixtures/classdesctag.js @@ -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 + */ diff --git a/test/specs/tags/classdesctag.js b/test/specs/tags/classdesctag.js index 2a369cf1..4bf64ce7 100644 --- a/test/specs/tags/classdesctag.js +++ b/test/specs/tags/classdesctag.js @@ -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.'); }); });