Detect whether code needs a block wrapper {…} vs expression wrapper (…) inside an async IIFE.
(code: string)
| 30 | |
| 31 | /** Detect whether code needs a block wrapper {…} vs expression wrapper (…) inside an async IIFE. */ |
| 32 | function 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. */ |
| 41 | function wrapForEvaluate(code: string): string { |