|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
| 6 | +import * as v8 from 'node:v8'; |
6 | 7 | import * as fs from 'fs'; |
7 | 8 | import * as path from 'path'; |
8 | 9 | import { argv } from 'process'; |
@@ -338,17 +339,16 @@ class DeclarationData { |
338 | 339 | constructor( |
339 | 340 | readonly fileName: string, |
340 | 341 | readonly node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.EnumDeclaration | ts.VariableDeclaration, |
341 | | - private readonly service: ts.LanguageService, |
342 | 342 | fileIdents: ShortIdent, |
343 | 343 | ) { |
344 | 344 | // Todo: generate replacement names based on usage count, with more used names getting shorter identifiers |
345 | 345 | this.replacementName = fileIdents.next(); |
346 | 346 | } |
347 | 347 |
|
348 | | - get locations(): Iterable<{ fileName: string; offset: number }> { |
| 348 | + getLocations(service: ts.LanguageService): Iterable<{ fileName: string; offset: number }> { |
349 | 349 | if (ts.isVariableDeclaration(this.node)) { |
350 | 350 | // If the const aliases any types, we need to rename those too |
351 | | - const definitionResult = this.service.getDefinitionAndBoundSpan(this.fileName, this.node.name.getStart()); |
| 351 | + const definitionResult = service.getDefinitionAndBoundSpan(this.fileName, this.node.name.getStart()); |
352 | 352 | if (definitionResult?.definitions && definitionResult.definitions.length > 1) { |
353 | 353 | return definitionResult.definitions.map(x => ({ fileName: x.fileName, offset: x.textSpan.start })); |
354 | 354 | } |
@@ -471,7 +471,7 @@ export class Mangler { |
471 | 471 | return; |
472 | 472 | } |
473 | 473 |
|
474 | | - this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, service, fileIdents)); |
| 474 | + this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, fileIdents)); |
475 | 475 | } |
476 | 476 | } |
477 | 477 |
|
@@ -620,7 +620,7 @@ export class Mangler { |
620 | 620 | } |
621 | 621 |
|
622 | 622 | const newText = data.replacementName; |
623 | | - for (const { fileName, offset } of data.locations) { |
| 623 | + for (const { fileName, offset } of data.getLocations(service)) { |
624 | 624 | queueRename(fileName, offset, newText); |
625 | 625 | } |
626 | 626 | } |
@@ -723,7 +723,8 @@ export class Mangler { |
723 | 723 |
|
724 | 724 | service.dispose(); |
725 | 725 | this.renameWorkerPool.terminate(); |
726 | | - this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(process.memoryUsage())}`); |
| 726 | + |
| 727 | + this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(v8.getHeapStatistics())}`); |
727 | 728 | return result; |
728 | 729 | } |
729 | 730 | } |
|
0 commit comments