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

Commit 427db62

Browse files
author
Shahar Talmi
committed
refactor(injector): extract common code to function
1 parent 0c626bc commit 427db62

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/auto/injector.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
6868
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
6969
var $injectorMinErr = minErr('$injector');
7070

71+
function extractArgs(fn) {
72+
var fnText = fn.toString().replace(STRIP_COMMENTS, ''),
73+
args = fnText.match(FN_ARGS);
74+
return args;
75+
}
76+
7177
function anonFn(fn) {
7278
// For anonymous functions, showing at the very least the function signature can help in
7379
// debugging.
74-
var fnText = fn.toString().replace(STRIP_COMMENTS, ''),
75-
args = fnText.match(FN_ARGS);
80+
var args = extractArgs(fn);
7681
if (args) {
7782
return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')';
7883
}
@@ -81,7 +86,6 @@ function anonFn(fn) {
8186

8287
function annotate(fn, strictDi, name) {
8388
var $inject,
84-
fnText,
8589
argDecl,
8690
last;
8791

@@ -96,8 +100,7 @@ function annotate(fn, strictDi, name) {
96100
throw $injectorMinErr('strictdi',
97101
'{0} is not using explicit annotation and cannot be invoked in strict mode', name);
98102
}
99-
fnText = fn.toString().replace(STRIP_COMMENTS, '');
100-
argDecl = fnText.match(FN_ARGS);
103+
argDecl = extractArgs(fn);
101104
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
102105
arg.replace(FN_ARG, function(all, underscore, name) {
103106
$inject.push(name);

0 commit comments

Comments
 (0)