From 924e2c1875cf3ed19187a2277c454271b9ad86a6 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Wed, 16 Feb 2022 16:29:31 +0100 Subject: [PATCH] Add doc strings Basically conclusions from a discussion in facebook/jest#12403 --- packages/jest-transform/src/types.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/jest-transform/src/types.ts b/packages/jest-transform/src/types.ts index 596f1f1de4fd..ccc27e488e1b 100644 --- a/packages/jest-transform/src/types.ts +++ b/packages/jest-transform/src/types.ts @@ -136,6 +136,12 @@ export interface AsyncTransformer { ) => Promise; } +/** + * We have both sync (process) and async (processAsync) code transformation, which both can be provided. + * `require` will always use process, and import will use `processAsync` if it exists, otherwise fall back to process. + * Meaning, if you use import exclusively you do not need process, but in most cases supplying both makes sense: + * Jest transpiles on demand rather than ahead of time, so the sync one needs to exist. + */ export type Transformer = | SyncTransformer | AsyncTransformer; @@ -144,4 +150,9 @@ type TransformerCreator = ( options?: OptionType, ) => Transformer; +/** + * Instead of having your custom transformer implement the Transformer interface + * directly, you can choose to export a factory function to dynamically create + * transformers. This is to allow having a transformer config in your jest config. + */ export type TransformerFactory = {createTransformer: TransformerCreator};