Skip to content

Commit ebce170

Browse files
committed
Nesting ⇢ guard clauses
1 parent b6dc9f6 commit ebce170

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

streams/hierarchy.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,31 @@ function inferHierarchy(comments) {
4747
nameIndex[comments[i].name] = comments[i];
4848
comments[i].members = { instance: [], static: [] };
4949
}
50+
5051
for (i = comments.length - 1; i >= 0; i--) {
51-
if (comments[i].memberof) {
52-
if (nameIndex[comments[i].memberof]) {
53-
if (comments[i].scope) {
54-
nameIndex[comments[i].memberof].members[comments[i].scope].push(comments[i]);
55-
// remove non-root nodes from the lowest level: these are reachable
56-
// as members of other docs.
57-
comments.splice(i, 1);
58-
} else {
59-
console.error(error(comments[i], 'found memberof but no @scope, @static, or @instance tag'));
60-
}
61-
} else {
62-
console.error(error(comments[i], 'memberof reference to %s not found', comments[i].memberof));
63-
}
52+
var comment = comments[i];
53+
54+
if (!comment.memberof) {
55+
continue;
56+
}
57+
58+
var parent = nameIndex[comment.memberof];
59+
60+
if (!parent) {
61+
console.error(error(comment, 'memberof reference to %s not found', comment.memberof));
62+
continue;
6463
}
64+
65+
if (!comment.scope) {
66+
console.error(error(comment, 'found memberof but no @scope, @static, or @instance tag'));
67+
continue;
68+
}
69+
70+
parent.members[comment.scope].push(comment);
71+
72+
// remove non-root nodes from the lowest level: these are reachable
73+
// as members of other docs.
74+
comments.splice(i, 1);
6575
}
6676

6777
// Now the members are in the right order but the root comments are reversed

0 commit comments

Comments
 (0)