documentation/lib/infer/return.js
2015-11-28 11:50:29 -05:00

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;
});
};