Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arrow functions #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
8 changes: 8 additions & 0 deletions test/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down