diff --git a/lib/hierarchy.js b/lib/hierarchy.js index 702e5b5bb..a597fc770 100644 --- a/lib/hierarchy.js +++ b/lib/hierarchy.js @@ -1,5 +1,6 @@ 'use strict'; +var _ = require('lodash'); var hasOwnProperty = Object.prototype.hasOwnProperty; /** @@ -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)); @@ -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'; +} diff --git a/test/fixture/_external-deps-included.json b/test/fixture/_external-deps-included.json index 779e67335..15b2c155d 100644 --- a/test/fixture/_external-deps-included.json +++ b/test/fixture/_external-deps-included.json @@ -114,7 +114,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -275,7 +276,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -436,7 +438,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/_multi-file-input.json b/test/fixture/_multi-file-input.json index 854a11638..dd227b807 100644 --- a/test/fixture/_multi-file-input.json +++ b/test/fixture/_multi-file-input.json @@ -232,7 +232,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -393,7 +394,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/boolean-literal-type.output.json b/test/fixture/boolean-literal-type.output.json index 2ea4eb916..51d31929a 100644 --- a/test/fixture/boolean-literal-type.output.json +++ b/test/fixture/boolean-literal-type.output.json @@ -66,7 +66,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/class.output.json b/test/fixture/class.output.json index c539e4535..49b3b81e0 100644 --- a/test/fixture/class.output.json +++ b/test/fixture/class.output.json @@ -385,7 +385,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -551,7 +552,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/document-exported-export-default-object.output.json b/test/fixture/document-exported-export-default-object.output.json index c85665602..03b839755 100644 --- a/test/fixture/document-exported-export-default-object.output.json +++ b/test/fixture/document-exported-export-default-object.output.json @@ -28,7 +28,8 @@ "name": "document-exported-export-default-object.input", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -66,7 +67,8 @@ "name": "x", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/document-exported-export-default-value.output.json b/test/fixture/document-exported-export-default-value.output.json index e15877f5d..baa003f74 100644 --- a/test/fixture/document-exported-export-default-value.output.json +++ b/test/fixture/document-exported-export-default-value.output.json @@ -28,7 +28,8 @@ "name": "document-exported-export-default-value.input", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/document-exported.output.json b/test/fixture/document-exported.output.json index b886f3cbc..29d6660e1 100644 --- a/test/fixture/document-exported.output.json +++ b/test/fixture/document-exported.output.json @@ -61,7 +61,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -125,7 +126,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -197,7 +199,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -244,7 +247,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -298,7 +302,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -347,7 +352,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -394,7 +400,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -448,7 +455,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -508,7 +516,8 @@ }, "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -547,7 +556,8 @@ "name": "y2Default", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -655,7 +665,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -726,7 +737,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -771,7 +783,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -785,7 +798,8 @@ ], "namespace": "object.func" } - ] + ], + "events": [] }, "path": [ { @@ -824,7 +838,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -864,7 +879,8 @@ "kind": "member", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -911,7 +927,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -951,7 +968,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -991,7 +1009,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1035,7 +1054,8 @@ }, "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1079,7 +1099,8 @@ }, "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1123,7 +1144,8 @@ }, "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1174,7 +1196,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1213,7 +1236,8 @@ "name": "o1", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1252,7 +1276,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1354,7 +1379,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1393,7 +1419,8 @@ "name": "o2", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1432,7 +1459,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/es6-class.output.json b/test/fixture/es6-class.output.json index acdacf6b3..20a562615 100644 --- a/test/fixture/es6-class.output.json +++ b/test/fixture/es6-class.output.json @@ -86,7 +86,8 @@ "kind": "class", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -281,7 +282,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -388,7 +390,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/es6-default2.output.json b/test/fixture/es6-default2.output.json index 17bb6cac3..43a0cc58f 100644 --- a/test/fixture/es6-default2.output.json +++ b/test/fixture/es6-default2.output.json @@ -43,7 +43,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/es6-import.output.json b/test/fixture/es6-import.output.json index 8388f25d0..4c3b25624 100644 --- a/test/fixture/es6-import.output.json +++ b/test/fixture/es6-import.output.json @@ -157,7 +157,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -247,7 +248,8 @@ "name": "es6-ext", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -407,7 +409,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/es6.output.json b/test/fixture/es6.output.json index 4e899117d..62862566d 100644 --- a/test/fixture/es6.output.json +++ b/test/fixture/es6.output.json @@ -115,7 +115,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -244,7 +245,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -500,7 +502,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -674,7 +677,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -772,7 +776,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -874,7 +879,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1064,7 +1070,8 @@ "scope": "instance", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1164,7 +1171,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1341,7 +1349,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1590,7 +1599,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1691,7 +1701,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1796,7 +1807,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -1887,7 +1899,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2048,7 +2061,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2146,7 +2160,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2244,7 +2259,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2342,7 +2358,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2432,7 +2449,8 @@ "name": "execute", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -2601,7 +2619,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/event.output.json b/test/fixture/event.output.json index 934cbf267..ae349584c 100644 --- a/test/fixture/event.output.json +++ b/test/fixture/event.output.json @@ -237,7 +237,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/example-caption.output.json b/test/fixture/example-caption.output.json index 1a9091b06..7fb36daf6 100644 --- a/test/fixture/example-caption.output.json +++ b/test/fixture/example-caption.output.json @@ -213,7 +213,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/external.output.json b/test/fixture/external.output.json index 929a6a4c4..c8e02a0b7 100644 --- a/test/fixture/external.output.json +++ b/test/fixture/external.output.json @@ -114,7 +114,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/factory.output.json b/test/fixture/factory.output.json index 4b9d07561..7e7078904 100644 --- a/test/fixture/factory.output.json +++ b/test/fixture/factory.output.json @@ -150,7 +150,8 @@ "kind": "function", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -205,7 +206,8 @@ ], "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { @@ -317,7 +319,8 @@ "scope": "static", "members": { "instance": [], - "static": [] + "static": [], + "events": [] }, "path": [ { diff --git a/test/fixture/html/nested.config-output.html b/test/fixture/html/nested.config-output.html index 4250860a2..626338271 100644 --- a/test/fixture/html/nested.config-output.html +++ b/test/fixture/html/nested.config-output.html @@ -76,12 +76,6 @@
.MAGIC_NUMBER -Klass event
- - -Klass event
+ + +Klass event
- - -Klass event
+ + +