blob: 401a3c5ea14841f3b3c942beb4712ebd483df0a0 [file] [log] [blame]
var annotate = function() {
var args = Array.prototype.slice.call(arguments);
var fn = args.pop();
fn.$inject = args;
return fn;
};
// Current limitations:
// - can't put into "function arg" comments
// function /* (no parenthesis like this) */ (){}
// function abc( /* xx (no parenthesis like this) */ a, b) {}
//
// Just put the comment before function or inside:
// /* (((this is fine))) */ function(a, b) {}
// function abc(a) { /* (((this is fine))) */}
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG = /\/\*([^\*]*)\*\//m;
var parse = function(fn) {
if (typeof fn !== 'function') {
throw new Error('Can not annotate "' + fn + '". Expected a function!');
}
var match = fn.toString().match(FN_ARGS);
return match[1] && match[1].split(',').map(function(arg) {
match = arg.match(FN_ARG);
return match ? match[1].trim() : arg.trim();
}) || [];
};
exports.annotate = annotate;
exports.parse = parse;