@mondaydotcomorg/atp-compiler
Version:
Production-ready compiler for transforming async iteration patterns into resumable operations with checkpoint-based state management
45 lines • 1.38 kB
JavaScript
/**
* Default Array Transformer Plugin
* Wraps the existing ArrayTransformer
*/
import * as t from '@babel/types';
import { ArrayTransformer } from '../../transformer/array-transformer.js';
export class DefaultArrayTransformerPlugin {
name = 'atp-array-transformer';
version = '1.0.0';
priority = 100;
transformer;
constructor(batchSizeThreshold) {
this.transformer = new ArrayTransformer(batchSizeThreshold);
}
getVisitor(config) {
return {
CallExpression: (path) => {
const node = path.node;
if (this.isArrayMethodCall(node)) {
this.transformer.transformArrayMethod(path);
}
},
};
}
getMetadata() {
return {
arrayMethodCount: this.transformer.getTransformCount(),
};
}
reset() {
this.transformer.resetTransformCount();
}
isArrayMethodCall(node) {
if (!t.isMemberExpression(node.callee)) {
return false;
}
const property = node.callee.property;
if (!t.isIdentifier(property)) {
return false;
}
const arrayMethods = ['map', 'forEach', 'filter', 'reduce', 'find', 'some', 'every', 'flatMap'];
return arrayMethods.includes(property.name);
}
}
//# sourceMappingURL=array-transformer-plugin.js.map