Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once merged with #42960 this has to be added here:

/*avoidInitializingSignatures*/ true

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