feat: ternary

This commit is contained in:
cha0s 2021-04-20 02:59:18 -05:00
parent b6d6dc4766
commit 107d6964a1

View File

@ -98,7 +98,6 @@ export default class Sandbox {
console.error("evaluateAssignmentExpression(): Can't handle operator", node.operator);
return undefined;
}
return value;
};
if (Vasync) {
return {
@ -295,6 +294,19 @@ export default class Sandbox {
return {value: invokeMember(O.value, P.value, args, callOptional, memberOptional)};
}
evaluateConditionalExpression(node) {
const test = this.evaluate(node.test);
if (test.async) {
return {
async: true,
value: Promise.resolve(test.value).then((test) => (
this.evaluate(test ? node.consequent : node.alternate).value
)),
};
}
return this.evaluate(test.value ? node.consequent : node.alternate);
}
// eslint-disable-next-line class-methods-use-this
evaluateDirectiveLiteral({value}) {
return {value};
@ -560,6 +572,7 @@ export default class Sandbox {
'AwaitExpression',
'BinaryExpression',
'CallExpression',
'ConditionalExpression',
'DirectiveLiteral',
'Identifier',
'Literal',