Skip to content

Commit 775a4dd

Browse files
TypeScript Botsheetalkamat
TypeScript Bot
authored andcommitted
Cherry-pick PR microsoft#33168 into release-3.6 (microsoft#33169)
Component commits: 078ef7f Fix the semantic diagnostics caching in builder to handle conversion from relative to buildInfo to absolute path Fixes microsoft#33161
1 parent 8118bec commit 775a4dd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/compiler/builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ namespace ts {
10361036
compilerOptions: convertFromReusableCompilerOptions(program.options, toAbsolutePath),
10371037
referencedMap: getMapOfReferencedSet(program.referencedMap, toPath),
10381038
exportedModulesMap: getMapOfReferencedSet(program.exportedModulesMap, toPath),
1039-
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => isString(value) ? value : value[0], value => isString(value) ? emptyArray : value[1]),
1039+
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => toPath(isString(value) ? value : value[0]), value => isString(value) ? emptyArray : value[1]),
10401040
hasReusableDiagnostic: true
10411041
};
10421042
return {

src/testRunner/unittests/tscWatch/incremental.ts

+43
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,49 @@ namespace ts.tscWatch {
542542
],
543543
expectedIncrementalErrors: file2Errors,
544544
});
545+
546+
it("verify that state is read correctly", () => {
547+
const system = createWatchedSystem([libFile, file1, fileModified, config], { currentDirectory: project });
548+
incrementalBuild("tsconfig.json", system);
549+
550+
const command = parseConfigFileWithSystem("tsconfig.json", {}, system, noop)!;
551+
const builderProgram = createIncrementalProgram({
552+
rootNames: command.fileNames,
553+
options: command.options,
554+
projectReferences: command.projectReferences,
555+
configFileParsingDiagnostics: getConfigFileParsingDiagnostics(command),
556+
host: createIncrementalCompilerHost(command.options, system)
557+
});
558+
559+
const state = builderProgram.getState();
560+
assert.equal(state.changedFilesSet!.size, 0, "changes");
561+
562+
assert.equal(state.fileInfos.size, 3, "FileInfo size");
563+
assert.deepEqual(state.fileInfos.get(libFile.path), libFileInfo);
564+
assert.deepEqual(state.fileInfos.get(file1.path), getFileInfo(file1.content));
565+
assert.deepEqual(state.fileInfos.get(file2.path), file2FileInfo);
566+
567+
assert.deepEqual(state.compilerOptions, {
568+
incremental: true,
569+
module: ModuleKind.AMD,
570+
configFilePath: config.path
571+
});
572+
573+
assert.equal(state.referencedMap!.size, 0);
574+
assert.equal(state.exportedModulesMap!.size, 0);
575+
576+
assert.equal(state.semanticDiagnosticsPerFile!.size, 3);
577+
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(libFile.path), emptyArray);
578+
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(file1.path), emptyArray);
579+
const { file: _, relatedInformation: __, ...rest } = file2ReuasableError[1][0];
580+
assert.deepEqual(state.semanticDiagnosticsPerFile!.get(file2.path), [{
581+
...rest,
582+
file: state.program!.getSourceFileByPath(file2.path as Path)!,
583+
relatedInformation: undefined,
584+
reportsUnnecessary: undefined,
585+
source: undefined
586+
}]);
587+
});
545588
});
546589

547590
describe("with --out", () => {

0 commit comments

Comments
 (0)