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.

24 lines 689 B
import { parse as babelParse } from "@babel/parser"; /** * Parse JavaScript code into an AST * * This is a thin wrapper around @babel/parser that configures it * for ES5 script parsing. Users can import this to parse code, * or use their own parser and pass the AST to the interpreter. * * @param code - JavaScript code to parse * @returns Babel AST Program node */ export function parse(code) { try { const ast = babelParse(code, { sourceType: "script", plugins: [], }); return ast.program; } catch (parseError) { throw new Error(`Parse error: ${parseError.message}`); } } //# sourceMappingURL=parser.js.map