diff --git a/src/auto/injector.js b/src/auto/injector.js index f6980a671403..cf76afba7f61 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -62,7 +62,7 @@ * Implicit module which gets automatically added to each {@link auto.$injector $injector}. */ -var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARGS = /^[^\(]*\(\s*([^\)]*)\)/m; var FN_ARG_SPLIT = /,/; var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/; var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index cff2ec5b0e7b..15199a23286c 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -237,6 +237,15 @@ describe('injector', function() { }); + // Only Chrome and Firefox support this syntax. + if (/chrome|firefox/i.test(navigator.userAgent)) { + it('should be possible to annotate functions that are declared using ES6 syntax', function() { + // The function is generated using `eval` as just having the ES6 syntax can break some browsers. + expect(annotate(eval('({ fn(x) { return; } })').fn)).toEqual(['x']); + }); + } + + it('should publish annotate API', function() { expect(angular.mock.$$annotate).toBe(annotate); spyOn(angular.mock, '$$annotate').andCallThrough();