Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions lib/hierarchy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var _ = require('lodash');
var hasOwnProperty = Object.prototype.hasOwnProperty;

/**
Expand Down Expand Up @@ -119,16 +120,24 @@ module.exports = function (comments) {
comment.members[scope] = node.members[scope];
}

var events = comment.members.events || [];
var groups = [];

if (comment.members.instance.length) {
comment.members.events = comment.members.instance.filter(function (member) {
return member.kind === 'event';
});
groups = _.groupBy(comment.members.instance, isEvent);

comment.members.instance = comment.members.instance.filter(function (member) {
return member.kind !== 'event';
});
events = events.concat(groups[true] || []);
comment.members.instance = groups[false] || [];
}

if (comment.members.static.length) {
groups = _.groupBy(comment.members.static, isEvent);

events = events.concat(groups[true] || []);
comment.members.static = groups[false] || [];
}

comment.members.events = events;

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

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

return toComments(root.members.static);
};

/**
* Check if a given member object is of kind `event`.
* @param {Object} member - The member to check.
* @returns {boolean} `true` if it is of kind `event`, otherwise false.
*/
function isEvent(member) {
return member.kind === 'event';
}
9 changes: 6 additions & 3 deletions test/fixture/_external-deps-included.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -275,7 +276,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -436,7 +438,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/_multi-file-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -393,7 +394,8 @@
"kind": "function",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/boolean-literal-type.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
],
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/class.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@
"scope": "instance",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -551,7 +552,8 @@
"scope": "instance",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"name": "document-exported-export-default-object.input",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down Expand Up @@ -66,7 +67,8 @@
"name": "x",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"name": "document-exported-export-default-value.input",
"members": {
"instance": [],
"static": []
"static": [],
"events": []
},
"path": [
{
Expand Down
Loading