(_node: jsep.Expression, context: object)
| 178 | |
| 179 | // eslint-disable-next-line complexity |
| 180 | function evaluate(_node: jsep.Expression, context: object) { |
| 181 | const node = _node as AnyExpression; |
| 182 | |
| 183 | switch (node.type) { |
| 184 | case 'ArrayExpression': |
| 185 | return evaluateArray(node.elements, context); |
| 186 | |
| 187 | case 'BinaryExpression': |
| 188 | return binops[node.operator](evaluate(node.left, context), evaluate(node.right, context)); |
| 189 | |
| 190 | case 'CallExpression': |
| 191 | let caller: object; |
| 192 | let fn: Function; |
| 193 | let assign: unknown[]; |
| 194 | if (node.callee.type === 'MemberExpression') { |
| 195 | assign = evaluateMember(node.callee as jsep.MemberExpression, context); |
| 196 | caller = assign[0] as object; |
| 197 | fn = assign[1] as Function; |
| 198 | } else { |
| 199 | fn = evaluate(node.callee, context); |
| 200 | } |
| 201 | if (typeof fn !== 'function') { |
| 202 | return undefined; |
| 203 | } |
| 204 | return fn.apply(caller!, evaluateArray(node.arguments, context)); |
| 205 | |
| 206 | case 'ConditionalExpression': |
| 207 | return evaluate(node.test, context) |
| 208 | ? evaluate(node.consequent, context) |
| 209 | : evaluate(node.alternate, context); |
| 210 | |
| 211 | case 'Identifier': |
| 212 | return context[node.name]; |
| 213 | |
| 214 | case 'Literal': |
| 215 | return node.value; |
| 216 | |
| 217 | case 'LogicalExpression': |
| 218 | if (node.operator === '||') { |
| 219 | return evaluate(node.left, context) || evaluate(node.right, context); |
| 220 | } else if (node.operator === '&&') { |
| 221 | return evaluate(node.left, context) && evaluate(node.right, context); |
| 222 | } |
| 223 | return binops[node.operator](evaluate(node.left, context), evaluate(node.right, context)); |
| 224 | |
| 225 | case 'MemberExpression': |
| 226 | return evaluateMember(node, context)[1]; |
| 227 | |
| 228 | case 'ThisExpression': |
| 229 | return context; |
| 230 | |
| 231 | case 'UnaryExpression': |
| 232 | return unops[node.operator](evaluate(node.argument, context)); |
| 233 | |
| 234 | default: |
| 235 | return undefined; |
| 236 | } |
| 237 | } |
no test coverage detected
searching dependent graphs…