(node, scope)
| 420 | } |
| 421 | |
| 422 | function evaluateObjectExpression(node, scope) { |
| 423 | const output = {}; |
| 424 | for (const property of node.properties || []) { |
| 425 | if (!property || property.type !== "Property") { |
| 426 | throw new Error("Unsupported object property"); |
| 427 | } |
| 428 | if (property.kind !== "init" || property.method || property.shorthand) { |
| 429 | throw new Error("Unsupported object property kind"); |
| 430 | } |
| 431 | const key = property.computed |
| 432 | ? evaluateNode(property.key, scope) |
| 433 | : getPropertyKey(property.key); |
| 434 | const normalizedKey = |
| 435 | typeof key === "string" || typeof key === "number" ? String(key) : null; |
| 436 | if (!normalizedKey) { |
| 437 | throw new Error("Unsupported object key"); |
| 438 | } |
| 439 | output[normalizedKey] = evaluateNode(property.value, scope); |
| 440 | } |
| 441 | return output; |
| 442 | } |
| 443 | |
| 444 | function getPropertyKey(node) { |
| 445 | if (node?.type === "Identifier") return node.name; |
no test coverage detected