UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

30 lines (29 loc) • 733 B
import { parse } from "acorn"; //#region src/agents/code-mode-script-syntax.ts /** Mirrors the worker's async-arrow body grammar so valid top-level await/return stay legal. */ function buildCodeModeScriptParseSource(e) { return { source: `(async () => { ${e}\n})`, codeOffset: 15 }; } function parseCodeModeScriptSyntax(e) { const { source: t } = buildCodeModeScriptParseSource(e); try { return { ok: true, program: parse(t, { ecmaVersion: "latest" }) }; } catch (e) { const t = e; return { ok: false, message: t.message.replace(/ \(\d+:\d+\)$/u, ""), line: t.loc.line - 1, column: t.loc.column }; } } //#endregion export { parseCodeModeScriptSyntax as n, buildCodeModeScriptParseSource as t };