Skip to content

Commit f1e0267

Browse files
dignifiedquiretmcw
authored andcommitted
fix(hierarchy): collect events from static and instance members (#628)
Fixes #486
1 parent 73ba79b commit f1e0267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+447
-257
lines changed

lib/hierarchy.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var _ = require('lodash');
34
var hasOwnProperty = Object.prototype.hasOwnProperty;
45

56
/**
@@ -119,16 +120,24 @@ module.exports = function (comments) {
119120
comment.members[scope] = node.members[scope];
120121
}
121122

123+
var events = comment.members.events || [];
124+
var groups = [];
125+
122126
if (comment.members.instance.length) {
123-
comment.members.events = comment.members.instance.filter(function (member) {
124-
return member.kind === 'event';
125-
});
127+
groups = _.groupBy(comment.members.instance, isEvent);
126128

127-
comment.members.instance = comment.members.instance.filter(function (member) {
128-
return member.kind !== 'event';
129-
});
129+
events = events.concat(groups[true] || []);
130+
comment.members.instance = groups[false] || [];
131+
}
132+
133+
if (comment.members.static.length) {
134+
groups = _.groupBy(comment.members.static, isEvent);
135+
136+
events = events.concat(groups[true] || []);
137+
comment.members.static = groups[false] || [];
130138
}
131139

140+
comment.members.events = events;
132141

133142
comment.path = path.map(pick).concat(pick(comment));
134143

@@ -168,3 +177,12 @@ module.exports = function (comments) {
168177

169178
return toComments(root.members.static);
170179
};
180+
181+
/**
182+
* Check if a given member object is of kind `event`.
183+
* @param {Object} member - The member to check.
184+
* @returns {boolean} `true` if it is of kind `event`, otherwise false.
185+
*/
186+
function isEvent(member) {
187+
return member.kind === 'event';
188+
}

test/fixture/_external-deps-included.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
"kind": "function",
115115
"members": {
116116
"instance": [],
117-
"static": []
117+
"static": [],
118+
"events": []
118119
},
119120
"path": [
120121
{
@@ -275,7 +276,8 @@
275276
"kind": "function",
276277
"members": {
277278
"instance": [],
278-
"static": []
279+
"static": [],
280+
"events": []
279281
},
280282
"path": [
281283
{
@@ -436,7 +438,8 @@
436438
"kind": "function",
437439
"members": {
438440
"instance": [],
439-
"static": []
441+
"static": [],
442+
"events": []
440443
},
441444
"path": [
442445
{

test/fixture/_multi-file-input.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@
232232
"kind": "function",
233233
"members": {
234234
"instance": [],
235-
"static": []
235+
"static": [],
236+
"events": []
236237
},
237238
"path": [
238239
{
@@ -393,7 +394,8 @@
393394
"kind": "function",
394395
"members": {
395396
"instance": [],
396-
"static": []
397+
"static": [],
398+
"events": []
397399
},
398400
"path": [
399401
{

test/fixture/boolean-literal-type.output.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
],
6767
"members": {
6868
"instance": [],
69-
"static": []
69+
"static": [],
70+
"events": []
7071
},
7172
"path": [
7273
{

test/fixture/class.output.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@
385385
"scope": "instance",
386386
"members": {
387387
"instance": [],
388-
"static": []
388+
"static": [],
389+
"events": []
389390
},
390391
"path": [
391392
{
@@ -551,7 +552,8 @@
551552
"scope": "instance",
552553
"members": {
553554
"instance": [],
554-
"static": []
555+
"static": [],
556+
"events": []
555557
},
556558
"path": [
557559
{

test/fixture/document-exported-export-default-object.output.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"name": "document-exported-export-default-object.input",
2929
"members": {
3030
"instance": [],
31-
"static": []
31+
"static": [],
32+
"events": []
3233
},
3334
"path": [
3435
{
@@ -66,7 +67,8 @@
6667
"name": "x",
6768
"members": {
6869
"instance": [],
69-
"static": []
70+
"static": [],
71+
"events": []
7072
},
7173
"path": [
7274
{

test/fixture/document-exported-export-default-value.output.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"name": "document-exported-export-default-value.input",
2929
"members": {
3030
"instance": [],
31-
"static": []
31+
"static": [],
32+
"events": []
3233
},
3334
"path": [
3435
{

0 commit comments

Comments
 (0)