@@ -37,28 +37,28 @@ export function transformSync(
3737 } ) ;
3838
3939 const hash = sha1 ( code + JSON . stringify ( esbuildOptions ) + esbuildVersion ) ;
40- const cacheHit = cache . get ( hash ) ;
40+ let transformed = cache . get ( hash ) ;
4141
42- if ( cacheHit ) {
43- return cacheHit ;
44- }
45-
46- const transformed = applyTransformersSync (
47- filePath ,
48- code ,
49- [
50- // eslint-disable-next-line @typescript-eslint/no-shadow
51- ( filePath , code ) => {
42+ if ( ! transformed ) {
43+ transformed = applyTransformersSync (
44+ filePath ,
45+ code ,
46+ [
5247 // eslint-disable-next-line @typescript-eslint/no-shadow
53- const transformed = esbuildTransformSync ( code , esbuildOptions ) ;
54- if ( esbuildOptions . sourcefile !== filePath ) {
55- transformed . map = transformed . map . replace ( `"${ esbuildOptions . sourcefile } "` , `"${ filePath } "` ) ;
56- }
57- return transformed ;
58- } ,
59- transformDynamicImport ,
60- ] as const ,
61- ) ;
48+ ( filePath , code ) => {
49+ // eslint-disable-next-line @typescript-eslint/no-shadow
50+ const transformed = esbuildTransformSync ( code , esbuildOptions ) ;
51+ if ( esbuildOptions . sourcefile !== filePath ) {
52+ transformed . map = transformed . map . replace ( `"${ esbuildOptions . sourcefile } "` , `"${ filePath } "` ) ;
53+ }
54+ return transformed ;
55+ } ,
56+ transformDynamicImport ,
57+ ] as const ,
58+ ) ;
59+
60+ cache . set ( hash , transformed ) ;
61+ }
6262
6363 if ( transformed . warnings . length > 0 ) {
6464 const { warnings } = transformed ;
@@ -67,8 +67,6 @@ export function transformSync(
6767 }
6868 }
6969
70- cache . set ( hash , transformed ) ;
71-
7270 return transformed ;
7371}
7472
@@ -85,27 +83,28 @@ export async function transform(
8583 } ) ;
8684
8785 const hash = sha1 ( code + JSON . stringify ( esbuildOptions ) + esbuildVersion ) ;
88- const cacheHit = cache . get ( hash ) ;
89- if ( cacheHit ) {
90- return cacheHit ;
91- }
86+ let transformed = cache . get ( hash ) ;
9287
93- const transformed = await applyTransformers (
94- filePath ,
95- code ,
96- [
97- // eslint-disable-next-line @typescript-eslint/no-shadow
98- async ( filePath , code ) => {
88+ if ( ! transformed ) {
89+ transformed = await applyTransformers (
90+ filePath ,
91+ code ,
92+ [
9993 // eslint-disable-next-line @typescript-eslint/no-shadow
100- const transformed = await esbuildTransform ( code , esbuildOptions ) ;
101- if ( esbuildOptions . sourcefile !== filePath ) {
102- transformed . map = transformed . map . replace ( `"${ esbuildOptions . sourcefile } "` , `"${ filePath } "` ) ;
103- }
104- return transformed ;
105- } ,
106- transformDynamicImport ,
107- ] as const ,
108- ) ;
94+ async ( filePath , code ) => {
95+ // eslint-disable-next-line @typescript-eslint/no-shadow
96+ const transformed = await esbuildTransform ( code , esbuildOptions ) ;
97+ if ( esbuildOptions . sourcefile !== filePath ) {
98+ transformed . map = transformed . map . replace ( `"${ esbuildOptions . sourcefile } "` , `"${ filePath } "` ) ;
99+ }
100+ return transformed ;
101+ } ,
102+ transformDynamicImport ,
103+ ] as const ,
104+ ) ;
105+
106+ cache . set ( hash , transformed ) ;
107+ }
109108
110109 if ( transformed . warnings . length > 0 ) {
111110 const { warnings } = transformed ;
@@ -114,7 +113,5 @@ export async function transform(
114113 }
115114 }
116115
117- cache . set ( hash , transformed ) ;
118-
119116 return transformed ;
120117}
0 commit comments