Skip to content

Commit 42e8aee

Browse files
committed
Correctly infer @typedef name (fixes #90)
1 parent 3ab94ab commit 42e8aee

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

streams/infer_name.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ module.exports = function () {
2121
return;
2222
}
2323

24-
// If this comment has a @class tag with a name, use it
25-
// as a title
26-
if (comment.tags[i].title === 'class' && comment.tags[i].name) {
27-
comment.tags.push({ title: 'name', name: comment.tags[i].name });
28-
this.push(comment);
29-
return;
30-
}
24+
// If this comment has a @class, @event, or @typedef tag with a name,
25+
// use it.
26+
var explicitNameTags = {
27+
'class': 'name',
28+
'event': 'description',
29+
'typedef': 'description'
30+
};
3131

32-
// If this comment has an @event tag with a name, use it
33-
// as a title
34-
if (comment.tags[i].title === 'event' && comment.tags[i].description) {
35-
comment.tags.push({ title: 'name', name: comment.tags[i].description });
36-
this.push(comment);
37-
return;
32+
for (var title in explicitNameTags) {
33+
var value = explicitNameTags[title];
34+
if (comment.tags[i].title === title && comment.tags[i][value]) {
35+
comment.tags.push({ title: 'name', name: comment.tags[i][value] });
36+
this.push(comment);
37+
return;
38+
}
3839
}
3940
}
4041

test/streams/infer_name.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,36 @@ test('inferName - explicit name', function (t) {
121121
t.end();
122122
});
123123
});
124+
125+
test('inferName - class', function (t) {
126+
evaluate(function () {
127+
/** @class ExplicitClass */
128+
function ImplicitClass() {}
129+
return ImplicitClass;
130+
}, function (result) {
131+
t.equal(result[ 0 ].name, 'ExplicitClass');
132+
t.end();
133+
});
134+
});
135+
136+
test('inferName - event', function (t) {
137+
evaluate(function () {
138+
/** @event explicitEvent */
139+
function implicitName() {}
140+
return implicitName;
141+
}, function (result) {
142+
t.equal(result[ 0 ].name, 'explicitEvent');
143+
t.end();
144+
});
145+
});
146+
147+
test('inferName - typedef', function (t) {
148+
evaluate(function () {
149+
/** @typedef {Object} ExplicitTypedef */
150+
function implicitName() {}
151+
return implicitName;
152+
}, function (result) {
153+
t.equal(result[ 0 ].name, 'ExplicitTypedef');
154+
t.end();
155+
});
156+
});

0 commit comments

Comments
 (0)