@@ -21,7 +21,7 @@ import { decodedSourcemap } from './decodedSourcemap';
21
21
import { augmentCodeLocation , errNoTransformMapOrAstWithoutCode } from './error' ;
22
22
import { throwPluginError } from './pluginUtils' ;
23
23
24
- export default function transform (
24
+ export default async function transform (
25
25
source : SourceDescription ,
26
26
module : Module ,
27
27
pluginDriver : PluginDriver ,
@@ -37,7 +37,7 @@ export default function transform(
37
37
const emittedFiles : EmittedFile [ ] = [ ] ;
38
38
let customTransformCache = false ;
39
39
const useCustomTransformCache = ( ) => ( customTransformCache = true ) ;
40
- let curPlugin : Plugin ;
40
+ let pluginName = '' ;
41
41
const curSource : string = source . code ;
42
42
43
43
function transformReducer (
@@ -77,13 +77,15 @@ export default function transform(
77
77
return code ;
78
78
}
79
79
80
- return pluginDriver
81
- . hookReduceArg0 (
80
+ let code : string ;
81
+
82
+ try {
83
+ code = await pluginDriver . hookReduceArg0 (
82
84
'transform' ,
83
85
[ curSource , id ] ,
84
86
transformReducer ,
85
87
( pluginContext , plugin ) : TransformPluginContext => {
86
- curPlugin = plugin ;
88
+ pluginName = plugin . name ;
87
89
return {
88
90
...pluginContext ,
89
91
addWatchFile ( id : string ) {
@@ -149,23 +151,24 @@ export default function transform(
149
151
}
150
152
} ;
151
153
}
152
- )
153
- . catch ( err => throwPluginError ( err , curPlugin . name , { hook : 'transform' , id } ) )
154
- . then ( code => {
155
- if ( ! customTransformCache ) {
156
- // files emitted by a transform hook need to be emitted again if the hook is skipped
157
- if ( emittedFiles . length ) module . transformFiles = emittedFiles ;
158
- }
154
+ ) ;
155
+ } catch ( err : any ) {
156
+ throwPluginError ( err , pluginName , { hook : 'transform' , id } ) ;
157
+ }
158
+
159
+ if ( ! customTransformCache ) {
160
+ // files emitted by a transform hook need to be emitted again if the hook is skipped
161
+ if ( emittedFiles . length ) module . transformFiles = emittedFiles ;
162
+ }
159
163
160
- return {
161
- ast,
162
- code,
163
- customTransformCache,
164
- meta : module . info . meta ,
165
- originalCode,
166
- originalSourcemap,
167
- sourcemapChain,
168
- transformDependencies
169
- } ;
170
- } ) ;
164
+ return {
165
+ ast,
166
+ code,
167
+ customTransformCache,
168
+ meta : module . info . meta ,
169
+ originalCode,
170
+ originalSourcemap,
171
+ sourcemapChain,
172
+ transformDependencies
173
+ } ;
171
174
}
0 commit comments