mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-13 17:02:23 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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_']);
|
||||
|
||||
Reference in New Issue
Block a user