From 2cb907a8366e3273890f5ef6174b2e3970cd1720 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 28 Mar 2012 17:20:12 -0700 Subject: 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 --- src/auto/injector.js | 2 +- test/auto/injectorSpec.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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_']); -- cgit v1.2.3