UNPKG

open-loop-killer

Version:

Inject timeout protection into JavaScript loops to prevent infinite loops. Supports while, for, do-while, for-in, and for-of loops with customizable timeout and error messages.

32 lines (26 loc) 702 B
import type { Program, Statement } from 'estree'; /** * Options for configuring loop protection behavior */ export interface InjectorOptions { /** * Timeout in milliseconds before throwing error * @default 1000 */ timeout?: number; /** * Custom error message to throw when loop timeout is detected * @default 'Open Loop Detected!' */ errorMessage?: string; } /** * Processes an AST and injects loop protection code * @param ast - The Abstract Syntax Tree (Program or Statement) * @param options - Configuration options */ declare function injectionProcess( ast: Program | Statement | Statement[], options?: InjectorOptions ): void; export = injectionProcess;