Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($injector): don't parse fns with no args
Browse files Browse the repository at this point in the history
When annotating a fn, it is wasteful to try to parse a fn that has no arguments
as such fn has no injectable dependencies
  • Loading branch information
IgorMinar committed Aug 16, 2013
1 parent 35d4993 commit 44b6b72
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ function annotate(fn) {
if (typeof fn == 'function') {
if (!($inject = fn.$inject)) {
$inject = [];
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){
arg.replace(FN_ARG, function(all, underscore, name){
$inject.push(name);
if (fn.length) {
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){
arg.replace(FN_ARG, function(all, underscore, name){
$inject.push(name);
});
});
});
}
fn.$inject = $inject;
}
} else if (isArray(fn)) {
Expand Down

0 comments on commit 44b6b72

Please sign in to comment.