1 var annotate = function() {
2 var args = Array.prototype.slice.call(arguments);
11 // Current limitations:
12 // - can't put into "function arg" comments
13 // function /* (no parenthesis like this) */ (){}
14 // function abc( /* xx (no parenthesis like this) */ a, b) {}
16 // Just put the comment before function or inside:
17 // /* (((this is fine))) */ function(a, b) {}
18 // function abc(a) { /* (((this is fine))) */}
20 var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
21 var FN_ARG = /\/\*([^\*]*)\*\//m;
23 var parse = function(fn) {
24 if (typeof fn !== 'function') {
25 throw new Error('Can not annotate "' + fn + '". Expected a function!');
28 var match = fn.toString().match(FN_ARGS);
29 return match[1] && match[1].split(',').map(function(arg) {
30 match = arg.match(FN_ARG);
31 return match ? match[1].trim() : arg.trim();
36 exports.annotate = annotate;
37 exports.parse = parse;