Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/autoInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/);
}

/**
Expand Down
31 changes: 30 additions & 1 deletion mocha_test/autoInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
}
});