diff --git a/streams/infer_name.js b/streams/infer_name.js index 324a0d2..01e1dcd 100644 --- a/streams/infer_name.js +++ b/streams/infer_name.js @@ -21,20 +21,21 @@ module.exports = function () { return; } - // If this comment has a @class tag with a name, use it - // as a title - if (comment.tags[i].title === 'class' && comment.tags[i].name) { - comment.tags.push({ title: 'name', name: comment.tags[i].name }); - this.push(comment); - return; - } + // If this comment has a @class, @event, or @typedef tag with a name, + // use it. + var explicitNameTags = { + 'class': 'name', + 'event': 'description', + 'typedef': 'description' + }; - // If this comment has an @event tag with a name, use it - // as a title - if (comment.tags[i].title === 'event' && comment.tags[i].description) { - comment.tags.push({ title: 'name', name: comment.tags[i].description }); - this.push(comment); - return; + for (var title in explicitNameTags) { + var value = explicitNameTags[title]; + if (comment.tags[i].title === title && comment.tags[i][value]) { + comment.tags.push({ title: 'name', name: comment.tags[i][value] }); + this.push(comment); + return; + } } } diff --git a/test/streams/infer_name.js b/test/streams/infer_name.js index a472a75..d37a724 100644 --- a/test/streams/infer_name.js +++ b/test/streams/infer_name.js @@ -121,3 +121,36 @@ test('inferName - explicit name', function (t) { t.end(); }); }); + +test('inferName - class', function (t) { + evaluate(function () { + /** @class ExplicitClass */ + function ImplicitClass() {} + return ImplicitClass; + }, function (result) { + t.equal(result[ 0 ].name, 'ExplicitClass'); + t.end(); + }); +}); + +test('inferName - event', function (t) { + evaluate(function () { + /** @event explicitEvent */ + function implicitName() {} + return implicitName; + }, function (result) { + t.equal(result[ 0 ].name, 'explicitEvent'); + t.end(); + }); +}); + +test('inferName - typedef', function (t) { + evaluate(function () { + /** @typedef {Object} ExplicitTypedef */ + function implicitName() {} + return implicitName; + }, function (result) { + t.equal(result[ 0 ].name, 'ExplicitTypedef'); + t.end(); + }); +});