Skip to content

Commit acc8f2f

Browse files
authored
Ensure that when new file affecting global scope is added, the signatures are updated (#43084)
* Ensure that when new file affecting global scope is added, the signatures are updated * Update src/compiler/builder.ts * Better comment
1 parent 6e4456b commit acc8f2f

File tree

3 files changed

+729
-0
lines changed

3 files changed

+729
-0
lines changed

src/compiler/builder.ts

+15
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,23 @@ namespace ts {
438438
removeSemanticDiagnosticsOf(state, f.resolvedPath)
439439
);
440440
}
441+
// When a change affects the global scope, all files are considered to be affected without updating their signature
442+
// That means when affected file is handled, its signature can be out of date
443+
// To avoid this, ensure that we update the signature for any affected file in this scenario.
444+
BuilderState.updateShapeSignature(
445+
state,
446+
Debug.checkDefined(state.program),
447+
affectedFile,
448+
Debug.checkDefined(state.currentAffectedFilesSignatures),
449+
cancellationToken,
450+
computeHash,
451+
state.currentAffectedFilesExportedModulesMap
452+
);
441453
return;
442454
}
455+
else {
456+
Debug.assert(state.hasCalledUpdateShapeSignature.has(affectedFile.resolvedPath) || state.currentAffectedFilesSignatures?.has(affectedFile.resolvedPath), `Signature not updated for affected file: ${affectedFile.fileName}`);
457+
}
443458

444459
if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
445460
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));

src/testRunner/unittests/tsc/incremental.ts

+52
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,58 @@ const a: string = 10;`, "utf-8"),
236236
}
237237
});
238238

239+
verifyTscSerializedIncrementalEdits({
240+
scenario: "incremental",
241+
subScenario: `when global file is added, the signatures are updated`,
242+
fs: () => loadProjectFromFiles({
243+
"/src/project/src/main.ts": Utils.dedent`
244+
/// <reference path="./filePresent.ts"/>
245+
/// <reference path="./fileNotFound.ts"/>
246+
function main() { }
247+
`,
248+
"/src/project/src/anotherFileWithSameReferenes.ts": Utils.dedent`
249+
/// <reference path="./filePresent.ts"/>
250+
/// <reference path="./fileNotFound.ts"/>
251+
function anotherFileWithSameReferenes() { }
252+
`,
253+
"/src/project/src/filePresent.ts": `function something() { return 10; }`,
254+
"/src/project/tsconfig.json": JSON.stringify({
255+
compilerOptions: { composite: true, },
256+
include: ["src/**/*.ts"]
257+
}),
258+
}),
259+
commandLineArgs: ["--p", "src/project"],
260+
incrementalScenarios: [
261+
noChangeRun,
262+
{
263+
subScenario: "Modify main file",
264+
buildKind: BuildKind.IncrementalDtsChange,
265+
modifyFs: fs => appendText(fs, `/src/project/src/main.ts`, `something();`),
266+
},
267+
{
268+
subScenario: "Add new file and update main file",
269+
buildKind: BuildKind.IncrementalDtsChange,
270+
modifyFs: fs => {
271+
fs.writeFileSync(`/src/project/src/newFile.ts`, "function foo() { return 20; }");
272+
prependText(fs, `/src/project/src/main.ts`, `/// <reference path="./newFile.ts"/>
273+
`);
274+
appendText(fs, `/src/project/src/main.ts`, `foo();`);
275+
},
276+
},
277+
{
278+
subScenario: "Write file that could not be resolved",
279+
buildKind: BuildKind.IncrementalDtsChange,
280+
modifyFs: fs => fs.writeFileSync(`/src/project/src/fileNotFound.ts`, "function something2() { return 20; }"),
281+
},
282+
{
283+
subScenario: "Modify main file",
284+
buildKind: BuildKind.IncrementalDtsChange,
285+
modifyFs: fs => appendText(fs, `/src/project/src/main.ts`, `something();`),
286+
},
287+
],
288+
baselinePrograms: true,
289+
});
290+
239291
const jsxLibraryContent = `
240292
export {};
241293
declare global {

0 commit comments

Comments
 (0)