@mondaydotcomorg/atp-compiler 0.18.2 → 0.18.4-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/__tests__/unit/default-compiler.test.ts +259 -0
  2. package/__tests__/unit/plugin-system.test.ts +401 -0
  3. package/dist/atp-compiler/src/index.d.ts +8 -0
  4. package/dist/atp-compiler/src/index.d.ts.map +1 -1
  5. package/dist/atp-compiler/src/index.js +9 -0
  6. package/dist/atp-compiler/src/index.js.map +1 -1
  7. package/dist/atp-compiler/src/plugin-system/create-default-compiler.d.ts +40 -0
  8. package/dist/atp-compiler/src/plugin-system/create-default-compiler.d.ts.map +1 -0
  9. package/dist/atp-compiler/src/plugin-system/create-default-compiler.js +40 -0
  10. package/dist/atp-compiler/src/plugin-system/create-default-compiler.js.map +1 -0
  11. package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.d.ts +18 -0
  12. package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.d.ts.map +1 -0
  13. package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.js +45 -0
  14. package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.js.map +1 -0
  15. package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.d.ts +17 -0
  16. package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.d.ts.map +1 -0
  17. package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.js +33 -0
  18. package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.js.map +1 -0
  19. package/dist/atp-compiler/src/plugin-system/default-plugins/index.d.ts +11 -0
  20. package/dist/atp-compiler/src/plugin-system/default-plugins/index.d.ts.map +1 -0
  21. package/dist/atp-compiler/src/plugin-system/default-plugins/index.js +11 -0
  22. package/dist/atp-compiler/src/plugin-system/default-plugins/index.js.map +1 -0
  23. package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.d.ts +17 -0
  24. package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.d.ts.map +1 -0
  25. package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.js +36 -0
  26. package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.js.map +1 -0
  27. package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.d.ts +19 -0
  28. package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.d.ts.map +1 -0
  29. package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.js +49 -0
  30. package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.js.map +1 -0
  31. package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.d.ts +31 -0
  32. package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.d.ts.map +1 -0
  33. package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.js +60 -0
  34. package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.js.map +1 -0
  35. package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.d.ts +48 -0
  36. package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.d.ts.map +1 -0
  37. package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.js +108 -0
  38. package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.js.map +1 -0
  39. package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.d.ts +53 -0
  40. package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.d.ts.map +1 -0
  41. package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.js +106 -0
  42. package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.js.map +1 -0
  43. package/dist/atp-compiler/src/plugin-system/index.d.ts +14 -0
  44. package/dist/atp-compiler/src/plugin-system/index.d.ts.map +1 -0
  45. package/dist/atp-compiler/src/plugin-system/index.js +16 -0
  46. package/dist/atp-compiler/src/plugin-system/index.js.map +1 -0
  47. package/dist/atp-compiler/src/plugin-system/pluggable-compiler.d.ts +102 -0
  48. package/dist/atp-compiler/src/plugin-system/pluggable-compiler.d.ts.map +1 -0
  49. package/dist/atp-compiler/src/plugin-system/pluggable-compiler.js +280 -0
  50. package/dist/atp-compiler/src/plugin-system/pluggable-compiler.js.map +1 -0
  51. package/dist/atp-compiler/src/plugin-system/plugin-api.d.ts +165 -0
  52. package/dist/atp-compiler/src/plugin-system/plugin-api.d.ts.map +1 -0
  53. package/dist/atp-compiler/src/plugin-system/plugin-api.js +180 -0
  54. package/dist/atp-compiler/src/plugin-system/plugin-api.js.map +1 -0
  55. package/dist/atp-compiler/src/transformer/index.d.ts +15 -1
  56. package/dist/atp-compiler/src/transformer/index.d.ts.map +1 -1
  57. package/dist/atp-compiler/src/transformer/index.js +17 -0
  58. package/dist/atp-compiler/src/transformer/index.js.map +1 -1
  59. package/dist/atp-compiler/src/types/compiler-interface.d.ts +61 -0
  60. package/dist/atp-compiler/src/types/compiler-interface.d.ts.map +1 -0
  61. package/dist/atp-compiler/src/types/compiler-interface.js +18 -0
  62. package/dist/atp-compiler/src/types/compiler-interface.js.map +1 -0
  63. package/dist/runtime/src/approval/index.js +2 -1
  64. package/dist/runtime/src/approval/index.js.map +1 -1
  65. package/dist/runtime/src/index.d.ts +1 -1
  66. package/dist/runtime/src/index.d.ts.map +1 -1
  67. package/dist/runtime/src/index.js +1 -1
  68. package/dist/runtime/src/index.js.map +1 -1
  69. package/dist/runtime/src/llm/index.d.ts +1 -1
  70. package/dist/runtime/src/llm/index.d.ts.map +1 -1
  71. package/dist/runtime/src/llm/index.js +1 -1
  72. package/dist/runtime/src/llm/index.js.map +1 -1
  73. package/dist/runtime/src/llm/replay.d.ts +75 -0
  74. package/dist/runtime/src/llm/replay.d.ts.map +1 -1
  75. package/dist/runtime/src/llm/replay.js +187 -5
  76. package/dist/runtime/src/llm/replay.js.map +1 -1
  77. package/dist/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +13 -5
  79. package/src/index.ts +26 -0
  80. package/src/plugin-system/create-default-compiler.ts +57 -0
  81. package/src/plugin-system/default-plugins/array-transformer-plugin.ts +57 -0
  82. package/src/plugin-system/default-plugins/detection-plugin.ts +41 -0
  83. package/src/plugin-system/default-plugins/index.ts +12 -0
  84. package/src/plugin-system/default-plugins/loop-transformer-plugin.ts +47 -0
  85. package/src/plugin-system/default-plugins/promise-transformer-plugin.ts +63 -0
  86. package/src/plugin-system/examples/loop-transformer-plugin.ts +76 -0
  87. package/src/plugin-system/examples/security-validator-plugin.ts +168 -0
  88. package/src/plugin-system/examples/timeout-plugin.ts +158 -0
  89. package/src/plugin-system/index.ts +19 -0
  90. package/src/plugin-system/pluggable-compiler.ts +318 -0
  91. package/src/plugin-system/plugin-api.ts +330 -0
  92. package/src/transformer/index.ts +21 -1
  93. package/src/types/compiler-interface.ts +79 -0
