(node: Expression, stack: Node[], ctx: BoxContext)
| 12 | * @see https://github.com/wessberg/ts-evaluator#setting-up-policies |
| 13 | */ |
| 14 | export const evaluateNode = (node: Expression, stack: Node[], ctx: BoxContext) => { |
| 15 | if (ctx.flags?.skipEvaluate) return |
| 16 | if (ctx.canEval && !ctx.canEval?.(node, stack)) return |
| 17 | |
| 18 | if (cacheMap.has(node)) { |
| 19 | return cacheMap.get(node) |
| 20 | } |
| 21 | |
| 22 | const result = evaluate({ |
| 23 | policy: { |
| 24 | deterministic: true, |
| 25 | network: false, |
| 26 | console: false, |
| 27 | maxOps: Number.POSITIVE_INFINITY, |
| 28 | maxOpDuration: 1000, |
| 29 | io: { read: true, write: false }, |
| 30 | process: { exit: false, spawnChild: false }, |
| 31 | }, |
| 32 | ...ctx.getEvaluateOptions?.(node, stack), |
| 33 | node: node.compilerNode as any, |
| 34 | typescript: ts as any, |
| 35 | }) |
| 36 | |
| 37 | const expr = result.success ? result.value : TsEvalError |
| 38 | cacheMap.set(node, expr) |
| 39 | |
| 40 | return expr |
| 41 | } |
| 42 | |
| 43 | export const safeEvaluateNode = <T>(node: Expression, stack: Node[], ctx: BoxContext) => { |
| 44 | const result = evaluateNode(node, stack, ctx) |
no test coverage detected