UNPKG

@mondaydotcomorg/atp-compiler

Version:

Production-ready compiler for transforming async iteration patterns into resumable operations with checkpoint-based state management

69 lines 2.06 kB
import * as t from '@babel/types'; import { isArrayMethod } from './utils.js'; /** * Find LLM call expression in AST node */ export function findLLMCallExpression(body) { let found = null; const visit = (node) => { if (found) return; if (t.isAwaitExpression(node) && t.isCallExpression(node.argument)) { const call = node.argument; if (t.isMemberExpression(call.callee)) { found = call; return; } } Object.keys(node).forEach((key) => { const value = node[key]; if (Array.isArray(value)) { value.forEach((item) => { if (item && typeof item === 'object' && item.type) { visit(item); } }); } else if (value && typeof value === 'object' && value.type) { visit(value); } }); }; visit(body); return found; } /** * Get array method name from call expression */ export function getArrayMethodName(node) { const arrayMethods = ['map', 'forEach', 'filter', 'reduce', 'find', 'some', 'every', 'flatMap']; for (const method of arrayMethods) { if (isArrayMethod(node, method)) { return method; } } return null; } /** * Get runtime method name for array method */ export function getRuntimeMethodName(arrayMethod) { const mapping = { map: 'resumableMap', forEach: 'resumableForEach', filter: 'resumableFilter', reduce: 'resumableReduce', find: 'resumableFind', some: 'resumableSome', every: 'resumableEvery', flatMap: 'resumableFlatMap', }; return mapping[arrayMethod] || null; } /** * Check if method can use batch parallel optimization */ export function canUseBatchParallel(methodName) { return ['map', 'forEach', 'filter', 'find', 'some', 'every'].includes(methodName); } //# sourceMappingURL=array-transformer-utils.js.map