pull/203536/head
Johannes 2024-01-26 16:39:19 +01:00
parent a6f9e08a42
commit b7d1c336ee
No known key found for this signature in database
GPG Key ID: 6DEF802A22264FCA
1 changed files with 8 additions and 7 deletions

View File

@ -346,19 +346,18 @@ class Mangler {
config;
allClassDataByKey = new Map();
allExportedSymbols = new Set();
service;
renameWorkerPool;
constructor(projectPath, log = () => { }, config) {
this.projectPath = projectPath;
this.log = log;
this.config = config;
this.service = ts.createLanguageService(new staticLanguageServiceHost_1.StaticLanguageServiceHost(projectPath));
this.renameWorkerPool = workerpool.pool(path.join(__dirname, 'renameWorker.js'), {
maxWorkers: 1,
minWorkers: 'max'
});
}
async computeNewFileContents(strictImplicitPublicHandling) {
const service = ts.createLanguageService(new staticLanguageServiceHost_1.StaticLanguageServiceHost(this.projectPath));
// STEP:
// - Find all classes and their field info.
// - Find exported symbols.
@ -405,12 +404,12 @@ class Mangler {
if (isInAmbientContext(node)) {
return;
}
this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, this.service, fileIdents));
this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, service, fileIdents));
}
}
ts.forEachChild(node, visit);
};
for (const file of this.service.getProgram().getSourceFiles()) {
for (const file of service.getProgram().getSourceFiles()) {
if (!file.isDeclarationFile) {
ts.forEachChild(file, visit);
}
@ -423,7 +422,7 @@ class Mangler {
// no EXTENDS-clause
return;
}
const info = this.service.getDefinitionAtPosition(data.fileName, extendsClause.types[0].expression.getEnd());
const info = service.getDefinitionAtPosition(data.fileName, extendsClause.types[0].expression.getEnd());
if (!info || info.length === 0) {
// throw new Error('SUPER type not found');
return;
@ -545,8 +544,8 @@ class Mangler {
// STEP: apply all rename edits (per file)
const result = new Map();
let savedBytes = 0;
for (const item of this.service.getProgram().getSourceFiles()) {
const { mapRoot, sourceRoot } = this.service.getProgram().getCompilerOptions();
for (const item of service.getProgram().getSourceFiles()) {
const { mapRoot, sourceRoot } = service.getProgram().getCompilerOptions();
const projectDir = path.dirname(this.projectPath);
const sourceMapRoot = mapRoot ?? (0, url_1.pathToFileURL)(sourceRoot ?? projectDir).toString();
// source maps
@ -614,6 +613,8 @@ class Mangler {
}
result.set(item.fileName, { out: newFullText, sourceMap: generator?.toString() });
}
service.dispose();
this.renameWorkerPool.terminate();
this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(process.memoryUsage())}`);
return result;
}