Basic event hierarchization

This commit is contained in:
John Firebaugh 2015-06-10 12:20:54 -04:00
parent ebce170380
commit 6d29b8f8ee
2 changed files with 32 additions and 5 deletions

View File

@ -46,6 +46,7 @@ function inferHierarchy(comments) {
for (i = 0; i < comments.length; i++) {
nameIndex[comments[i].name] = comments[i];
comments[i].members = { instance: [], static: [] };
comments[i].events = [];
}
for (i = comments.length - 1; i >= 0; i--) {
@ -62,12 +63,19 @@ function inferHierarchy(comments) {
continue;
}
if (!comment.scope) {
console.error(error(comment, 'found memberof but no @scope, @static, or @instance tag'));
continue;
}
switch (comment.kind) {
case 'event':
parent.events.push(comment);
break;
parent.members[comment.scope].push(comment);
default:
if (!comment.scope) {
console.error(error(comment, 'found memberof but no @scope, @static, or @instance tag'));
continue;
}
parent.members[comment.scope].push(comment);
break;
}
// remove non-root nodes from the lowest level: these are reachable
// as members of other docs.
@ -95,6 +103,9 @@ function inferHierarchy(comments) {
comment.members.static.forEach(function (member) {
addPath(member, comment.path);
});
comment.events.forEach(function (member) {
addPath(member, comment.path);
});
}
for (i = 0; i < comments.length; i++) addPath(comments[i], []);

View File

@ -58,10 +58,26 @@ test('hierarchy', function (t) {
* A magic number that identifies this Klass.
*/
Klass.MAGIC_NUMBER = 42;
/**
* Klass event
* @event event
* @memberof Klass
*/
return Klass;
}, function (result) {
t.equal(result.length, 1);
t.equal(result[0].members.static.length, 2);
t.deepEqual(result[0].members.static[0].path, ['Klass', 'isClass']);
t.equal(result[0].members.instance.length, 1);
t.deepEqual(result[0].members.instance[0].path, ['Klass', 'getFoo']);
t.equal(result[0].events.length, 1);
t.deepEqual(result[0].events[0].path, ['Klass', 'event']);
t.end();
});
});