Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
955 bytes
|
Line | |
---|
1 | var annotate = function() {
|
---|
2 | var args = Array.prototype.slice.call(arguments);
|
---|
3 | var fn = args.pop();
|
---|
4 |
|
---|
5 | fn.$inject = args;
|
---|
6 |
|
---|
7 | return fn;
|
---|
8 | };
|
---|
9 |
|
---|
10 |
|
---|
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) {}
|
---|
15 | //
|
---|
16 | // Just put the comment before function or inside:
|
---|
17 | // /* (((this is fine))) */ function(a, b) {}
|
---|
18 | // function abc(a) { /* (((this is fine))) */}
|
---|
19 |
|
---|
20 | var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
|
---|
21 | var FN_ARG = /\/\*([^\*]*)\*\//m;
|
---|
22 |
|
---|
23 | var parse = function(fn) {
|
---|
24 | if (typeof fn !== 'function') {
|
---|
25 | throw new Error('Can not annotate "' + fn + '". Expected a function!');
|
---|
26 | }
|
---|
27 |
|
---|
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();
|
---|
32 | }) || [];
|
---|
33 | };
|
---|
34 |
|
---|
35 |
|
---|
36 | exports.annotate = annotate;
|
---|
37 | exports.parse = parse;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.