silphius/app/astride/evaluators/conditional.js
2024-06-22 08:02:23 -05:00

14 lines
388 B
JavaScript

export default function(node, {evaluate, scope}) {
const test = evaluate(node.test, {scope});
if (test.async) {
return {
async: true,
value: (
Promise.resolve(test.value)
.then((test) => evaluate(test ? node.consequent : node.alternate).value, {scope})
),
};
}
return evaluate(test.value ? node.consequent : node.alternate, {scope});
}