Skip to content

Commit 9f9ae00

Browse files
committed
Enable getSemanticDiagnosticsOfNextAffectedFile for EmitAndSemanticDiagnosticsBuilder
1 parent e4fe4ac commit 9f9ae00

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

src/compiler/builder.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ namespace ts {
796796
(result as SemanticDiagnosticsBuilderProgram).getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile;
797797
}
798798
else if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
799+
(result as EmitAndSemanticDiagnosticsBuilderProgram).getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile;
799800
(result as EmitAndSemanticDiagnosticsBuilderProgram).emitNextAffectedFile = emitNextAffectedFile;
800801
}
801802
else {
@@ -913,6 +914,11 @@ namespace ts {
913914
);
914915
}
915916

917+
// Add file to affected file pending emit to handle for later emit time
918+
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
919+
addToAffectedFilesPendingEmit(state, [(affected as SourceFile).path]);
920+
}
921+
916922
// Get diagnostics for the affected file if its not ignored
917923
if (ignoreSourceFile && ignoreSourceFile(affected as SourceFile)) {
918924
// Get next affected file
@@ -951,18 +957,8 @@ namespace ts {
951957

952958
// When semantic builder asks for diagnostics of the whole program,
953959
// ensure that all the affected files are handled
954-
let affected: SourceFile | Program | undefined;
955-
let affectedFilesPendingEmit: Path[] | undefined;
956-
while (affected = getNextAffectedFile(state, cancellationToken, computeHash)) {
957-
if (affected !== state.program && kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
958-
(affectedFilesPendingEmit || (affectedFilesPendingEmit = [])).push((affected as SourceFile).path);
959-
}
960-
doneWithAffectedFile(state, affected);
961-
}
962-
963-
// In case of emit builder, cache the files to be emitted
964-
if (affectedFilesPendingEmit) {
965-
addToAffectedFilesPendingEmit(state, affectedFilesPendingEmit);
960+
// tslint:disable-next-line no-empty
961+
while (getSemanticDiagnosticsOfNextAffectedFile(cancellationToken)) {
966962
}
967963

968964
let diagnostics: Diagnostic[] | undefined;
@@ -1181,7 +1177,7 @@ namespace ts {
11811177
* The builder that can handle the changes in program and iterate through changed file to emit the files
11821178
* The semantic diagnostics are cached per file and managed by clearing for the changed/affected files
11831179
*/
1184-
export interface EmitAndSemanticDiagnosticsBuilderProgram extends BuilderProgram {
1180+
export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram {
11851181
/**
11861182
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
11871183
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host

src/harness/fakes.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,33 @@ namespace fakes {
388388
return ts.compareStringsCaseSensitive(ts.isString(a) ? a : a[0], ts.isString(b) ? b : b[0]);
389389
}
390390

391+
export function sanitizeBuildInfoProgram(buildInfo: ts.BuildInfo) {
392+
if (buildInfo.program) {
393+
// reference Map
394+
if (buildInfo.program.referencedMap) {
395+
const referencedMap: ts.MapLike<string[]> = {};
396+
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
397+
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
398+
}
399+
buildInfo.program.referencedMap = referencedMap;
400+
}
401+
402+
// exportedModulesMap
403+
if (buildInfo.program.exportedModulesMap) {
404+
const exportedModulesMap: ts.MapLike<string[]> = {};
405+
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
406+
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
407+
}
408+
buildInfo.program.exportedModulesMap = exportedModulesMap;
409+
}
410+
411+
// semanticDiagnosticsPerFile
412+
if (buildInfo.program.semanticDiagnosticsPerFile) {
413+
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
414+
}
415+
}
416+
}
417+
391418
export const version = "FakeTSVersion";
392419

393420
export class SolutionBuilderHost extends CompilerHost implements ts.SolutionBuilderHost<ts.BuilderProgram> {
@@ -405,30 +432,7 @@ namespace fakes {
405432
public writeFile(fileName: string, content: string, writeByteOrderMark: boolean) {
406433
if (!ts.isBuildInfoFile(fileName)) return super.writeFile(fileName, content, writeByteOrderMark);
407434
const buildInfo = ts.getBuildInfo(content);
408-
if (buildInfo.program) {
409-
// reference Map
410-
if (buildInfo.program.referencedMap) {
411-
const referencedMap: ts.MapLike<string[]> = {};
412-
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
413-
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
414-
}
415-
buildInfo.program.referencedMap = referencedMap;
416-
}
417-
418-
// exportedModulesMap
419-
if (buildInfo.program.exportedModulesMap) {
420-
const exportedModulesMap: ts.MapLike<string[]> = {};
421-
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
422-
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
423-
}
424-
buildInfo.program.exportedModulesMap = exportedModulesMap;
425-
}
426-
427-
// semanticDiagnosticsPerFile
428-
if (buildInfo.program.semanticDiagnosticsPerFile) {
429-
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
430-
}
431-
}
435+
sanitizeBuildInfoProgram(buildInfo);
432436
buildInfo.version = version;
433437
super.writeFile(fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
434438
}

src/testRunner/unittests/tscWatch/incremental.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,23 @@ namespace ts.tscWatch {
105105
result.close();
106106
}
107107

108+
function sanitizeBuildInfo(content: string) {
109+
const buildInfo = getBuildInfo(content);
110+
fakes.sanitizeBuildInfoProgram(buildInfo);
111+
return getBuildInfoText(buildInfo);
112+
}
113+
108114
function checkFileEmit(actual: Map<string>, expected: ReadonlyArray<File>) {
109115
assert.equal(actual.size, expected.length, `Actual: ${JSON.stringify(arrayFrom(actual.entries()), /*replacer*/ undefined, " ")}\nExpected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}`);
110-
expected.forEach(file => assert.equal(actual.get(file.path), file.content, `Emit for ${file.path}`));
116+
expected.forEach(file => {
117+
let expectedContent = file.content;
118+
let actualContent = actual.get(file.path);
119+
if (isBuildInfoFile(file.path)) {
120+
actualContent = actualContent && sanitizeBuildInfo(actualContent);
121+
expectedContent = sanitizeBuildInfo(expectedContent);
122+
}
123+
assert.equal(actualContent, expectedContent, `Emit for ${file.path}`);
124+
});
111125
}
112126

113127
const libFileInfo: BuilderState.FileInfo = {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ declare namespace ts {
44174417
* The builder that can handle the changes in program and iterate through changed file to emit the files
44184418
* The semantic diagnostics are cached per file and managed by clearing for the changed/affected files
44194419
*/
4420-
interface EmitAndSemanticDiagnosticsBuilderProgram extends BuilderProgram {
4420+
interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram {
44214421
/**
44224422
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
44234423
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ declare namespace ts {
44174417
* The builder that can handle the changes in program and iterate through changed file to emit the files
44184418
* The semantic diagnostics are cached per file and managed by clearing for the changed/affected files
44194419
*/
4420-
interface EmitAndSemanticDiagnosticsBuilderProgram extends BuilderProgram {
4420+
interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram {
44214421
/**
44224422
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
44234423
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host

0 commit comments

Comments
 (0)