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
This commit is contained in:
Igor Minar
2012-03-28 17:20:12 -07:00
parent 2f2fd465a4
commit 2cb907a836
2 changed files with 8 additions and 1 deletions

View File

@@ -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;

View File

@@ -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_']);