From 2ad20d2e6b6aed06a6a4c16de9ae2f7725853395 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 12 Sep 2014 13:19:26 -0700 Subject: [PATCH] Fix declaring function for writer and setting writer to undefined --- src/services/services.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index cc45e861946..f3e309615ae 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2830,8 +2830,7 @@ module ts { } function containErrors(diagnostics: Diagnostic[]): boolean { - var hasError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); - return hasError; + return forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); } function getEmitOutput(filename: string): EmitOutput { @@ -2846,15 +2845,17 @@ module ts { emitOutputStatus: undefined, }; - // Initialize writer for CompilerHost.writeFile - writer = function (fileName: string, data: string, writeByteOrderMark: boolean) { + function getEmitOutputWriter(filename: string, data: string, writeByteOrderMark: boolean) { emitOutput.outputFiles.push({ - name: fileName, + name: filename, writeByteOrderMark: writeByteOrderMark, text: data }); } + // Initialize writer for CompilerHost.writeFile + writer = getEmitOutputWriter; + var syntacticDiagnostics: Diagnostic[] = []; if (emitToSingleFile) { // Check only the file we want to emit @@ -2873,6 +2874,8 @@ module ts { // If there is any syntactic error, terminate the process if (containErrors(syntacticDiagnostics)) { emitOutput.emitOutputStatus = EmitReturnStatus.AllOutputGenerationSkipped; + // Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput + writer = undefined; return emitOutput; } @@ -2890,7 +2893,7 @@ module ts { emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus; // Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput - this.writer = undefined; + writer = undefined; return emitOutput; }