NET-Web-API-w-Angular/my-app/node_modules/di/lib/annotation.js

38 lines
955 B
JavaScript
Raw Normal View History

2024-02-09 00:38:41 +00:00
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;