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

Function needsBlockWrapper

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

Detect whether code needs a block wrapper {…} vs expression wrapper (…) inside an async IIFE.

(code: string)

Source from the content-addressed store, hash-verified

30
31/** Detect whether code needs a block wrapper {…} vs expression wrapper (…) inside an async IIFE. */
32function needsBlockWrapper(code: string): boolean {
33 const trimmed = code.trim();
34 if (trimmed.split('\n').length > 1) return true;
35 if (/\b(const|let|var|function|class|return|throw|if|for|while|switch|try)\b/.test(trimmed)) return true;
36 if (trimmed.includes(';')) return true;
37 return false;
38}
39
40/** Wrap code for page.evaluate(), using async IIFE with block or expression body as needed. */
41function wrapForEvaluate(code: string): string {

Callers 1

wrapForEvaluateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected