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

Function evaluateNode

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

Source from the content-addressed store, hash-verified

394}
395
396function 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
422function evaluateObjectExpression(node, scope) {
423 const output = {};

Callers 6

parseSafeExpressionFunction · 0.85
readVariableDeclarationFunction · 0.85
readCommonJsExportFunction · 0.85
readEsmExportFunction · 0.85
evaluateObjectExpressionFunction · 0.85
evaluateUnaryExpressionFunction · 0.85

Calls 3

evaluateObjectExpressionFunction · 0.85
evaluateUnaryExpressionFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected