diff --git a/lib/autoInject.js b/lib/autoInject.js index 35c852a68..40a250d50 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -3,11 +3,12 @@ import forOwn from 'lodash/forOwn'; import arrayMap from 'lodash/_arrayMap'; import clone from 'lodash/_copyArray'; import isArray from 'lodash/isArray'; +import trim from 'lodash/trim'; -var argsRegex = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var argsRegex = /^(function[^\(]*)?\(?\s*([^\)=]*)/m; function parseParams(func) { - return func.toString().match(argsRegex)[1].split(/\s*\,\s*/); + return trim(func.toString().match(argsRegex)[2]).split(/\s*\,\s*/); } /** diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index 9be3c1009..39c99a4b4 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -59,7 +59,7 @@ describe('autoInject', function () { callOrder.push('task1'); cb(null, 1); }, - task2: ['task3', function (task3, cb) { + task2: ['task3', function ( task3 , cb ) { expect(task3).to.equal(3); callOrder.push('task2'); cb(null, 2); @@ -86,4 +86,33 @@ describe('autoInject', function () { }, done); }); + var arrowSupport = true; + try { + /* jshint -W054 */ + new Function('x => x'); + /* jshint +W054 */ + } catch (e) { + arrowSupport = false; + } + + if (arrowSupport) { + // Needs to be run on ES6 only + + /* jshint -W061 */ + eval("(function() { " + + " it('should work with es6 arrow syntax', function (done) { " + + " async.autoInject({ " + + " task1: (cb) => cb(null, 1), " + + " task2: ( task3 , cb ) => cb(null, 2), " + + " task3: cb => cb(null, 3) " + + " }, (err, results) => { " + + " expect(results.task1).to.equal(1); " + + " expect(results.task3).to.equal(3); " + + " done(); " + + " }); " + + " }); " + + "}) " + )(); + /* jshint +W061 */ + } });