MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / evaluateObjectExpression

Function evaluateObjectExpression

src/lib/prettierFormatter.js:422–442  ·  view source on GitHub ↗
(node, scope)

Source from the content-addressed store, hash-verified

420}
421
422function 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
444function getPropertyKey(node) {
445 if (node?.type === "Identifier") return node.name;

Callers 1

evaluateNodeFunction · 0.85

Calls 3

evaluateNodeFunction · 0.85
getPropertyKeyFunction · 0.85
StringInterface · 0.85

Tested by

no test coverage detected