@@ -1 +1 @@
1
- {"root":["../src/index.ts","../src/types.ts","../src/runtime/batch-parallel.ts","../src/runtime/checkpoint-manager.ts","../src/runtime/context.ts","../src/runtime/errors.ts","../src/runtime/index.ts","../src/runtime/resumable-arrays.ts","../src/runtime/resumable-loops.ts","../src/runtime/resumable-parallel.ts","../src/transformer/array-transformer-batch.ts","../src/transformer/array-transformer-sequential.ts","../src/transformer/array-transformer-utils.ts","../src/transformer/array-transformer-wrappers.ts","../src/transformer/array-transformer.ts","../src/transformer/batch-detector.ts","../src/transformer/batch-optimizer.ts","../src/transformer/detector.ts","../src/transformer/index.ts","../src/transformer/loop-transformer.ts","../src/transformer/promise-transformer.ts","../src/transformer/utils.ts"],"version":"5.9.3"}
1
+ {"root":["../src/index.ts","../src/types.ts","../src/plugin-system/create-default-compiler.ts","../src/plugin-system/index.ts","../src/plugin-system/pluggable-compiler.ts","../src/plugin-system/plugin-api.ts","../src/plugin-system/default-plugins/array-transformer-plugin.ts","../src/plugin-system/default-plugins/detection-plugin.ts","../src/plugin-system/default-plugins/index.ts","../src/plugin-system/default-plugins/loop-transformer-plugin.ts","../src/plugin-system/default-plugins/promise-transformer-plugin.ts","../src/plugin-system/examples/loop-transformer-plugin.ts","../src/plugin-system/examples/security-validator-plugin.ts","../src/plugin-system/examples/timeout-plugin.ts","../src/runtime/batch-parallel.ts","../src/runtime/checkpoint-manager.ts","../src/runtime/context.ts","../src/runtime/errors.ts","../src/runtime/index.ts","../src/runtime/resumable-arrays.ts","../src/runtime/resumable-loops.ts","../src/runtime/resumable-parallel.ts","../src/transformer/array-transformer-batch.ts","../src/transformer/array-transformer-sequential.ts","../src/transformer/array-transformer-utils.ts","../src/transformer/array-transformer-wrappers.ts","../src/transformer/array-transformer.ts","../src/transformer/batch-detector.ts","../src/transformer/batch-optimizer.ts","../src/transformer/detector.ts","../src/transformer/index.ts","../src/transformer/loop-transformer.ts","../src/transformer/promise-transformer.ts","../src/transformer/utils.ts","../src/types/compiler-interface.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondaydotcomorg/atp-compiler",
3
- "version": "0.18.2",
3
+ "version": "0.18.4-rc.1",
4
4
  "description": "Production-ready compiler for transforming async iteration patterns into resumable operations with checkpoint-based state management",
5
5
  "type": "module",
6
6
  "main": "dist/atp-compiler/src/index.js",
@@ -10,6 +10,14 @@
10
10
  "types": "./dist/atp-compiler/src/index.d.ts",
11
11
  "import": "./dist/atp-compiler/src/index.js"
12
12
  },
13
+ "./plugin-system": {
14
+ "types": "./dist/atp-compiler/src/plugin-system/index.d.ts",
15
+ "import": "./dist/atp-compiler/src/plugin-system/index.js"
16
+ },
17
+ "./plugin-system/*": {
18
+ "types": "./dist/atp-compiler/src/plugin-system/*.d.ts",
19
+ "import": "./dist/atp-compiler/src/plugin-system/*.js"
20
+ },
13
21
  "./*": {
14
22
  "types": "./dist/atp-compiler/src/*.d.ts",
15
23
  "import": "./dist/atp-compiler/src/*.js"
@@ -47,15 +55,15 @@
47
55
  "@babel/parser": "^7.26.0",
48
56
  "@babel/traverse": "^7.26.0",
49
57
  "@babel/types": "^7.26.0",
50
- "@mondaydotcomorg/atp-protocol": "0.18.2",
51
- "@mondaydotcomorg/atp-runtime": "0.18.2",
58
+ "@mondaydotcomorg/atp-protocol": "0.18.4-rc.1",
59
+ "@mondaydotcomorg/atp-runtime": "0.18.4-rc.1",
52
60
  "@types/babel__generator": "^7.6.0",
53
61
  "@types/babel__traverse": "^7.20.0",
54
62
  "nanoid": "^5.0.0"
55
63
  },
56
64
  "peerDependencies": {
57
- "@mondaydotcomorg/atp-protocol": "0.18.2",
58
- "@mondaydotcomorg/atp-runtime": "0.18.2"
65
+ "@mondaydotcomorg/atp-protocol": "0.18.4-rc.1",
66
+ "@mondaydotcomorg/atp-runtime": "0.18.4-rc.1"
59
67
  },
60
68
  "devDependencies": {
61
69
  "@stryker-mutator/core": "^8.0.0",
package/src/index.ts CHANGED
@@ -1,6 +1,32 @@
1
+ // Core exports
1
2
  export * from './types.js';
2
3
  export * from './transformer/index.js';
3
4
  export * from './runtime/index.js';
4
5
 
6
+ // Compiler interface exports
7
+ export * from './types/compiler-interface.js';
8
+
9
+ // Plugin system exports
10
+ export * from './plugin-system/index.js';
11
+
12
+ // Main exports
5
13
  export { ATPCompiler } from './transformer/index.js';
6
14
  export { initializeRuntime, cleanupRuntime } from './runtime/index.js';
15
+ export { PluggableCompiler } from './plugin-system/pluggable-compiler.js';
16
+ export { PluginRegistry } from './plugin-system/plugin-api.js';
17
+ export { createDefaultCompiler } from './plugin-system/create-default-compiler.js';
18
+
19
+ // Plugin type exports for convenience
20
+ export type {
21
+ CompilerPlugin,
22
+ DetectionPlugin,
23
+ TransformationPlugin,
24
+ OptimizerPlugin,
25
+ ValidatorPlugin,
26
+ PluginContext,
27
+ BabelVisitor,
28
+ } from './plugin-system/plugin-api.js';
29
+ export type { ATPCompilerLike } from './plugin-system/create-default-compiler.js';
30
+
31
+ // Compiler interface type exports
32
+ export type { ICompiler, CacheStats } from './types/compiler-interface.js';
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Factory function to create a PluggableCompiler with all default plugins
3
+ *
4
+ * This makes PluggableCompiler a drop-in replacement for ATPCompiler
5
+ */
6
+
7
+ import { PluggableCompiler } from './pluggable-compiler.js';
8
+ import { DefaultDetectionPlugin } from './default-plugins/detection-plugin.js';
9
+ import { DefaultLoopTransformerPlugin } from './default-plugins/loop-transformer-plugin.js';
10
+ import { DefaultArrayTransformerPlugin } from './default-plugins/array-transformer-plugin.js';
11
+ import { DefaultPromiseTransformerPlugin } from './default-plugins/promise-transformer-plugin.js';
12
+ import type { CompilerConfig } from '../types.js';
13
+
14
+ /**
15
+ * Create a PluggableCompiler with all default ATP transformations
16
+ *
17
+ * This provides the same functionality as ATPCompiler but with plugin extensibility.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Drop-in replacement for ATPCompiler
22
+ * const compiler = createDefaultCompiler({
23
+ * enableBatchParallel: true,
24
+ * maxBatchSize: 10,
25
+ * });
26
+ *
27
+ * // Works exactly like ATPCompiler
28
+ * const result = await compiler.transform(code);
29
+ *
30
+ * // But you can also add custom plugins!
31
+ * compiler.use(myCustomPlugin);
32
+ * ```
33
+ */
34
+ export function createDefaultCompiler(config: Partial<CompilerConfig> = {}): PluggableCompiler {
35
+ const compiler = new PluggableCompiler(config);
36
+
37
+ // Register default plugins that provide all ATP compiler functionality
38
+ compiler.use(new DefaultDetectionPlugin());
39
+ compiler.use(new DefaultLoopTransformerPlugin(config.batchSizeThreshold));
40
+ compiler.use(new DefaultArrayTransformerPlugin(config.batchSizeThreshold));
41
+ compiler.use(new DefaultPromiseTransformerPlugin(config.enableBatchParallel));
42
+
43
+ return compiler;
44
+ }
45
+
46
+ /**
47
+ * Type alias for backward compatibility
48
+ *
49
+ * This allows:
50
+ * ```typescript
51
+ * import type { ATPCompilerLike } from '@mondaydotcomorg/atp-compiler';
52
+ *
53
+ * const compiler: ATPCompilerLike = createDefaultCompiler();
54
+ * ```
55
+ */
56
+ export type ATPCompilerLike = PluggableCompiler;
57
+
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Default Array Transformer Plugin
3
+ * Wraps the existing ArrayTransformer
4
+ */
5
+
6
+ import * as t from '@babel/types';
7
+ import type { TransformationPlugin, BabelVisitor } from '../plugin-api.js';
8
+ import type { CompilerConfig, TransformMetadata } from '../../types.js';
9
+ import { ArrayTransformer } from '../../transformer/array-transformer.js';
10
+
11
+ export class DefaultArrayTransformerPlugin implements TransformationPlugin {
12
+ name = 'atp-array-transformer';
13
+ version = '1.0.0';
14
+ priority = 100;
15
+
16
+ private transformer: ArrayTransformer;
17
+
18
+ constructor(batchSizeThreshold?: number) {
19
+ this.transformer = new ArrayTransformer(batchSizeThreshold);
20
+ }
21
+
22
+ getVisitor(config: CompilerConfig): BabelVisitor {
23
+ return {
24
+ CallExpression: (path: any) => {
25
+ const node = path.node;
26
+ if (this.isArrayMethodCall(node)) {
27
+ this.transformer.transformArrayMethod(path);
28
+ }
29
+ },
30
+ };
31
+ }
32
+
33
+ getMetadata(): Partial<TransformMetadata> {
34
+ return {
35
+ arrayMethodCount: this.transformer.getTransformCount(),
36
+ };
37
+ }
38
+
39
+ reset(): void {
40
+ this.transformer.resetTransformCount();
41
+ }
42
+
43
+ private isArrayMethodCall(node: t.CallExpression): boolean {
44
+ if (!t.isMemberExpression(node.callee)) {
45
+ return false;
46
+ }
47
+
48
+ const property = node.callee.property;
49
+ if (!t.isIdentifier(property)) {
50
+ return false;
51
+ }
52
+
53
+ const arrayMethods = ['map', 'forEach', 'filter', 'reduce', 'find', 'some', 'every', 'flatMap'];
54
+ return arrayMethods.includes(property.name);
55
+ }
56
+ }
57
+
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Default Detection Plugin
3
+ * Wraps the existing AsyncIterationDetector
4
+ */
5
+
6
+ import type * as t from '@babel/types';
7
+ import type { DetectionPlugin } from '../plugin-api.js';
8
+ import type { CompilerConfig, AsyncPattern, DetectionResult } from '../../types.js';
9
+ import { AsyncIterationDetector } from '../../transformer/detector.js';
10
+
11
+ export class DefaultDetectionPlugin implements DetectionPlugin {
12
+ name = 'atp-default-detector';
13
+ version = '1.0.0';
14
+ priority = 100;
15
+ patterns: AsyncPattern[] = [
16
+ 'for-of-await',
17
+ 'while-await',
18
+ 'map-async',
19
+ 'forEach-async',
20
+ 'filter-async',
21
+ 'reduce-async',
22
+ 'find-async',
23
+ 'some-async',
24
+ 'every-async',
25
+ 'flatMap-async',
26
+ 'promise-all',
27
+ 'promise-allSettled',
28
+ ];
29
+
30
+ private detector: AsyncIterationDetector;
31
+
32
+ constructor() {
33
+ this.detector = new AsyncIterationDetector();
34
+ }
35
+
36
+ async detect(code: string, ast: t.File): Promise<DetectionResult> {
37
+ // Use existing detector
38
+ return this.detector.detect(code);
39
+ }
40
+ }
41
+
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Default Plugins
3
+ *
4
+ * These plugins wrap the existing ATP Compiler functionality,
5
+ * making the PluggableCompiler a drop-in replacement for ATPCompiler.
6
+ */
7
+
8
+ export * from './detection-plugin.js';
9
+ export * from './loop-transformer-plugin.js';
10
+ export * from './array-transformer-plugin.js';
11
+ export * from './promise-transformer-plugin.js';
12
+
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Default Loop Transformer Plugin
3
+ * Wraps the existing LoopTransformer
4
+ */
5
+
6
+ import type { TransformationPlugin, BabelVisitor } from '../plugin-api.js';
7
+ import type { CompilerConfig, TransformMetadata } from '../../types.js';
8
+ import { LoopTransformer } from '../../transformer/loop-transformer.js';
9
+
10
+ export class DefaultLoopTransformerPlugin implements TransformationPlugin {
11
+ name = 'atp-loop-transformer';
12
+ version = '1.0.0';
13
+ priority = 100;
14
+
15
+ private transformer: LoopTransformer;
16
+
17
+ constructor(batchSizeThreshold?: number) {
18
+ this.transformer = new LoopTransformer(batchSizeThreshold);
19
+ }
20
+
21
+ getVisitor(config: CompilerConfig): BabelVisitor {
22
+ return {
23
+ ForOfStatement: (path: any) => {
24
+ this.transformer.transformForOfLoop(path);
25
+ },
26
+
27
+ WhileStatement: (path: any) => {
28
+ this.transformer.transformWhileLoop(path);
29
+ },
30
+
31
+ ForStatement: (path: any) => {
32
+ this.transformer.transformForLoop(path);
33
+ },
34
+ };
35
+ }
36
+
37
+ getMetadata(): Partial<TransformMetadata> {
38
+ return {
39
+ loopCount: this.transformer.getTransformCount(),
40
+ };
41
+ }
42
+
43
+ reset(): void {
44
+ this.transformer.resetTransformCount();
45
+ }
46
+ }
47
+
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Default Promise Transformer Plugin
3
+ * Wraps the existing PromiseTransformer
4
+ */
5
+
6
+ import * as t from '@babel/types';
7
+ import type { TransformationPlugin, BabelVisitor } from '../plugin-api.js';
8
+ import type { CompilerConfig, TransformMetadata } from '../../types.js';
9
+ import { PromiseTransformer } from '../../transformer/promise-transformer.js';
10
+
11
+ export class DefaultPromiseTransformerPlugin implements TransformationPlugin {
12
+ name = 'atp-promise-transformer';
13
+ version = '1.0.0';
14
+ priority = 100;
15
+
16
+ private transformer: PromiseTransformer;
17
+
18
+ constructor(enableBatchParallel?: boolean) {
19
+ this.transformer = new PromiseTransformer(enableBatchParallel);
20
+ }
21
+
22
+ getVisitor(config: CompilerConfig): BabelVisitor {
23
+ return {
24
+ CallExpression: (path: any) => {
25
+ const node = path.node;
26
+ if (this.isPromiseAllCall(node)) {
27
+ this.transformer.transformPromiseAll(path);
28
+ } else if (this.isPromiseAllSettledCall(node)) {
29
+ this.transformer.transformPromiseAllSettled(path);
30
+ }
31
+ },
32
+ };
33
+ }
34
+
35
+ getMetadata(): Partial<TransformMetadata> {
36
+ return {
37
+ parallelCallCount: this.transformer.getTransformCount(),
38
+ };
39
+ }
40
+
41
+ reset(): void {
42
+ this.transformer.resetTransformCount();
43
+ }
44
+
45
+ private isPromiseAllCall(node: t.CallExpression): boolean {
46
+ const callee = node.callee;
47
+ return (
48
+ t.isMemberExpression(callee) &&
49
+ t.isIdentifier(callee.object, { name: 'Promise' }) &&
50
+ t.isIdentifier(callee.property, { name: 'all' })
51
+ );
52
+ }
53
+
54
+ private isPromiseAllSettledCall(node: t.CallExpression): boolean {
55
+ const callee = node.callee;
56
+ return (
57
+ t.isMemberExpression(callee) &&
58
+ t.isIdentifier(callee.object, { name: 'Promise' }) &&
59
+ t.isIdentifier(callee.property, { name: 'allSettled' })
60
+ );
61
+ }
62
+ }
63
+
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Example: Loop Transformer as a Plugin
3
+ *
4
+ * Shows how to migrate existing LoopTransformer to plugin architecture
5
+ * This demonstrates the migration path for built-in transformers
6
+ */
7
+
8
+ import type { NodePath } from '@babel/traverse';
9
+ import * as t from '@babel/types';
10
+ import type { TransformationPlugin, BabelVisitor } from '../plugin-api.js';
11
+ import type { CompilerConfig, TransformMetadata } from '../../types.js';
12
+ import { LoopTransformer } from '../../transformer/loop-transformer.js';
13
+
14
+ /**
15
+ * Loop Transformer Plugin
16
+ *
17
+ * Transforms for...of, while, and for loops into resumable versions
18
+ * with checkpoint-based state management
19
+ */
20
+ export class LoopTransformerPlugin implements TransformationPlugin {
21
+ name = 'loop-transformer';
22
+ version = '1.0.0';
23
+ priority = 50; // Standard priority for core transformations
24
+
25
+ private transformer: LoopTransformer;
26
+
27
+ constructor(batchSizeThreshold: number = 10) {
28
+ this.transformer = new LoopTransformer(batchSizeThreshold);
29
+ }
30
+
31
+ initialize(config: CompilerConfig): void {
32
+ // Initialize with config if needed
33
+ console.log('[LoopTransformerPlugin] Initialized');
34
+ }
35
+
36
+ getVisitor(config: CompilerConfig): BabelVisitor {
37
+ return {
38
+ ForOfStatement: (path: NodePath<t.ForOfStatement>) => {
39
+ this.transformer.transformForOfLoop(path as any);
40
+ },
41
+
42
+ WhileStatement: (path: NodePath<t.WhileStatement>) => {
43
+ this.transformer.transformWhileLoop(path as any);
44
+ },
45
+
46
+ ForStatement: (path: NodePath<t.ForStatement>) => {
47
+ this.transformer.transformForLoop(path as any);
48
+ },
49
+ };
50
+ }
51
+
52
+ getMetadata(): Partial<TransformMetadata> {
53
+ return {
54
+ loopCount: this.transformer.getTransformCount(),
55
+ arrayMethodCount: 0,
56
+ parallelCallCount: 0,
57
+ batchableCount: 0,
58
+ };
59
+ }
60
+
61
+ reset(): void {
62
+ this.transformer.resetTransformCount();
63
+ }
64
+
65
+ dispose(): void {
66
+ console.log('[LoopTransformerPlugin] Disposed');
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Factory function for easy creation
72
+ */
73
+ export function createLoopTransformerPlugin(batchSizeThreshold?: number): LoopTransformerPlugin {
74
+ return new LoopTransformerPlugin(batchSizeThreshold);
75
+ }
76
+
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Example Plugin: Security Validator
3
+ *
4
+ * Validates code for security issues before transformation
5
+ *
6
+ * @example
7
+ * const compiler = new PluggableCompiler();
8
+ * compiler.use(new SecurityValidatorPlugin({
9
+ * forbiddenPatterns: [/eval\s*\(/],
10
+ * maxComplexity: 20
11
+ * }));
12
+ */
13
+
14
+ import type * as t from '@babel/types';
15
+ import _traverse from '@babel/traverse';
16
+ const traverse = (_traverse as any).default || _traverse;
17
+ import type { ValidatorPlugin } from '../plugin-api.js';
18
+ import type { CompilerConfig } from '../../types.js';
19
+
20
+ export interface SecurityValidatorOptions {
21
+ /**
22
+ * Forbidden patterns (regex)
23
+ */
24
+ forbiddenPatterns?: RegExp[];
25
+
26
+ /**
27
+ * Maximum cyclomatic complexity
28
+ */
29
+ maxComplexity?: number;
30
+
31
+ /**
32
+ * Maximum nesting depth
33
+ */
34
+ maxNesting?: number;
35
+
36
+ /**
37
+ * Forbidden global access
38
+ */
39
+ forbiddenGlobals?: string[];
40
+ }
41
+
42
+ export class SecurityValidatorPlugin implements ValidatorPlugin {
43
+ name = 'security-validator';
44
+ version = '1.0.0';
45
+ priority = 100; // Run first
46
+
47
+ private options: SecurityValidatorOptions;
48
+
49
+ constructor(options: SecurityValidatorOptions = {}) {
50
+ this.options = {
51
+ forbiddenPatterns: options.forbiddenPatterns || [
52
+ /\beval\s*\(/,
53
+ /new\s+Function\s*\(/,
54
+ /constructor\s*\[\s*['"`]constructor['"`]\s*\]/,
55
+ ],
56
+ maxComplexity: options.maxComplexity || 50,
57
+ maxNesting: options.maxNesting || 10,
58
+ forbiddenGlobals: options.forbiddenGlobals || [
59
+ 'process',
60
+ 'require',
61
+ '__dirname',
62
+ '__filename',
63
+ ],
64
+ };
65
+ }
66
+
67
+ async validate(code: string, ast: t.File, phase: 'pre' | 'post'): Promise<void> {
68
+ // Only validate before transformation
69
+ if (phase === 'post') {
70
+ return;
71
+ }
72
+
73
+ // 1. Check forbidden patterns
74
+ for (const pattern of this.options.forbiddenPatterns!) {
75
+ if (pattern.test(code)) {
76
+ throw new SecurityValidationError(
77
+ `Forbidden pattern detected: ${pattern}`,
78
+ 'forbidden-pattern'
79
+ );
80
+ }
81
+ }
82
+
83
+ // 2. Check complexity and nesting
84
+ let maxNestingFound = 0;
85
+ let complexityScore = 0;
86
+
87
+ traverse(ast, {
88
+ enter(path: any) {
89
+ const depth = path.scope.path.node ? getDepth(path) : 0;
90
+ maxNestingFound = Math.max(maxNestingFound, depth);
91
+
92
+ // Increment complexity for control flow
93
+ if (
94
+ path.isIfStatement() ||
95
+ path.isWhileStatement() ||
96
+ path.isForStatement() ||
97
+ path.isForOfStatement() ||
98
+ path.isSwitchCase() ||
99
+ path.isCatchClause()
100
+ ) {
101
+ complexityScore++;
102
+ }
103
+ },
104
+
105
+ // 3. Check forbidden globals
106
+ Identifier: (path: any) => {
107
+ if (
108
+ this.options.forbiddenGlobals!.includes(path.node.name) &&
109
+ !path.scope.hasBinding(path.node.name)
110
+ ) {
111
+ throw new SecurityValidationError(
112
+ `Access to forbidden global: ${path.node.name}`,
113
+ 'forbidden-global'
114
+ );
115
+ }
116
+ },
117
+ });
118
+
119
+ if (maxNestingFound > this.options.maxNesting!) {
120
+ throw new SecurityValidationError(
121
+ `Maximum nesting depth exceeded: ${maxNestingFound} > ${this.options.maxNesting}`,
122
+ 'max-nesting'
123
+ );
124
+ }
125
+
126
+ if (complexityScore > this.options.maxComplexity!) {
127
+ throw new SecurityValidationError(
128
+ `Maximum complexity exceeded: ${complexityScore} > ${this.options.maxComplexity}`,
129
+ 'max-complexity'
130
+ );
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Security validation error
137
+ */
138
+ export class SecurityValidationError extends Error {
139
+ constructor(
140
+ message: string,
141
+ public code: string
142
+ ) {
143
+ super(message);
144
+ this.name = 'SecurityValidationError';
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Get nesting depth of a path
150
+ */
151
+ function getDepth(path: any): number {
152
+ let depth = 0;
153
+ let current = path;
154
+
155
+ while (current.parentPath) {
156
+ if (
157
+ current.isBlockStatement() ||
158
+ current.isFunctionDeclaration() ||
159
+ current.isArrowFunctionExpression()
160
+ ) {
161
+ depth++;
162
+ }
163
+ current = current.parentPath;
164
+ }
165
+
166
+ return depth;
167
+ }
168
+