mirror of
https://github.com/documentationjs/documentation.git
synced 2025-12-08 18:23:43 +00:00
Given the `type` tag introduced with Flow, this can infer a typedef statement, as well as infer its potentially nested properties and their types. This also includes * Refactor of Markdown AST generation that fixes #228 * Refactor of nest.js to handle multi-level nesting
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
function nestTag(comment, tagName, target) {
|
|
if (!comment[target]) {
|
|
return comment;
|
|
}
|
|
|
|
var result = [],
|
|
index = {};
|
|
|
|
comment[target].forEach(function (tag) {
|
|
index[tag.name] = tag;
|
|
var parts = tag.name.split(/(\[\])?\./)
|
|
.filter(function (part) {
|
|
return part && part !== '[]';
|
|
});
|
|
if (parts.length > 1) {
|
|
var parent = index[parts.slice(0, -1).join('.')];
|
|
if (parent === undefined) {
|
|
comment.errors.push({
|
|
message: '@' + tagName + ' ' + tag.name + '\'s parent ' + parts[0] + ' not found',
|
|
commentLineNumber: tag.lineNumber
|
|
});
|
|
result.push(tag);
|
|
return;
|
|
}
|
|
parent.properties = parent.properties || [];
|
|
parent.properties.push(tag);
|
|
} else {
|
|
result.push(tag);
|
|
}
|
|
});
|
|
|
|
comment[target] = result;
|
|
|
|
return comment;
|
|
}
|
|
|
|
/**
|
|
* Nests
|
|
* [parameters with properties](http://usejsdoc.org/tags-param.html#parameters-with-properties).
|
|
*
|
|
* A parameter `employee.name` will be attached to the parent parameter `employee` in
|
|
* a `properties` array.
|
|
*
|
|
* This assumes that incoming comments have been flattened.
|
|
*
|
|
* @param {Object} comment input comment
|
|
* @return {Object} nested comment
|
|
*/
|
|
function nest(comment) {
|
|
return nestTag(nestTag(comment, 'param', 'params'),
|
|
'property', 'properties');
|
|
}
|
|
|
|
module.exports = nest;
|