@@ -10,23 +10,34 @@ export default async function transform(this: LoaderContext<any>, source: string
1010 return callback ( null , source , map )
1111
1212 const context = createContext ( this )
13- const res = await plugin . transform . call (
14- Object . assign ( { } , createBuildContext ( {
15- addWatchFile : ( file ) => {
16- this . addDependency ( file )
17- } ,
18- getWatchFiles : ( ) => {
19- return this . getDependencies ( )
20- } ,
21- } , this . _compiler ! , this . _compilation , this ) , context ) ,
22- source ,
23- this . resource ,
24- )
2513
26- if ( res == null )
27- callback ( null , source , map )
28- else if ( typeof res !== 'string' )
29- callback ( null , res . code , map == null ? map : ( res . map || map ) )
30- else
31- callback ( null , res , map )
14+ try {
15+ const res = await plugin . transform . call (
16+ Object . assign ( { } , createBuildContext ( {
17+ addWatchFile : ( file ) => {
18+ this . addDependency ( file )
19+ } ,
20+ getWatchFiles : ( ) => {
21+ return this . getDependencies ( )
22+ } ,
23+ } , this . _compiler ! , this . _compilation , this ) , context ) ,
24+ source ,
25+ this . resource ,
26+ )
27+
28+ if ( res == null )
29+ callback ( null , source , map )
30+ else if ( typeof res !== 'string' )
31+ callback ( null , res . code , map == null ? map : ( res . map || map ) )
32+ else
33+ callback ( null , res , map )
34+ }
35+ catch ( error ) {
36+ if ( error instanceof Error ) {
37+ callback ( error )
38+ }
39+ else {
40+ callback ( new Error ( String ( error ) ) )
41+ }
42+ }
3243}
0 commit comments