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

Function parseSafeExpression

src/lib/prettierFormatter.js:336–346  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

334}
335
336function parseSafeExpression(text) {
337 const wrapped = `(${text})`;
338 const ast = parse(wrapped, {
339 ecmaVersion: "latest",
340 sourceType: "module",
341 allowHashBang: true,
342 });
343 const statement = ast.body[0];
344 if (statement?.type !== "ExpressionStatement") return null;
345 return evaluateNode(statement.expression, new Map());
346}
347
348function readVariableDeclaration(statement, scope) {
349 if (statement?.type !== "VariableDeclaration") return null;

Callers 1

parseJsonLikeFunction · 0.85

Calls 2

evaluateNodeFunction · 0.85
parseFunction · 0.50

Tested by

no test coverage detected