(node, scope)
| 394 | } |
| 395 | |
| 396 | function evaluateNode(node, scope) { |
| 397 | if (!node) return null; |
| 398 | |
| 399 | switch (node.type) { |
| 400 | case "ObjectExpression": |
| 401 | return evaluateObjectExpression(node, scope); |
| 402 | case "ArrayExpression": |
| 403 | return node.elements.map((entry) => evaluateNode(entry, scope)); |
| 404 | case "Literal": |
| 405 | return node.value; |
| 406 | case "TemplateLiteral": |
| 407 | if (node.expressions.length) { |
| 408 | throw new Error("Template expressions are not supported"); |
| 409 | } |
| 410 | return node.quasis.map((part) => part.value.cooked ?? "").join(""); |
| 411 | case "Identifier": |
| 412 | if (scope.has(node.name)) return scope.get(node.name); |
| 413 | if (node.name === "undefined") return undefined; |
| 414 | throw new Error(`Unsupported identifier: ${node.name}`); |
| 415 | case "UnaryExpression": |
| 416 | return evaluateUnaryExpression(node, scope); |
| 417 | default: |
| 418 | throw new Error(`Unsupported node type: ${node.type}`); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | function evaluateObjectExpression(node, scope) { |
| 423 | const output = {}; |
no test coverage detected