Skip to content

Commit 2cb907a

Browse files
committed
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 angular#829
1 parent 2f2fd46 commit 2cb907a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/auto/injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Implicit module which gets automatically added to each {@link angular.module.AUTO.$injector $injector}.
3939
*/
4040

41-
var FN_ARGS = /^function\s*[^\(]*\(([^\)]*)\)/m;
41+
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
4242
var FN_ARG_SPLIT = /,/;
4343
var FN_ARG = /^\s*(_?)(.+?)\1\s*$/;
4444
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;

test/auto/injectorSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ describe('injector', function() {
160160
});
161161

162162

163+
it('should handle no arg functions with spaces in the arguments list', function() {
164+
function fn( ) {}
165+
expect(inferInjectionArgs(fn)).toEqual([]);
166+
expect(fn.$inject).toEqual([]);
167+
});
168+
169+
163170
it('should handle args with both $ and _', function() {
164171
function $f_n0($a_) {}
165172
expect(inferInjectionArgs($f_n0)).toEqual(['$a_']);

0 commit comments

Comments
 (0)