0
# Transform Types
1
2
Types for Jest's code transformation system enabling custom transformers and build tool integration. These types are designed to avoid huge dependency trees while providing the necessary interfaces for code transformation.
3
4
## Capabilities
5
6
### Transform Result Interface
7
8
Core interface for the result of code transformation operations.
9
10
```typescript { .api }
11
/**
12
* Result of code transformation
13
* Designed to avoid huge dependency trees for transformation processing
14
*/
15
interface TransformResult {
16
/** Transformed code output */
17
code: string;
18
19
/** Original source code before transformation */
20
originalCode: string;
21
22
/** Path to source map file, or null if no source map */
23
sourceMapPath: string | null;
24
}
25
```
26
27
**Usage Examples:**
28
29
```typescript
30
import type { TransformTypes } from "@jest/types";
31
32
// Custom transformer function signature
33
type CustomTransformer = (
34
source: string,
35
filename: string,
36
options?: any
37
) => TransformTypes.TransformResult;
38
39
// Example transformer implementation
40
const myTransformer: CustomTransformer = (source, filename, options) => {
41
// Perform transformation logic
42
const transformedCode = transformSource(source, options);
43
44
return {
45
code: transformedCode,
46
originalCode: source,
47
sourceMapPath: `${filename}.map`,
48
};
49
};
50
51
// Process transform result
52
const processTransformResult = (result: TransformTypes.TransformResult) => {
53
console.log('Transformed code length:', result.code.length);
54
console.log('Original code length:', result.originalCode.length);
55
56
if (result.sourceMapPath) {
57
console.log('Source map available at:', result.sourceMapPath);
58
}
59
};
60
61
// Check if transformation changed the code
62
const isCodeTransformed = (result: TransformTypes.TransformResult): boolean => {
63
return result.code !== result.originalCode;
64
};
65
```