aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2012-03-28 17:20:12 -0700
committerIgor Minar2012-03-29 11:21:04 -0700
commit2cb907a8366e3273890f5ef6174b2e3970cd1720 (patch)
tree3ddb2b21cdec49752e3157ec9e60e1323f07a250
parent2f2fd465a40f675c969effd2324611533929fb73 (diff)
downloadangular.js-2cb907a8366e3273890f5ef6174b2e3970cd1720.tar.bz2
fix($injector): properly infer dependencies from fn with no args
Previously if there was a white-space in fn: fn( ) {} we failed to infer no args. This was originally reported by recht, but I decided to use a different fix. Closes #829
-rw-r--r--src/auto/injector.js2
-rw-r--r--test/auto/injectorSpec.js7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/auto/injector.js b/src/auto/injector.js
index 1844db2a..1a1fcc27 100644
--- a/src/auto/injector.js
+++ b/src/auto/injector.js
@@ -38,7 +38,7 @@
* Implicit module which gets automatically added to each {@link angular.module.AUTO.$injector $injector}.
*/
-var FN_ARGS = /^function\s*[^\(]*\(([^\)]*)\)/m;
+var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(.+?)\1\s*$/;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js
index 16cf1524..83bd3d1f 100644
--- a/test/auto/injectorSpec.js
+++ b/test/auto/injectorSpec.js
@@ -160,6 +160,13 @@ describe('injector', function() {
});
+ it('should handle no arg functions with spaces in the arguments list', function() {
+ function fn( ) {}
+ expect(inferInjectionArgs(fn)).toEqual([]);
+ expect(fn.$inject).toEqual([]);
+ });
+
+
it('should handle args with both $ and _', function() {
function $f_n0($a_) {}
expect(inferInjectionArgs($f_n0)).toEqual(['$a_']);