MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / renderHeuristicBody

Function renderHeuristicBody

packages/kernel/core/src/code-recovery.ts:122–140  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

120};
121
122const renderHeuristicBody = (source: string): string => {
123 const withoutDefaultExport = source.replace(/^export\s+default\s+/, "").trim();
124
125 if (
126 (withoutDefaultExport.startsWith("async") || withoutDefaultExport.startsWith("(")) &&
127 withoutDefaultExport.includes("=>")
128 ) {
129 return wrapCallableBody(withoutDefaultExport);
130 }
131
132 if (FUNCTION_DECLARATION.test(withoutDefaultExport)) {
133 const name = withoutDefaultExport.match(FUNCTION_DECLARATION)?.[1];
134 return name
135 ? wrapNamedFunctionBody(withoutDefaultExport, name)
136 : wrapAnonymousFunctionBody(withoutDefaultExport);
137 }
138
139 return withoutDefaultExport;
140};
141
142export const recoverExecutionBody = (code: string): string => {
143 const source = extractCandidateSource(code);

Callers 1

recoverExecutionBodyFunction · 0.85

Calls 4

wrapNamedFunctionBodyFunction · 0.85
wrapCallableBodyFunction · 0.70
replaceMethod · 0.65

Tested by

no test coverage detected