MCPcopy
hub / github.com/garrytan/gstack / wrapForEvaluate

Function wrapForEvaluate

browse/src/read-commands.ts:41–47  ·  view source on GitHub ↗

Wrap code for page.evaluate(), using async IIFE with block or expression body as needed.

(code: string)

Source from the content-addressed store, hash-verified

39
40/** Wrap code for page.evaluate(), using async IIFE with block or expression body as needed. */
41function wrapForEvaluate(code: string): string {
42 if (!hasAwait(code)) return code;
43 const trimmed = code.trim();
44 return needsBlockWrapper(trimmed)
45 ? `(async()=>{\n${code}\n})()`
46 : `(async()=>(${trimmed}))()`;
47}
48
49/** Flags split out of `js`/`eval` args by parseOutArgs. */
50export interface OutArgs {

Callers 1

handleReadCommandFunction · 0.85

Calls 2

hasAwaitFunction · 0.85
needsBlockWrapperFunction · 0.85

Tested by

no test coverage detected