@@ -29,6 +29,8 @@ import type {
2929 TransformResult ,
3030 TransformedSource ,
3131 Transformer ,
32+ SyncTransformer ,
33+ AsyncTransformer
3234} from './types' ;
3335import shouldInstrument from './shouldInstrument' ;
3436import handlePotentialSyntaxError from './enhanceUnexpectedTokenMessage' ;
@@ -114,7 +116,7 @@ export default class ScriptTransformer {
114116 }
115117
116118 private _getCacheKey (
117- fileData : string ,
119+ content : string ,
118120 filename : Config . Path ,
119121 instrument : boolean ,
120122 supportsDynamicImport : boolean ,
@@ -126,7 +128,7 @@ export default class ScriptTransformer {
126128
127129 if ( transformer && typeof transformer . getCacheKey === 'function' ) {
128130 transformerCacheKey = transformer . getCacheKey (
129- fileData ,
131+ content ,
130132 filename ,
131133 configString ,
132134 {
@@ -139,7 +141,7 @@ export default class ScriptTransformer {
139141 ) ;
140142 }
141143 return this . _buildCacheKeyFromFileInfo (
142- fileData ,
144+ content ,
143145 filename ,
144146 instrument ,
145147 configString ,
@@ -148,7 +150,7 @@ export default class ScriptTransformer {
148150 }
149151
150152 private async _getCacheKeyAsync (
151- fileData : string ,
153+ content : string ,
152154 filename : Config . Path ,
153155 instrument : boolean ,
154156 supportsDynamicImport : boolean ,
@@ -160,7 +162,7 @@ export default class ScriptTransformer {
160162
161163 if ( transformer && typeof transformer . getCacheKeyAsync === 'function' ) {
162164 transformerCacheKey = await transformer . getCacheKeyAsync (
163- fileData ,
165+ content ,
164166 filename ,
165167 configString ,
166168 {
@@ -173,7 +175,7 @@ export default class ScriptTransformer {
173175 ) ;
174176 }
175177 return this . _buildCacheKeyFromFileInfo (
176- fileData ,
178+ content ,
177179 filename ,
178180 instrument ,
179181 configString ,
@@ -259,7 +261,7 @@ export default class ScriptTransformer {
259261 }
260262
261263 private async _getTransformerAsync ( filename : Config . Path ) {
262- let transform : Transformer | null = null ;
264+ let transform : AsyncTransformer | null = null ;
263265 if ( ! this . _config . transform || ! this . _config . transform . length ) {
264266 return null ;
265267 }
@@ -294,7 +296,7 @@ export default class ScriptTransformer {
294296 }
295297
296298 private _getTransformer ( filename : Config . Path ) {
297- let transform : Transformer | null = null ;
299+ let transform : SyncTransformer | null = null ;
298300 if ( ! this . _config . transform || ! this . _config . transform . length ) {
299301 return null ;
300302 }
@@ -592,17 +594,20 @@ export default class ScriptTransformer {
592594 let processed : TransformedSource | null = null ;
593595
594596 if ( transform && shouldCallTransform ) {
595- processed = transform . processAsync
596- ? await transform . processAsync ( content , filename , this . _config , {
597+
598+ if ( transform . processAsync ) {
599+ processed = await transform . processAsync ( content , filename , this . _config , {
597600 instrument,
598601 supportsDynamicImport,
599602 supportsStaticESM,
600603 } )
601- : transform . process ( content , filename , this . _config , {
602- instrument,
603- supportsDynamicImport,
604- supportsStaticESM,
605- } ) ;
604+ } else if ( transform . process ) {
605+ processed = transform . process ( content , filename , this . _config , {
606+ instrument,
607+ supportsDynamicImport,
608+ supportsStaticESM,
609+ } ) ;
610+ }
606611
607612 if (
608613 processed == null ||
0 commit comments