Skip to content

Commit

Permalink
Add test that fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Oct 1, 2020
1 parent 3511123 commit ca35546
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ namespace ts {
getOptionsDiagnostics,
getGlobalDiagnostics,
getSemanticDiagnostics,
getCachedSemanticDiagnostics,
getSuggestionDiagnostics,
getDeclarationDiagnostics,
getBindAndCheckDiagnostics,
Expand Down Expand Up @@ -1656,6 +1657,12 @@ namespace ts {
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile, cancellationToken);
}

function getCachedSemanticDiagnostics(sourceFile?: SourceFile): readonly Diagnostic[] | undefined {
return sourceFile
? cachedBindAndCheckDiagnosticsForFile.perFile?.get(sourceFile.path)
: cachedBindAndCheckDiagnosticsForFile.allDiagnostics;
}

function getBindAndCheckDiagnostics(sourceFile: SourceFile, cancellationToken?: CancellationToken): readonly Diagnostic[] {
return getBindAndCheckDiagnosticsForFile(sourceFile, cancellationToken);
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3762,6 +3762,8 @@ namespace ts {
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
/* @internal */ dropDiagnosticsProducingTypeChecker(): void;

/* @internal */ getCachedSemanticDiagnostics(sourceFile?: SourceFile): readonly Diagnostic[] | undefined;

/* @internal */ getClassifiableNames(): Set<__String>;

getTypeCatalog(): readonly Type[];
Expand Down
32 changes: 32 additions & 0 deletions src/testRunner/unittests/tscWatch/watchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,36 @@ namespace ts.tscWatch {
checkProgramActualFiles(watch.getProgram().getProgram(), [mainFile.path, otherFile.path, libFile.path]);
});
});

describe("unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticDiagnosticsBuilderProgram", () => {
it("verifies that noEmit is handled on createSemanticDiagnosticsBuilderProgram and typechecking happens only on affected files", () => {
const config: File = {
path: `${projectRoot}/tsconfig.json`,
content: "{}"
};
const mainFile: File = {
path: `${projectRoot}/main.ts`,
content: "export const x = 10;"
};
const otherFile: File = {
path: `${projectRoot}/other.ts`,
content: "export const y = 10;"
};
const sys = createWatchedSystem([config, mainFile, otherFile, libFile]);
const watchCompilerHost = createWatchCompilerHost(
config.path,
{ noEmit: true },
sys,
createSemanticDiagnosticsBuilderProgram
);
const watch = createWatchProgram(watchCompilerHost);
checkProgramActualFiles(watch.getProgram().getProgram(), [mainFile.path, otherFile.path, libFile.path]);
sys.appendFile(mainFile.path, "\n// SomeComment");
sys.runQueuedTimeoutCallbacks();
const program = watch.getProgram().getProgram();
assert.deepEqual(program.getCachedSemanticDiagnostics(program.getSourceFile(mainFile.path)), []);
// Should not retrieve diagnostics for other file thats not changed
assert.deepEqual(program.getCachedSemanticDiagnostics(program.getSourceFile(otherFile.path)), /*expected*/ undefined);
});
});
}

0 comments on commit ca35546

Please sign in to comment.