Skip to content

Commit 2ad20d2

Browse files
author
Yui T
committed
Fix declaring function for writer and setting writer to undefined
1 parent 0b06ddc commit 2ad20d2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/services/services.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,8 +2830,7 @@ module ts {
28302830
}
28312831

28322832
function containErrors(diagnostics: Diagnostic[]): boolean {
2833-
var hasError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
2834-
return hasError;
2833+
return forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
28352834
}
28362835

28372836
function getEmitOutput(filename: string): EmitOutput {
@@ -2846,15 +2845,17 @@ module ts {
28462845
emitOutputStatus: undefined,
28472846
};
28482847

2849-
// Initialize writer for CompilerHost.writeFile
2850-
writer = function (fileName: string, data: string, writeByteOrderMark: boolean) {
2848+
function getEmitOutputWriter(filename: string, data: string, writeByteOrderMark: boolean) {
28512849
emitOutput.outputFiles.push({
2852-
name: fileName,
2850+
name: filename,
28532851
writeByteOrderMark: writeByteOrderMark,
28542852
text: data
28552853
});
28562854
}
28572855

2856+
// Initialize writer for CompilerHost.writeFile
2857+
writer = getEmitOutputWriter;
2858+
28582859
var syntacticDiagnostics: Diagnostic[] = [];
28592860
if (emitToSingleFile) {
28602861
// Check only the file we want to emit
@@ -2873,6 +2874,8 @@ module ts {
28732874
// If there is any syntactic error, terminate the process
28742875
if (containErrors(syntacticDiagnostics)) {
28752876
emitOutput.emitOutputStatus = EmitReturnStatus.AllOutputGenerationSkipped;
2877+
// 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
2878+
writer = undefined;
28762879
return emitOutput;
28772880
}
28782881

@@ -2890,7 +2893,7 @@ module ts {
28902893
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
28912894

28922895
// 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
2893-
this.writer = undefined;
2896+
writer = undefined;
28942897
return emitOutput;
28952898
}
28962899

0 commit comments

Comments
 (0)