Skip to content

Commit

Permalink
Merge pull request #1125 from steverobb/es6arrows
Browse files Browse the repository at this point in the history
Arrow function support in ES6.
  • Loading branch information
aearly committed May 16, 2016
2 parents c54345d + 79fd887 commit 5a9bbe5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/autoInject.js
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
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 */
}
});

0 comments on commit 5a9bbe5

Please sign in to comment.