Skip to content

Commit

Permalink
refactor(nest): Better nesting implementation
Browse files Browse the repository at this point in the history
This nesting implementation uses a proper recursive tree algorithm

Fixes #554
  • Loading branch information
tmcw committed Apr 15, 2017
1 parent d8ec5da commit 44371d3
Show file tree
Hide file tree
Showing 29 changed files with 1,256 additions and 1,129 deletions.
43 changes: 29 additions & 14 deletions declarations/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,21 @@ declare type CommentContextGitHub = {
url: string
};

declare type CommentTag = {
declare type CommentTagBase = {
title: string
};

declare type CommentTag = CommentTagBase & {
name?: string,
title: string,
description?: Object,
default?: any,
lineNumber?: number,
type?: DoctrineType,
properties?: Array<CommentTag>
};

declare type CommentTagNamed = CommentTag & {
name?: string,
title: string,
description?: Object,
Expand Down Expand Up @@ -88,18 +102,19 @@ declare type Remark = {

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' |
'interface';
declare type Kind =
| 'class'
| 'constant'
| 'event'
| 'external'
| 'file'
| 'function'
| 'member'
| 'mixin'
| 'module'
| 'namespace'
| 'typedef'
| 'interface';

declare type Comment = {
errors: Array<CommentError>,
Expand Down Expand Up @@ -152,4 +167,4 @@ declare type ReducedComment = {
name: string,
kind: ?Kind,
scope?: ?Scope
}
};
43 changes: 21 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ function pipeline() {
};
}



function configure(indexes, args)/*: Promise<InputsConfig> */ {
function configure(indexes, args) /*: Promise<InputsConfig> */ {
let mergedConfig = mergeConfig(args);

return mergedConfig.then(config => {

let expandedInputs = expandInputs(indexes, config);

return expandedInputs.then(inputs => {
Expand All @@ -71,8 +68,10 @@ function configure(indexes, args)/*: Promise<InputsConfig> */ {
* @param {Object} config options
* @returns {Promise<Array<string>>} promise with results
*/
function expandInputs(indexes/*: string|Array<string> */,
config /*: DocumentationConfig */) {
function expandInputs(
indexes /*: string|Array<string> */,
config /*: DocumentationConfig */
) {
// Ensure that indexes is an array of strings
indexes = [].concat(indexes);

Expand All @@ -91,40 +90,42 @@ function buildInternal(inputsAndConfig) {
config.access = ['public', 'undefined', 'protected'];
}

var parseFn = (config.polyglot) ? polyglot : parseJavaScript;
var parseFn = config.polyglot ? polyglot : parseJavaScript;

var buildPipeline = pipeline(
inferName,
inferAccess(config.inferPrivate),
inferAugments,
inferKind,
nest,
inferParams,
inferProperties,
inferReturn,
inferMembership(),
inferType,
nest,
config.github && github,
garbageCollect);
garbageCollect
);

let extractedComments = _.flatMap(inputs, function (sourceFile) {
let extractedComments = _.flatMap(inputs, function(sourceFile) {
if (!sourceFile.source) {
sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8');
}

return parseFn(sourceFile, config).map(buildPipeline);
}).filter(Boolean);

return filterAccess(config.access,
hierarchy(
sort(extractedComments, config)));
return filterAccess(
config.access,
hierarchy(sort(extractedComments, config))
);
}

function lintInternal(inputsAndConfig) {
let inputs = inputsAndConfig.inputs;
let config = inputsAndConfig.config;

let parseFn = (config.polyglot) ? polyglot : parseJavaScript;
let parseFn = config.polyglot ? polyglot : parseJavaScript;

let lintPipeline = pipeline(
lintComments,
Expand All @@ -137,7 +138,8 @@ function lintInternal(inputsAndConfig) {
inferReturn,
inferMembership(),
inferType,
nest);
nest
);

let extractedComments = _.flatMap(inputs, sourceFile => {
if (!sourceFile.source) {
Expand Down Expand Up @@ -183,8 +185,7 @@ function lintInternal(inputsAndConfig) {
* }
* });
*/
let lint = (indexes, args) => configure(indexes, args)
.then(lintInternal);
let lint = (indexes, args) => configure(indexes, args).then(lintInternal);

/**
* Generate JavaScript documentation as a list of parsed JSDoc
Expand Down Expand Up @@ -227,8 +228,7 @@ let lint = (indexes, args) => configure(indexes, args)
* // any other kind of code data.
* });
*/
let build = (indexes, args) => configure(indexes, args)
.then(buildInternal);
let build = (indexes, args) => configure(indexes, args).then(buildInternal);

/**
* Documentation's formats are modular methods that take comments
Expand All @@ -240,9 +240,8 @@ let build = (indexes, args) => configure(indexes, args)
var formats = {
html: require('./lib/output/html'),
md: require('./lib/output/markdown'),
remark: (comments/*: Array<Comment> */, config/*: DocumentationConfig */) =>
markdownAST(comments, config)
.then(res => JSON.stringify(res, null, 2)),
remark: (comments /*: Array<Comment> */, config /*: DocumentationConfig */) =>
markdownAST(comments, config).then(res => JSON.stringify(res, null, 2)),
json: require('./lib/output/json')
};

Expand Down
Loading

0 comments on commit 44371d3

Please sign in to comment.