diff --git a/index.js b/index.js index 92f4687..68e26c3 100644 --- a/index.js +++ b/index.js @@ -149,8 +149,8 @@ module.exports = function (ast, vars, opts) { else if (node.type === 'ReturnStatement') { return walk(node.argument, noExecute) } - else if (node.type === 'FunctionExpression') { - var bodies = node.body.body; + else if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') { + var bodies = node.body.body || [node.body]; // Create a "scope" for our arguments var oldVars = {}; diff --git a/test/eval.js b/test/eval.js index ed5cf90..0c3b026 100644 --- a/test/eval.js +++ b/test/eval.js @@ -44,6 +44,14 @@ test('array methods', function(t) { t.deepEqual(evaluate(ast), [2, 4, 6]); }); +test('array methods with arrow function', function(t) { + t.plan(1); + + var src = '[1, 2, 3].map(n => n * 2 )'; + var ast = parse(src).body[0].expression; + t.deepEqual(evaluate(ast), [2, 4, 6]); +}); + test('array methods invocation count', function(t) { t.plan(2);