Skip to content

Commit

Permalink
Ensure that when new file affecting global scope is added, the signat…
Browse files Browse the repository at this point in the history
…ures are updated (#43084)

* Ensure that when new file affecting global scope is added, the signatures are updated

* Update src/compiler/builder.ts

* Better comment
  • Loading branch information
sheetalkamat authored Mar 10, 2021
1 parent 6e4456b commit acc8f2f
Show file tree
Hide file tree
Showing 3 changed files with 729 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,23 @@ namespace ts {
removeSemanticDiagnosticsOf(state, f.resolvedPath)
);
}
// When a change affects the global scope, all files are considered to be affected without updating their signature
// That means when affected file is handled, its signature can be out of date
// To avoid this, ensure that we update the signature for any affected file in this scenario.
BuilderState.updateShapeSignature(
state,
Debug.checkDefined(state.program),
affectedFile,
Debug.checkDefined(state.currentAffectedFilesSignatures),
cancellationToken,
computeHash,
state.currentAffectedFilesExportedModulesMap
);
return;
}
else {
Debug.assert(state.hasCalledUpdateShapeSignature.has(affectedFile.resolvedPath) || state.currentAffectedFilesSignatures?.has(affectedFile.resolvedPath), `Signature not updated for affected file: ${affectedFile.fileName}`);
}

if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
Expand Down
52 changes: 52 additions & 0 deletions src/testRunner/unittests/tsc/incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,58 @@ const a: string = 10;`, "utf-8"),
}
});

verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: `when global file is added, the signatures are updated`,
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": Utils.dedent`
/// <reference path="./filePresent.ts"/>
/// <reference path="./fileNotFound.ts"/>
function main() { }
`,
"/src/project/src/anotherFileWithSameReferenes.ts": Utils.dedent`
/// <reference path="./filePresent.ts"/>
/// <reference path="./fileNotFound.ts"/>
function anotherFileWithSameReferenes() { }
`,
"/src/project/src/filePresent.ts": `function something() { return 10; }`,
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: { composite: true, },
include: ["src/**/*.ts"]
}),
}),
commandLineArgs: ["--p", "src/project"],
incrementalScenarios: [
noChangeRun,
{
subScenario: "Modify main file",
buildKind: BuildKind.IncrementalDtsChange,
modifyFs: fs => appendText(fs, `/src/project/src/main.ts`, `something();`),
},
{
subScenario: "Add new file and update main file",
buildKind: BuildKind.IncrementalDtsChange,
modifyFs: fs => {
fs.writeFileSync(`/src/project/src/newFile.ts`, "function foo() { return 20; }");
prependText(fs, `/src/project/src/main.ts`, `/// <reference path="./newFile.ts"/>
`);
appendText(fs, `/src/project/src/main.ts`, `foo();`);
},
},
{
subScenario: "Write file that could not be resolved",
buildKind: BuildKind.IncrementalDtsChange,
modifyFs: fs => fs.writeFileSync(`/src/project/src/fileNotFound.ts`, "function something2() { return 20; }"),
},
{
subScenario: "Modify main file",
buildKind: BuildKind.IncrementalDtsChange,
modifyFs: fs => appendText(fs, `/src/project/src/main.ts`, `something();`),
},
],
baselinePrograms: true,
});

const jsxLibraryContent = `
export {};
declare global {
Expand Down
Loading

0 comments on commit acc8f2f

Please sign in to comment.