Skip to content
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
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ module.exports = function (ast, vars) {
else if (node.type === 'TemplateElement') {
return node.value.cooked;
}
else if (node.type === 'NewExpression') {
var callee = walk(node.callee);
if (callee === FAIL) return FAIL;
if (typeof callee !== 'function') return FAIL;

var args = [];
for (var i = 0, l = node.arguments.length; i < l; i++) {
var x = walk(node.arguments[i]);
if (x === FAIL) return FAIL;
args.push(x);
}
return new callee(...args);
}
else return FAIL;
})(ast);

Expand Down
12 changes: 12 additions & 0 deletions test/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ test('evaluate this', function(t) {
});
t.equal(res, 101);
});

test('evaluate new', function(t) {
t.plan(1);

var src = '(new Array(1, v))[1]';
var ast = parse(src).body[0].expression;
var res = evaluate(ast, {
Array: Array,
v: 100
});
t.equal(res, 100);
});