@@ -323,11 +323,23 @@ export function createCompilerPlugin(
323
323
} ;
324
324
}
325
325
326
+ const data = typescriptResult . content ?? '' ;
327
+ const forceAsyncTransformation = / f o r \s + a w a i t \s * \( | a s y n c \s + f u n c t i o n \s * \* / . test ( data ) ;
326
328
const useInputSourcemap =
327
329
pluginOptions . sourcemap &&
328
330
( ! ! pluginOptions . thirdPartySourcemaps || ! / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / . test ( args . path ) ) ;
329
331
330
- const data = typescriptResult . content ?? '' ;
332
+ // If no additional transformations are needed, return the TypeScript output directly
333
+ if ( ! forceAsyncTransformation && ! pluginOptions . advancedOptimizations ) {
334
+ return {
335
+ // Strip sourcemaps if they should not be used
336
+ contents : useInputSourcemap
337
+ ? data
338
+ : data . replace ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm, '' ) ,
339
+ loader : 'js' ,
340
+ } ;
341
+ }
342
+
331
343
const babelResult = await transformAsync ( data , {
332
344
filename : args . path ,
333
345
inputSourceMap : ( useInputSourcemap ? undefined : false ) as undefined ,
@@ -341,7 +353,7 @@ export function createCompilerPlugin(
341
353
[
342
354
angularApplicationPreset ,
343
355
{
344
- forceAsyncTransformation : / f o r \s + a w a i t \s * \( | a s y n c \s + f u n c t i o n \s * \* / . test ( data ) ,
356
+ forceAsyncTransformation,
345
357
optimize : pluginOptions . advancedOptimizations && { } ,
346
358
} ,
347
359
] ,
@@ -356,6 +368,26 @@ export function createCompilerPlugin(
356
368
) ;
357
369
358
370
build . onLoad ( { filter : / \. [ c m ] ? j s $ / } , async ( args ) => {
371
+ const data = await fs . readFile ( args . path , 'utf-8' ) ;
372
+ const forceAsyncTransformation =
373
+ ! / [ \\ / ] [ _ f ] ? e s m 2 0 1 5 [ \\ / ] / . test ( args . path ) &&
374
+ / f o r \s + a w a i t \s * \( | a s y n c \s + f u n c t i o n \s * \* / . test ( data ) ;
375
+ const shouldLink = await requiresLinking ( args . path , data ) ;
376
+ const useInputSourcemap =
377
+ pluginOptions . sourcemap &&
378
+ ( ! ! pluginOptions . thirdPartySourcemaps || ! / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / . test ( args . path ) ) ;
379
+
380
+ // If no additional transformations are needed, return the TypeScript output directly
381
+ if ( ! forceAsyncTransformation && ! pluginOptions . advancedOptimizations && ! shouldLink ) {
382
+ return {
383
+ // Strip sourcemaps if they should not be used
384
+ contents : useInputSourcemap
385
+ ? data
386
+ : data . replace ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm, '' ) ,
387
+ loader : 'js' ,
388
+ } ;
389
+ }
390
+
359
391
const angularPackage = / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] @ a n g u l a r [ \\ / ] / . test ( args . path ) ;
360
392
361
393
const linkerPluginCreator = (
@@ -364,11 +396,6 @@ export function createCompilerPlugin(
364
396
)
365
397
) . createEs2015LinkerPlugin ;
366
398
367
- const useInputSourcemap =
368
- pluginOptions . sourcemap &&
369
- ( ! ! pluginOptions . thirdPartySourcemaps || ! / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / . test ( args . path ) ) ;
370
-
371
- const data = await fs . readFile ( args . path , 'utf-8' ) ;
372
399
const result = await transformAsync ( data , {
373
400
filename : args . path ,
374
401
inputSourceMap : ( useInputSourcemap ? undefined : false ) as undefined ,
@@ -383,13 +410,11 @@ export function createCompilerPlugin(
383
410
angularApplicationPreset ,
384
411
{
385
412
angularLinker : {
386
- shouldLink : await requiresLinking ( args . path , data ) ,
413
+ shouldLink,
387
414
jitMode : false ,
388
415
linkerPluginCreator,
389
416
} ,
390
- forceAsyncTransformation :
391
- ! / [ \\ / ] [ _ f ] ? e s m 2 0 1 5 [ \\ / ] / . test ( args . path ) &&
392
- / f o r \s + a w a i t \s * \( | a s y n c \s + f u n c t i o n \s * \* / . test ( data ) ,
417
+ forceAsyncTransformation,
393
418
optimize : pluginOptions . advancedOptimizations && {
394
419
looseEnums : angularPackage ,
395
420
pureTopLevel : angularPackage ,
0 commit comments