mirror of
https://github.com/documentationjs/documentation.git
synced 2025-12-08 18:23:43 +00:00
34 lines
826 B
JavaScript
34 lines
826 B
JavaScript
'use strict';
|
|
|
|
var types = require('ast-types'),
|
|
shouldSkipInference = require('./should_skip_inference'),
|
|
flowDoctrine = require('../flow_doctrine');
|
|
|
|
/**
|
|
* Infers returns tags by using Flow return type annotations
|
|
*
|
|
* @name inferReturn
|
|
* @param {Object} comment parsed comment
|
|
* @returns {Object} comment with return tag inferred
|
|
*/
|
|
module.exports = function () {
|
|
return shouldSkipInference(function inferReturn(comment) {
|
|
types.visit(comment.context.ast, {
|
|
visitFunction: function (path) {
|
|
|
|
if (!comment.returns &&
|
|
path.value.returnType &&
|
|
path.value.returnType.typeAnnotation) {
|
|
comment.returns = [{
|
|
type: flowDoctrine(path.value.returnType.typeAnnotation)
|
|
}];
|
|
}
|
|
|
|
this.abort();
|
|
}
|
|
});
|
|
|
|
return comment;
|
|
});
|
|
};
|