Skip to content

Commit eb817de

Browse files
committed
Merge branch 'release-3.2' into cacheHostResults
2 parents 26bee2b + 6197b7b commit eb817de

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/compiler/tsbuild.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,6 @@ namespace ts {
10511051
return buildErrors(syntaxDiagnostics, BuildResultFlags.SyntaxErrors, "Syntactic");
10521052
}
10531053

1054-
// Don't emit .d.ts if there are decl file errors
1055-
if (getEmitDeclarations(program.getCompilerOptions())) {
1056-
const declDiagnostics = program.getDeclarationDiagnostics();
1057-
if (declDiagnostics.length) {
1058-
return buildErrors(declDiagnostics, BuildResultFlags.DeclarationEmitErrors, "Declaration file");
1059-
}
1060-
}
1061-
10621054
// Same as above but now for semantic diagnostics
10631055
const semanticDiagnostics = program.getSemanticDiagnostics();
10641056
if (semanticDiagnostics.length) {
@@ -1067,29 +1059,39 @@ namespace ts {
10671059

10681060
let newestDeclarationFileContentChangedTime = minimumDate;
10691061
let anyDtsChanged = false;
1070-
let emitDiagnostics: Diagnostic[] | undefined;
1071-
const reportEmitDiagnostic = (d: Diagnostic) => (emitDiagnostics || (emitDiagnostics = [])).push(d);
1072-
emitFilesAndReportErrors(program, reportEmitDiagnostic, writeFileName, /*reportSummary*/ undefined, (fileName, content, writeBom, onError) => {
1062+
let declDiagnostics: Diagnostic[] | undefined;
1063+
const reportDeclarationDiagnostics = (d: Diagnostic) => (declDiagnostics || (declDiagnostics = [])).push(d);
1064+
const outputFiles: OutputFile[] = [];
1065+
emitFilesAndReportErrors(program, reportDeclarationDiagnostics, writeFileName, /*reportSummary*/ undefined, (name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark }));
1066+
// Don't emit .d.ts if there are decl file errors
1067+
if (declDiagnostics) {
1068+
return buildErrors(declDiagnostics, BuildResultFlags.DeclarationEmitErrors, "Declaration file");
1069+
}
1070+
1071+
// Actual Emit
1072+
const emitterDiagnostics = createDiagnosticCollection();
1073+
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
10731074
let priorChangeTime: Date | undefined;
1074-
if (!anyDtsChanged && isDeclarationFile(fileName)) {
1075+
if (!anyDtsChanged && isDeclarationFile(name)) {
10751076
// Check for unchanged .d.ts files
1076-
if (host.fileExists(fileName) && readFileWithCache(fileName) === content) {
1077-
priorChangeTime = host.getModifiedTime(fileName);
1077+
if (host.fileExists(name) && readFileWithCache(name) === text) {
1078+
priorChangeTime = host.getModifiedTime(name);
10781079
}
10791080
else {
10801081
resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
10811082
anyDtsChanged = true;
10821083
}
10831084
}
10841085

1085-
host.writeFile(fileName, content, writeBom, onError, emptyArray);
1086+
writeFile(host, emitterDiagnostics, name, text, writeByteOrderMark);
10861087
if (priorChangeTime !== undefined) {
10871088
newestDeclarationFileContentChangedTime = newer(priorChangeTime, newestDeclarationFileContentChangedTime);
1088-
unchangedOutputs.setValue(fileName, priorChangeTime);
1089+
unchangedOutputs.setValue(name, priorChangeTime);
10891090
}
10901091
});
10911092

1092-
if (emitDiagnostics) {
1093+
const emitDiagnostics = emitterDiagnostics.getDiagnostics();
1094+
if (emitDiagnostics.length) {
10931095
return buildErrors(emitDiagnostics, BuildResultFlags.EmitErrors, "Emit");
10941096
}
10951097

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3402,7 +3402,7 @@ namespace ts {
34023402
return combinePaths(newDirPath, sourceFilePath);
34033403
}
34043404

3405-
export function writeFile(host: EmitHost, diagnostics: DiagnosticCollection, fileName: string, data: string, writeByteOrderMark: boolean, sourceFiles?: ReadonlyArray<SourceFile>) {
3405+
export function writeFile(host: { writeFile: WriteFileCallback; }, diagnostics: DiagnosticCollection, fileName: string, data: string, writeByteOrderMark: boolean, sourceFiles?: ReadonlyArray<SourceFile>) {
34063406
host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => {
34073407
diagnostics.add(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
34083408
}, sourceFiles);

0 commit comments

Comments
 (0)