Tom MacWright 49347c82e7 Arv document exported (#502)
* Add a flag to document all exported bindings

This adds a boolean flag called `document-exported` (defaults to false)
that effectively adds an empty comment to all exported bindings that do
not already have a JSDoc comment. It also does the same for the
members of exported classes and objects.

```js
export class C {
  method() {}
}
```

Both `C` and `C#method` are now part of the generated documentation.

Related to #424

* Fix lint error

* Rebase and use options pragma in test file

* Create extractor type as a generalized comment/export getter

* Document exported extractor
2016-08-24 10:58:15 -04:00

48 lines
1.5 KiB
JavaScript

var traverse = require('babel-traverse').default,
isJSDocComment = require('../../lib/is_jsdoc_comment');
/**
* Iterate through the abstract syntax tree, finding a different kind of comment
* each time, and optionally including context. This is how we find
* JSDoc annotations that will become part of documentation
* @param {string} type comment type to find
* @param {boolean} includeContext to include context in the nodes
* @param {Object} ast the babel-parsed syntax tree
* @param {Function} addComment a method that creates a new comment if necessary
* @returns {Array<Object>} comments
* @private
*/
function walkComments(type, includeContext, ast, addComment) {
var newResults = [];
traverse(ast, {
/**
* Process a parse in an abstract syntax tree
* @param {Object} path ast path
* @returns {undefined} causes side effects
* @private
*/
enter: function (path) {
/**
* Parse a comment with doctrine and decorate the result with file position and code context.
*
* @param {Object} comment the current state of the parsed JSDoc comment
* @return {undefined} this emits data
*/
function parseComment(comment) {
newResults.push(addComment(comment.value, comment.loc, path, path.node.loc, includeContext));
}
(path.node[type] || [])
.filter(isJSDocComment)
.forEach(parseComment);
}
});
traverse.clearCache();
return newResults;
}
module.exports = walkComments;