22 lines
590 B
JavaScript
22 lines
590 B
JavaScript
|
export default function(node, {evaluate, scope}) {
|
||
|
let asyncArgs = false;
|
||
|
const args = [];
|
||
|
for (let i = 0; i < node.arguments.length; i++) {
|
||
|
const arg = node.arguments[i];
|
||
|
const {async, value} = evaluate(arg, {scope});
|
||
|
asyncArgs ||= async;
|
||
|
args.push(value);
|
||
|
}
|
||
|
const {callee} = node;
|
||
|
const {async, value} = evaluate(callee, {scope});
|
||
|
if (asyncArgs || async) {
|
||
|
return {
|
||
|
async: true,
|
||
|
value: Promise
|
||
|
.all([value, Promise.all(args)])
|
||
|
.then(([callee, args]) => new callee(...args)),
|
||
|
};
|
||
|
}
|
||
|
return {value: new value(...args)};
|
||
|
}
|