From 107d6964a140a02d881653595fa7a3bcf2da85ed Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 20 Apr 2021 02:59:18 -0500 Subject: [PATCH] feat: ternary --- packages/sandbox/src/sandbox.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/sandbox/src/sandbox.js b/packages/sandbox/src/sandbox.js index daffdee..c04ea9f 100644 --- a/packages/sandbox/src/sandbox.js +++ b/packages/sandbox/src/sandbox.js @@ -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',