diff --git a/build/lib/compilation.js b/build/lib/compilation.js index 8407c7102f2..be9839af024 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -104,14 +104,19 @@ function compileTask(src, out, build) { // mangle: TypeScript to TypeScript let mangleStream = es.through(); if (build) { - const ts2tsMangler = new mangleTypeScript_1.Mangler(compile.projectPath); - const replacer = ts2tsMangler.computeNewFileContents(); - mangleStream = es.through(function (data) { - const newContents = replacer.get(data.path); + let ts2tsMangler = new mangleTypeScript_1.Mangler(compile.projectPath); + const newContentsByFileName = ts2tsMangler.computeNewFileContents(); + mangleStream = es.through(function write(data) { + const newContents = newContentsByFileName.get(data.path); if (newContents !== undefined) { data.contents = Buffer.from(newContents); } this.push(data); + }, function end() { + this.push(null); + // free resources + newContentsByFileName.clear(); + ts2tsMangler = undefined; }); } return srcPipe diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index b1fb5879427..2cc04d2c977 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -123,14 +123,19 @@ export function compileTask(src: string, out: string, build: boolean): () => Nod // mangle: TypeScript to TypeScript let mangleStream = es.through(); if (build) { - const ts2tsMangler = new Mangler(compile.projectPath); - const replacer = ts2tsMangler.computeNewFileContents(); - mangleStream = es.through(function (data: File) { - const newContents = replacer.get(data.path); + let ts2tsMangler = new Mangler(compile.projectPath); + const newContentsByFileName = ts2tsMangler.computeNewFileContents(); + mangleStream = es.through(function write(data: File) { + const newContents = newContentsByFileName.get(data.path); if (newContents !== undefined) { data.contents = Buffer.from(newContents); } this.push(data); + }, function end() { + this.push(null); + // free resources + newContentsByFileName.clear(); + (ts2tsMangler) = undefined; }); } diff --git a/build/lib/mangleTypeScript.ts b/build/lib/mangleTypeScript.ts index d767cbd4793..ab5198a2924 100644 --- a/build/lib/mangleTypeScript.ts +++ b/build/lib/mangleTypeScript.ts @@ -350,7 +350,7 @@ export class Mangler { this.service = ts.createLanguageService(new StaticLanguageServiceHost(projectPath)); } - computeNewFileContents(): ReadonlyMap { + computeNewFileContents(): Map { // STEP: find all classes and their field info