UNPKG

shift-interpreter

Version:

Shift-interpreter is an experimental JavaScript meta-interpreter useful for reverse engineering and analysis. One notable difference from other projects is that shift-interpreter retains state over an entire script but can be fed expressions and statement

21 lines (15 loc) 562 B
import { Script } from 'shift-ast'; import { parseScript } from 'shift-parser'; import { Interpreter } from './interpreter'; export function interpretSource(source: string, context = {}) { return interpretTree(parseScript(source), context); } export function interpretTree(tree: Script, context = {}) { const interpreter = new Interpreter(); interpreter.pushContext(context); interpreter.load(tree); return interpreter.run(); } export default interpretSource; export const interpret = interpretSource; export { Interpreter } from './interpreter';