@@ -67,7 +67,10 @@ export default class ScriptTransformer {
6767 private readonly _cache : ProjectCache ;
6868 private readonly _cacheFS : StringMap ;
6969 private readonly _config : Config . ProjectConfig ;
70- private readonly _transformCache : Map < Config . Path , Transformer > ;
70+ private readonly _transformCache : Map <
71+ Config . Path ,
72+ { transformer : Transformer ; transformerConfig : unknown }
73+ > ;
7174 private readonly _transformConfigCache : Map < Config . Path , unknown > ;
7275
7376 constructor (
@@ -102,7 +105,8 @@ export default class ScriptTransformer {
102105 options : ReducedTransformOptions ,
103106 ) : string {
104107 const configString = this . _cache . configString ;
105- const transformer = this . _getTransformer ( filename ) ;
108+ const { transformer, transformerConfig = { } } =
109+ this . _getTransformer ( filename ) || { } ;
106110
107111 if ( transformer && typeof transformer . getCacheKey === 'function' ) {
108112 return createHash ( 'md5' )
@@ -112,6 +116,7 @@ export default class ScriptTransformer {
112116 cacheFS : this . _cacheFS ,
113117 config : this . _config ,
114118 configString,
119+ transformerConfig,
115120 } ) ,
116121 )
117122 . update ( CACHE_VERSION )
@@ -181,28 +186,30 @@ export default class ScriptTransformer {
181186 return null ;
182187 }
183188
184- const transformer = this . _transformCache . get ( transformPath ) ;
185- if ( transformer ) {
186- return transformer ;
189+ const cached = this . _transformCache . get ( transformPath ) ;
190+ if ( cached ) {
191+ return cached ;
187192 }
188193
189- let transform : Transformer = require ( transformPath ) ;
194+ let transformer : Transformer = require ( transformPath ) ;
190195
191- if ( ! transform ) {
196+ if ( ! transformer ) {
192197 throw new TypeError ( 'Jest: a transform must export something.' ) ;
193198 }
194- const transformerConfig = this . _transformConfigCache . get ( transformPath ) ;
195- if ( typeof transform . createTransformer === 'function' ) {
196- transform = transform . createTransformer ( transformerConfig ) ;
199+ const transformerConfig =
200+ this . _transformConfigCache . get ( transformPath ) || { } ;
201+ if ( typeof transformer . createTransformer === 'function' ) {
202+ transformer = transformer . createTransformer ( transformerConfig ) ;
197203 }
198- if ( typeof transform . process !== 'function' ) {
204+ if ( typeof transformer . process !== 'function' ) {
199205 throw new TypeError (
200206 'Jest: a transform must export a `process` function.' ,
201207 ) ;
202208 }
203- this . _transformCache . set ( transformPath , transform ) ;
209+ const res = { transformer, transformerConfig} ;
210+ this . _transformCache . set ( transformPath , res ) ;
204211
205- return transform ;
212+ return res ;
206213 }
207214
208215 private _instrumentFile (
@@ -262,18 +269,19 @@ export default class ScriptTransformer {
262269 options : ReducedTransformOptions ,
263270 ) : TransformResult {
264271 const filename = tryRealpath ( filepath ) ;
265- const transform = this . _getTransformer ( filename ) ;
272+ const { transformer, transformerConfig = { } } =
273+ this . _getTransformer ( filename ) || { } ;
266274 const cacheFilePath = this . _getFileCachePath ( filename , content , options ) ;
267275 let sourceMapPath : Config . Path | null = cacheFilePath + '.map' ;
268276 // Ignore cache if `config.cache` is set (--no-cache)
269277 let code = this . _config . cache ? readCodeCacheFile ( cacheFilePath ) : null ;
270278
271- const shouldCallTransform = transform && this . shouldTransform ( filename ) ;
279+ const shouldCallTransform = transformer && this . shouldTransform ( filename ) ;
272280
273281 // That means that the transform has a custom instrumentation
274282 // logic and will handle it based on `config.collectCoverage` option
275283 const transformWillInstrument =
276- shouldCallTransform && transform && transform . canInstrument ;
284+ shouldCallTransform && transformer && transformer . canInstrument ;
277285
278286 if ( code ) {
279287 // This is broken: we return the code, and a path for the source map
@@ -292,12 +300,13 @@ export default class ScriptTransformer {
292300 map : null ,
293301 } ;
294302
295- if ( transform && shouldCallTransform ) {
296- const processed = transform . process ( content , filename , {
303+ if ( transformer && shouldCallTransform ) {
304+ const processed = transformer . process ( content , filename , {
297305 ...options ,
298306 cacheFS : this . _cacheFS ,
299307 config : this . _config ,
300308 configString : this . _cache . configString ,
309+ transformerConfig,
301310 } ) ;
302311
303312 if ( typeof processed === 'string' ) {
@@ -343,7 +352,7 @@ export default class ScriptTransformer {
343352 *
344353 */
345354 const shouldEmitSourceMaps =
346- ( transform != null && map != null ) || transform == null ;
355+ ( transformer != null && map != null ) || transformer == null ;
347356
348357 const instrumented = this . _instrumentFile (
349358 filename ,
0 commit comments