@@ -399,15 +399,13 @@ export class Mangler {
399
399
private readonly allClassDataByKey = new Map < string , ClassData > ( ) ;
400
400
private readonly allExportedSymbols = new Set < DeclarationData > ( ) ;
401
401
402
- private readonly service : ts . LanguageService ;
403
402
private readonly renameWorkerPool : workerpool . WorkerPool ;
404
403
405
404
constructor (
406
405
private readonly projectPath : string ,
407
406
private readonly log : typeof console . log = ( ) => { } ,
408
407
private readonly config : { readonly manglePrivateFields : boolean ; readonly mangleExports : boolean } ,
409
408
) {
410
- this . service = ts . createLanguageService ( new StaticLanguageServiceHost ( projectPath ) ) ;
411
409
412
410
this . renameWorkerPool = workerpool . pool ( path . join ( __dirname , 'renameWorker.js' ) , {
413
411
maxWorkers : 1 ,
@@ -417,6 +415,8 @@ export class Mangler {
417
415
418
416
async computeNewFileContents ( strictImplicitPublicHandling ?: Set < string > ) : Promise < Map < string , MangleOutput > > {
419
417
418
+ const service = ts . createLanguageService ( new StaticLanguageServiceHost ( this . projectPath ) ) ;
419
+
420
420
// STEP:
421
421
// - Find all classes and their field info.
422
422
// - Find exported symbols.
@@ -471,14 +471,14 @@ export class Mangler {
471
471
return ;
472
472
}
473
473
474
- this . allExportedSymbols . add ( new DeclarationData ( node . getSourceFile ( ) . fileName , node , this . service , fileIdents ) ) ;
474
+ this . allExportedSymbols . add ( new DeclarationData ( node . getSourceFile ( ) . fileName , node , service , fileIdents ) ) ;
475
475
}
476
476
}
477
477
478
478
ts . forEachChild ( node , visit ) ;
479
479
} ;
480
480
481
- for ( const file of this . service . getProgram ( ) ! . getSourceFiles ( ) ) {
481
+ for ( const file of service . getProgram ( ) ! . getSourceFiles ( ) ) {
482
482
if ( ! file . isDeclarationFile ) {
483
483
ts . forEachChild ( file , visit ) ;
484
484
}
@@ -495,7 +495,7 @@ export class Mangler {
495
495
return ;
496
496
}
497
497
498
- const info = this . service . getDefinitionAtPosition ( data . fileName , extendsClause . types [ 0 ] . expression . getEnd ( ) ) ;
498
+ const info = service . getDefinitionAtPosition ( data . fileName , extendsClause . types [ 0 ] . expression . getEnd ( ) ) ;
499
499
if ( ! info || info . length === 0 ) {
500
500
// throw new Error('SUPER type not found');
501
501
return ;
@@ -641,9 +641,9 @@ export class Mangler {
641
641
const result = new Map < string , MangleOutput > ( ) ;
642
642
let savedBytes = 0 ;
643
643
644
- for ( const item of this . service . getProgram ( ) ! . getSourceFiles ( ) ) {
644
+ for ( const item of service . getProgram ( ) ! . getSourceFiles ( ) ) {
645
645
646
- const { mapRoot, sourceRoot } = this . service . getProgram ( ) ! . getCompilerOptions ( ) ;
646
+ const { mapRoot, sourceRoot } = service . getProgram ( ) ! . getCompilerOptions ( ) ;
647
647
const projectDir = path . dirname ( this . projectPath ) ;
648
648
const sourceMapRoot = mapRoot ?? pathToFileURL ( sourceRoot ?? projectDir ) . toString ( ) ;
649
649
@@ -721,7 +721,9 @@ export class Mangler {
721
721
result . set ( item . fileName , { out : newFullText , sourceMap : generator ?. toString ( ) } ) ;
722
722
}
723
723
724
- this . log ( `Done: ${ savedBytes / 1000 } kb saved` ) ;
724
+ service . dispose ( ) ;
725
+ this . renameWorkerPool . terminate ( ) ;
726
+ this . log ( `Done: ${ savedBytes / 1000 } kb saved, memory-usage: ${ JSON . stringify ( process . memoryUsage ( ) ) } ` ) ;
725
727
return result ;
726
728
}
727
729
}
0 commit comments