grrrrr
parent
a6f9e08a42
commit
b7d1c336ee
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue