UNPKG

@mariozechner/jailjs

Version:

Lightweight JavaScript interpreter for isolated execution. For plugins, user scripts, and browser extensions. Not for adversarial code - use SandboxJS or isolated-vm for that.

44 lines 1.4 kB
import type * as t from "@babel/types"; /** * Transform modern JavaScript (ES6+) to ES5 AST for interpreter execution * * This function uses Babel to transform modern JavaScript syntax to ES5, * then parses it into an AST. The resulting AST can be executed by the interpreter. * * @param code - Modern JavaScript code (ES6+, TypeScript, JSX, etc.) * @param options - Babel transformation options * @returns ES5 AST Program node * * @example * ```typescript * import { Interpreter } from '@mariozechner/jailjs'; * import { transformToES5 } from '@mariozechner/jailjs/transform'; * * const modernCode = ` * const double = (x) => x * 2; * const numbers = [1, 2, 3]; * numbers.map(double); * `; * * const ast = transformToES5(modernCode); * const interpreter = new Interpreter(); * const result = interpreter.evaluate(ast); * console.log(result); // [2, 4, 6] * ``` */ export declare function transformToES5(code: string, options?: { /** * Target environments (default: ES5-compatible) * Examples: { ie: 11 }, { chrome: 90 }, { node: '14' } */ targets?: Record<string, string | number>; /** * Enable TypeScript syntax support (requires @babel/preset-typescript) */ typescript?: boolean; /** * Enable JSX support (requires @babel/preset-react) */ jsx?: boolean; }): t.Program; //# sourceMappingURL=transform.d.ts.map