From ba176c0e8ca3e257a75ab22cb3ecc020833a19be Mon Sep 17 00:00:00 2001 From: Steve Robb Date: Mon, 25 Apr 2016 07:46:04 +0100 Subject: [PATCH 1/5] Arrow function support in ES6. --- lib/autoInject.js | 4 ++-- mocha_test/autoInject.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/autoInject.js b/lib/autoInject.js index 02324a176..dc16f2f93 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -4,10 +4,10 @@ import arrayMap from 'lodash/_arrayMap'; import clone from 'lodash/_copyArray'; import isArray from 'lodash/isArray'; -var argsRegex = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var argsRegex = /^(function[^\(]*)?\(?\s*([^\)=]*)/m; function parseParams(func) { - return func.toString().match(argsRegex)[1].split(/\s*\,\s*/); + return func.toString().match(argsRegex)[2].trim().split(/\s*\,\s*/); } /** diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index 1408af981..8715a70ab 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -92,4 +92,17 @@ describe('autoInject', function () { }]); }); + // Needs to be run on ES6 only - not sure how you plan to handle this +// 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, task3, task1) => { +// expect(task1).to.equal(1); +// expect(task3).to.equal(3); +// done(); +// }); +// }); + }); From 3b0d9bd039266d6b3f9603d4bc30aae8307becc6 Mon Sep 17 00:00:00 2001 From: Steve Robb Date: Mon, 25 Apr 2016 09:39:36 +0100 Subject: [PATCH 2/5] Code style fixes. --- mocha_test/autoInject.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index 8715a70ab..39c68cdca 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -93,16 +93,16 @@ describe('autoInject', function () { }); // Needs to be run on ES6 only - not sure how you plan to handle this -// 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, task3, task1) => { -// expect(task1).to.equal(1); -// expect(task3).to.equal(3); -// done(); -// }); -// }); + // 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, task3, task1) => { + // expect(task1).to.equal(1); + // expect(task3).to.equal(3); + // done(); + // }); + // }); }); From 5577fbcf4e8b90c5a24bf91f67547e5c19b56f70 Mon Sep 17 00:00:00 2001 From: Steve Robb Date: Sun, 1 May 2016 10:34:33 +0100 Subject: [PATCH 3/5] Fixes for ES6 tests. --- mocha_test/autoInject.js | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index e548d91c9..f9e570265 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -74,17 +74,34 @@ describe('autoInject', function () { }); }); - // Needs to be run on ES6 only - not sure how you plan to handle this - // 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(); - // }); - // }); + 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 */ + } }); From bc19c5a8c3ff3a2dea88fca574c22dc6511ba924 Mon Sep 17 00:00:00 2001 From: Steve Robb Date: Sat, 7 May 2016 01:18:39 +0100 Subject: [PATCH 4/5] Spaces added to parameters in tests. --- mocha_test/autoInject.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index f9e570265..b90125b01 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); @@ -90,9 +90,9 @@ describe('autoInject', function () { 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) " + + " 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); " + From 9f1834c169bbb5f8d56ad2033393101b4762a38c Mon Sep 17 00:00:00 2001 From: Steve Robb Date: Sat, 7 May 2016 01:18:57 +0100 Subject: [PATCH 5/5] Use of lodash/trim instead of String.trim. --- lib/autoInject.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/autoInject.js b/lib/autoInject.js index 0ed3cee16..5cd83a2d1 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*([^\)=]*)/m; function parseParams(func) { - return func.toString().match(argsRegex)[2].trim().split(/\s*\,\s*/); + return trim(func.toString().match(argsRegex)[2]).split(/\s*\,\s*/); } /**