Correctly infer @typedef name (fixes #90)

This commit is contained in:
John Firebaugh 2015-06-10 09:51:24 -04:00
parent 3ab94ab425
commit 42e8aee478
2 changed files with 47 additions and 13 deletions

View File

@ -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;
}
}
}

View File

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