mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
* feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 Big changes: * Uses template strings where appropriate * Config and argument parsing is unified and there is no such thing as formatterOptions anymore. All user-passed options go through mergeConfig. * The node API surface changed (again): `buildSync` is removed, building operations return Promises. * Now using Flow for internal type annotations. More changes: * Remove buildSync command * feat(inference): Partially implement object shorthand support * Refs #649 * Use Flow annotations to enforce types * Keep flow but switch to comment syntax * Clarify types * More flow improvements * Turn server into class * LinkerStack becomes class too * Fix comment description type * Run flow on lint * Many more flow fixes * More intense flow refactoring * Simplify inference steps * Update inference tests, flow errors down to 1 * Continue refining types * Fix more flow issues * Use 'use strict' everywhere * Make 'ast' property configurable * Fix many tests * Fix more tests * Fix more tests * Fix augments * Test Markdown meta support * Improve test coverage * Switch back from for of to for for speed
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
/* @flow */
|
|
'use strict';
|
|
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 type comment type to find
|
|
* @param includeContext to include context in the nodes
|
|
* @param ast the babel-parsed syntax tree
|
|
* @param data the filename and the source of the file the comment is in
|
|
* @param addComment a method that creates a new comment if necessary
|
|
* @returns comments
|
|
* @private
|
|
*/
|
|
function walkComments(type/*: string*/,
|
|
includeContext/*: boolean*/,
|
|
ast/*: Object*/,
|
|
data/*: Object*/,
|
|
addComment/*: Function*/)/*: Array<Comment>*/ {
|
|
var newResults = [];
|
|
|
|
traverse(ast, {
|
|
/**
|
|
* Process a parse in an abstract syntax tree
|
|
* @param {Object} path ast path
|
|
* @returns {undefined} causes side effects
|
|
* @private
|
|
*/
|
|
enter(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(data, comment.value, comment.loc, path, path.node.loc, includeContext));
|
|
}
|
|
|
|
(path.node[type] || [])
|
|
.filter(isJSDocComment)
|
|
.forEach(parseComment);
|
|
}
|
|
});
|
|
|
|
traverse.clearCache();
|
|
|
|
return newResults;
|
|
}
|
|
|
|
module.exports = walkComments;
|