diff options
author | Alex Early <alexander.early@gmail.com> | 2016-05-15 18:58:54 -0700 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2016-05-15 18:58:54 -0700 |
commit | 5a9bbe52bd83c767fb14ddd917e796a4f6b1da39 (patch) | |
tree | fb753580655fbabeac64b740e0601423db0e7005 | |
parent | c54345d703a3d1959e6509c066c6966b2da6ee13 (diff) | |
parent | 79fd8872f1c9c549450142dbd6c5c4c6b0517d76 (diff) | |
download | async-5a9bbe52bd83c767fb14ddd917e796a4f6b1da39.tar.gz |
Merge pull request #1125 from steverobb/es6arrows
Arrow function support in ES6.
-rw-r--r-- | lib/autoInject.js | 5 | ||||
-rw-r--r-- | mocha_test/autoInject.js | 31 |
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/autoInject.js b/lib/autoInject.js index 35c852a..40a250d 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 9be3c10..39c99a4 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 */ + } }); |