From 44a96a4c140873d9fd8484d870af83a0bb9acabd Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Thu, 23 Jul 2015 23:49:00 +0200 Subject: [PATCH] fix($injector): Allows ES6 function syntax Closes #12424 Closes #12425 --- src/auto/injector.js | 2 +- test/auto/injectorSpec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index 303348f5ee67..189421da8338 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 391082e28a26..14e4ceba8b43 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -243,6 +243,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();