Skip to content

Commit aeb79e4

Browse files
committed
free memory when TS2TS mangling is done
1 parent 85c28e5 commit aeb79e4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

build/lib/compilation.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ function compileTask(src, out, build) {
104104
// mangle: TypeScript to TypeScript
105105
let mangleStream = es.through();
106106
if (build) {
107-
const ts2tsMangler = new mangleTypeScript_1.Mangler(compile.projectPath);
108-
const replacer = ts2tsMangler.computeNewFileContents();
109-
mangleStream = es.through(function (data) {
110-
const newContents = replacer.get(data.path);
107+
let ts2tsMangler = new mangleTypeScript_1.Mangler(compile.projectPath);
108+
const newContentsByFileName = ts2tsMangler.computeNewFileContents();
109+
mangleStream = es.through(function write(data) {
110+
const newContents = newContentsByFileName.get(data.path);
111111
if (newContents !== undefined) {
112112
data.contents = Buffer.from(newContents);
113113
}
114114
this.push(data);
115+
}, function end() {
116+
this.push(null);
117+
// free resources
118+
newContentsByFileName.clear();
119+
ts2tsMangler = undefined;
115120
});
116121
}
117122
return srcPipe

build/lib/compilation.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,19 @@ export function compileTask(src: string, out: string, build: boolean): () => Nod
123123
// mangle: TypeScript to TypeScript
124124
let mangleStream = es.through();
125125
if (build) {
126-
const ts2tsMangler = new Mangler(compile.projectPath);
127-
const replacer = ts2tsMangler.computeNewFileContents();
128-
mangleStream = es.through(function (data: File) {
129-
const newContents = replacer.get(data.path);
126+
let ts2tsMangler = new Mangler(compile.projectPath);
127+
const newContentsByFileName = ts2tsMangler.computeNewFileContents();
128+
mangleStream = es.through(function write(data: File) {
129+
const newContents = newContentsByFileName.get(data.path);
130130
if (newContents !== undefined) {
131131
data.contents = Buffer.from(newContents);
132132
}
133133
this.push(data);
134+
}, function end() {
135+
this.push(null);
136+
// free resources
137+
newContentsByFileName.clear();
138+
(<any>ts2tsMangler) = undefined;
134139
});
135140
}
136141

build/lib/mangleTypeScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class Mangler {
350350
this.service = ts.createLanguageService(new StaticLanguageServiceHost(projectPath));
351351
}
352352

353-
computeNewFileContents(): ReadonlyMap<string, string> {
353+
computeNewFileContents(): Map<string, string> {
354354

355355
// STEP: find all classes and their field info
356356

0 commit comments

Comments
 (0)