Skip to content

Commit ca35546

Browse files
committed
Add test that fails
1 parent 3511123 commit ca35546

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/compiler/program.ts

+7
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ namespace ts {
936936
getOptionsDiagnostics,
937937
getGlobalDiagnostics,
938938
getSemanticDiagnostics,
939+
getCachedSemanticDiagnostics,
939940
getSuggestionDiagnostics,
940941
getDeclarationDiagnostics,
941942
getBindAndCheckDiagnostics,
@@ -1656,6 +1657,12 @@ namespace ts {
16561657
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile, cancellationToken);
16571658
}
16581659

1660+
function getCachedSemanticDiagnostics(sourceFile?: SourceFile): readonly Diagnostic[] | undefined {
1661+
return sourceFile
1662+
? cachedBindAndCheckDiagnosticsForFile.perFile?.get(sourceFile.path)
1663+
: cachedBindAndCheckDiagnosticsForFile.allDiagnostics;
1664+
}
1665+
16591666
function getBindAndCheckDiagnostics(sourceFile: SourceFile, cancellationToken?: CancellationToken): readonly Diagnostic[] {
16601667
return getBindAndCheckDiagnosticsForFile(sourceFile, cancellationToken);
16611668
}

src/compiler/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3762,6 +3762,8 @@ namespace ts {
37623762
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
37633763
/* @internal */ dropDiagnosticsProducingTypeChecker(): void;
37643764

3765+
/* @internal */ getCachedSemanticDiagnostics(sourceFile?: SourceFile): readonly Diagnostic[] | undefined;
3766+
37653767
/* @internal */ getClassifiableNames(): Set<__String>;
37663768

37673769
getTypeCatalog(): readonly Type[];

src/testRunner/unittests/tscWatch/watchApi.ts

+32
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,36 @@ namespace ts.tscWatch {
123123
checkProgramActualFiles(watch.getProgram().getProgram(), [mainFile.path, otherFile.path, libFile.path]);
124124
});
125125
});
126+
127+
describe("unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticDiagnosticsBuilderProgram", () => {
128+
it("verifies that noEmit is handled on createSemanticDiagnosticsBuilderProgram and typechecking happens only on affected files", () => {
129+
const config: File = {
130+
path: `${projectRoot}/tsconfig.json`,
131+
content: "{}"
132+
};
133+
const mainFile: File = {
134+
path: `${projectRoot}/main.ts`,
135+
content: "export const x = 10;"
136+
};
137+
const otherFile: File = {
138+
path: `${projectRoot}/other.ts`,
139+
content: "export const y = 10;"
140+
};
141+
const sys = createWatchedSystem([config, mainFile, otherFile, libFile]);
142+
const watchCompilerHost = createWatchCompilerHost(
143+
config.path,
144+
{ noEmit: true },
145+
sys,
146+
createSemanticDiagnosticsBuilderProgram
147+
);
148+
const watch = createWatchProgram(watchCompilerHost);
149+
checkProgramActualFiles(watch.getProgram().getProgram(), [mainFile.path, otherFile.path, libFile.path]);
150+
sys.appendFile(mainFile.path, "\n// SomeComment");
151+
sys.runQueuedTimeoutCallbacks();
152+
const program = watch.getProgram().getProgram();
153+
assert.deepEqual(program.getCachedSemanticDiagnostics(program.getSourceFile(mainFile.path)), []);
154+
// Should not retrieve diagnostics for other file thats not changed
155+
assert.deepEqual(program.getCachedSemanticDiagnostics(program.getSourceFile(otherFile.path)), /*expected*/ undefined);
156+
});
157+
});
126158
}

0 commit comments

Comments
 (0)