Skip to content

Commit 94723a9

Browse files
author
Yui T
committed
Remove concatenation of syntacticErrors instead return immediately if encountering any error
1 parent 13cf339 commit 94723a9

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/services/services.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,16 +1409,18 @@ module ts {
14091409
getCanonicalFileName: (filename) => useCaseSensitivefilenames ? filename : filename.toLowerCase(),
14101410
useCaseSensitiveFileNames: () => useCaseSensitivefilenames,
14111411
getNewLine: () => "\r\n",
1412-
// Need something that doesn't depend on sys.ts here
14131412
getDefaultLibFilename: (): string => {
1414-
return "";
1413+
// In the case there is no host (such as in fourslash test), return ""
1414+
return this.host !== undefined ? this.host.getDefaultLibFilename() : "";
14151415
},
14161416
writeFile: (filename, data, writeByteOrderMark) => {
1417-
writer(filename, data, writeByteOrderMark);
1417+
if (writer !== undefined) {
1418+
writer(filename, data, writeByteOrderMark);
1419+
}
14181420
},
14191421
getCurrentDirectory: (): string => {
1420-
// Return empty string as in compilerHost using with Visual Studio should not need to getCurrentDirectory since CompilerHost should have absolute path already
1421-
return "";
1422+
// In the case there is no host (such as in fourslash test), return ""
1423+
return this.host !== undefined ? this.host.getCurrentDirectory() : "";
14221424
}
14231425
};
14241426
}
@@ -2856,40 +2858,36 @@ module ts {
28562858
// Initialize writer for CompilerHost.writeFile
28572859
writer = getEmitOutputWriter;
28582860

2859-
var syntacticDiagnostics: Diagnostic[] = [];
2861+
var syntacticDiagnostics: Diagnostic[] = [];
2862+
var containSyntacticErrors = false;
2863+
28602864
if (emitToSingleFile) {
28612865
// Check only the file we want to emit
2862-
syntacticDiagnostics = program.getDiagnostics(targetSourceFile);
2863-
}
2864-
else {
2865-
// Only check the syntactic of only sourceFiles that will get emitted into single output
2866-
forEach(program.getSourceFiles(), sourceFile => {
2867-
// Emit to a single file then we will check all files that do not have external module
2866+
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
2867+
} else {
2868+
// Check the syntactic of only sourceFiles that will get emitted into single output
2869+
// Terminate the process immediately if we encounter a syntax error from one of the sourceFiles
2870+
containSyntacticErrors = program.getSourceFiles().some((sourceFile) => {
28682871
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
2869-
syntacticDiagnostics = syntacticDiagnostics.concat(program.getDiagnostics(sourceFile));
2872+
// If emit to a single file then we will check all files that do not have external module
2873+
return containErrors(program.getDiagnostics(sourceFile));
28702874
}
28712875
});
28722876
}
28732877

2874-
// If there is any syntactic error, terminate the process
2875-
if (containErrors(syntacticDiagnostics)) {
2878+
if (containSyntacticErrors) {
2879+
// If there is a syntax error, terminate the process and report outputStatus
28762880
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
2881+
// Reset writer back to undefined to make sure that we produce an error message
2882+
// if CompilerHost.writeFile is called when we are not in getEmitOutput
28782883
writer = undefined;
28792884
return emitOutput;
28802885
}
28812886

28822887
// Perform semantic and force a type check before emit to ensure that all symbols are updated
28832888
// EmitFiles will report if there is an error from TypeChecker and Emitter
2884-
if (emitToSingleFile) {
2885-
// Emit only selected file in the project
2886-
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
2887-
}
2888-
else {
2889-
// Emit all files into single file
2890-
var emitFilesResult = getFullTypeCheckChecker().emitFiles();
2891-
}
2892-
2889+
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
2890+
var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles();
28932891
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
28942892

28952893
// 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

0 commit comments

Comments
 (0)