Skip to content

Commit ad55994

Browse files
authored
Merge pull request #27974 from Microsoft/errorUpdateWithChangeInTransitiveDeclarationFile
Use reference map from declaration file as exported map to handle deep import semantic diagnostics invalidation
2 parents bf393ae + d352b8c commit ad55994

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/compiler/builderState.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ namespace ts.BuilderState {
292292
let latestSignature: string;
293293
if (sourceFile.isDeclarationFile) {
294294
latestSignature = sourceFile.version;
295+
if (exportedModulesMapCache && latestSignature !== prevSignature) {
296+
// All the references in this file are exported
297+
const references = state.referencedMap ? state.referencedMap.get(sourceFile.path) : undefined;
298+
exportedModulesMapCache.set(sourceFile.path, references || false);
299+
}
295300
}
296301
else {
297302
const emitOutput = getFileEmitOutput(programOfThisState, sourceFile, /*emitOnlyDtsFiles*/ true, cancellationToken);

src/testRunner/unittests/tscWatchMode.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,49 @@ export class B
13501350
assert.equal(host.getModifiedTime(`${currentDirectory}/a.js`), modifiedTimeOfAJs);
13511351
});
13521352

1353+
it("updates errors when deep import through declaration file changes", () => {
1354+
const currentDirectory = "/user/username/projects/myproject";
1355+
const aFile: File = {
1356+
path: `${currentDirectory}/a.ts`,
1357+
content: `import {B} from './b';
1358+
declare var console: any;
1359+
let b = new B();
1360+
console.log(b.c.d);`
1361+
};
1362+
const bFile: File = {
1363+
path: `${currentDirectory}/b.d.ts`,
1364+
content: `import {C} from './c';
1365+
export class B
1366+
{
1367+
c: C;
1368+
}`
1369+
};
1370+
const cFile: File = {
1371+
path: `${currentDirectory}/c.d.ts`,
1372+
content: `export class C
1373+
{
1374+
d: number;
1375+
}`
1376+
};
1377+
const config: File = {
1378+
path: `${currentDirectory}/tsconfig.json`,
1379+
content: `{}`
1380+
};
1381+
const files = [aFile, bFile, cFile, config, libFile];
1382+
const host = createWatchedSystem(files, { currentDirectory });
1383+
const watch = createWatchOfConfigFile("tsconfig.json", host);
1384+
checkProgramActualFiles(watch(), [aFile.path, bFile.path, cFile.path, libFile.path]);
1385+
checkOutputErrorsInitial(host, emptyArray);
1386+
const modifiedTimeOfAJs = host.getModifiedTime(`${currentDirectory}/a.js`);
1387+
host.writeFile(cFile.path, cFile.content.replace("d", "d2"));
1388+
host.runQueuedTimeoutCallbacks();
1389+
checkOutputErrorsIncremental(host, [
1390+
getDiagnosticOfFileFromProgram(watch(), aFile.path, aFile.content.lastIndexOf("d"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "d", "C")
1391+
]);
1392+
// File a need not be rewritten
1393+
assert.equal(host.getModifiedTime(`${currentDirectory}/a.js`), modifiedTimeOfAJs);
1394+
});
1395+
13531396
it("updates errors when strictNullChecks changes", () => {
13541397
const currentDirectory = "/user/username/projects/myproject";
13551398
const aFile: File = {

0 commit comments

Comments
 (0)