Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scopes): Support inner scope #665

Merged
merged 2 commits into from
Jan 29, 2017
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
33 changes: 28 additions & 5 deletions declarations/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ declare type CommentTag = {
declare type CommentMembers = {
static: Array<Comment>,
instance: Array<Comment>,
events: Array<Comment>
events: Array<Comment>,
global: Array<Comment>,
inner: Array<Comment>
};

declare type CommentExample = {
Expand All @@ -84,6 +86,20 @@ declare type Remark = {
children: Array<Object>
};

declare type Access = 'private' | 'public' | 'protected';
declare type Scope = 'instance' | 'static' | 'inner' | 'global';
declare type Kind = 'class' |
'constant' |
'event' |
'external' |
'file' |
'function' |
'member' |
'mixin' |
'module' |
'namespace' |
'typedef';

declare type Comment = {
errors: Array<CommentError>,
tags: Array<CommentTag>,
Expand All @@ -106,10 +122,11 @@ declare type Comment = {
members: CommentMembers,

name?: string,
kind?: string,
kind?: Kind,

memberof?: string,
scope?: string,
access?: string,
scope?: Scope,
access?: Access,
alias?: string,

copyright?: string,
Expand All @@ -126,6 +143,12 @@ declare type Comment = {

path?: Array<{
name: string,
scope: string
scope: Scope
}>
};

declare type ReducedComment = {
name: string,
kind: ?Kind,
scope?: ?Scope
}
12 changes: 12 additions & 0 deletions default_theme/index._
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
<% }) %>
</ul>
<% } %>
<% if (doc.members.inner && doc.members.inner.length) { %>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Inner members</span></li>
<% doc.members.inner.forEach(function(member) { %>
<li><a
href='#<%=member.namespace%>'
class='regular pre-open'>
#<%- member.name %>
</a></li>
<% }) %>
</ul>
<% } %>
<% if (doc.members.events && doc.members.events.length) { %>
<ul class='list-reset py1-ul pl1'>
<li class='h5'>Events</li>
Expand Down
49 changes: 33 additions & 16 deletions lib/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;
*/
let isEvent = member => member.kind === 'event';

/*::
declare type ReducedComment = {
name: string,
kind: ?string,
scope?: ?string
} */
/**
* We need to have members of all valid JSDoc scopes.
* @private
*/
let getMembers = () => ({
global: Object.create(null),
inner: Object.create(null),
instance: Object.create(null),
events: Object.create(null),
static: Object.create(null)
});


/**
* Pick only relevant properties from a comment to store them in
Expand Down Expand Up @@ -49,12 +55,10 @@ function pick(comment/*: Comment */)/*: ?ReducedComment */ {
module.exports = function (comments/*: Array<Comment>*/) {
var id = 0,
root = {
members: {
instance: Object.create(null),
static: Object.create(null)
}
members: getMembers()
};


comments.forEach(comment => {
var path = [];

Expand Down Expand Up @@ -86,10 +90,7 @@ module.exports = function (comments/*: Array<Comment>*/) {
if (!hasOwnProperty.call(node.members[scope], name)) {
node.members[scope][name] = {
comments: [],
members: {
instance: Object.create(null),
static: Object.create(null)
}
members: getMembers()
};
}

Expand Down Expand Up @@ -138,7 +139,7 @@ module.exports = function (comments/*: Array<Comment>*/) {
comment.members[scope] = node.members[scope];
}

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

if (comment.members.instance.length) {
Expand All @@ -155,6 +156,20 @@ module.exports = function (comments/*: Array<Comment>*/) {
comment.members.static = groups[false] || [];
}

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

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

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

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

comment.members.events = events;

comment.path = path.map(pick)
Expand All @@ -163,7 +178,9 @@ module.exports = function (comments/*: Array<Comment>*/) {

var scopeChars = {
instance: '#',
static: '.'
static: '.',
inner: '~',
global: ''
};

comment.namespace = comment.path.reduce((memo, part) => {
Expand Down
6 changes: 6 additions & 0 deletions lib/output/markdown_ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,18 @@ function buildMarkdownAST(comments/*: Array<Comment> */, config/*: Documentation
.concat(throwsSection(comment))
.concat(returnsSection(comment))
.concat(metaSection(comment))
.concat(!!comment.members.global.length &&
comment.members.global.reduce((memo, child) =>
memo.concat(generate(depth + 1, child)), []))
.concat(!!comment.members.instance.length &&
comment.members.instance.reduce((memo, child) =>
memo.concat(generate(depth + 1, child)), []))
.concat(!!comment.members.static.length &&
comment.members.static.reduce((memo, child) =>
memo.concat(generate(depth + 1, child)), []))
.concat(!!comment.members.inner.length &&
comment.members.inner.reduce((memo, child) =>
memo.concat(generate(depth + 1, child)), []))
.filter(Boolean);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var flatteners = {
* @returns {undefined} has side-effects
*/
'access': function (result, tag) {
// doctrine ensures that tag.access is valid
result.access = tag.access;
},
'alias': flattenName,
Expand Down Expand Up @@ -208,6 +209,7 @@ var flatteners = {
* @returns {undefined} has side-effects
*/
'kind': function (result, tag) {
// doctrine ensures that tag.kind is valid
result.kind = tag.kind;
},
'lends': flattenDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/serve/error_page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* @flow */
/* eslint no-console: 0 */
'use strict';
var File = require('vinyl');
var ansiHTML = require('ansi-html');
Expand Down
18 changes: 12 additions & 6 deletions test/fixture/_external-deps-included.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@
"name": "foo",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down Expand Up @@ -291,9 +293,11 @@
"name": "main",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down Expand Up @@ -461,9 +465,11 @@
"name": "index",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
12 changes: 8 additions & 4 deletions test/fixture/_multi-file-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@
"name": "returnTwo",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down Expand Up @@ -408,9 +410,11 @@
"name": "simple.input",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/fixture/boolean-literal-type.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@
"name": "f",
"kind": "function",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
18 changes: 12 additions & 6 deletions test/fixture/class.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
"kind": "class",
"name": "MyClass",
"members": {
"global": [],
"inner": [],
"instance": [
{
"description": {
Expand Down Expand Up @@ -400,9 +402,11 @@
"memberof": "MyClass",
"scope": "instance",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down Expand Up @@ -575,9 +579,11 @@
"memberof": "MyClass",
"scope": "instance",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand All @@ -593,8 +599,8 @@
"namespace": "MyClass#getUndefined"
}
],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
12 changes: 8 additions & 4 deletions test/fixture/document-exported-export-default-object.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"todos": [],
"name": "document-exported-export-default-object.input",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down Expand Up @@ -82,9 +84,11 @@
"todos": [],
"name": "x",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"todos": [],
"name": "document-exported-export-default-value.input",
"members": {
"global": [],
"inner": [],
"instance": [],
"static": [],
"events": []
"events": [],
"static": []
},
"path": [
{
Expand Down
Loading