Skip to content

Prevent excessive compilation of files within a cycle #33061

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

Closed
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
16 changes: 15 additions & 1 deletion src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,21 @@ namespace ts {
}

function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFilesPendingEmit: readonly Path[]) {
state.affectedFilesPendingEmit = concatenate(state.affectedFilesPendingEmit, affectedFilesPendingEmit);
const actualAffectedFilesPendingEmit = affectedFilesPendingEmit.filter((f) => {
Copy link
Member

Choose a reason for hiding this comment

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

Was able to repro the issue. The current fix isnt corrrect.
The fix is to set add seenEmittedFiles.set(affectedFile.path, true) at https://github.com/microsoft/TypeScript/blob/master/src/compiler/builder.ts#L384

// No point in concatenating if its already in there
if (state.affectedFilesPendingEmit && state.affectedFilesPendingEmit.some((v) => v === f)) {
return false;
}

return true;
});

if (actualAffectedFilesPendingEmit.length === 0) {
// We filtered everything out, abort.
return;
}

state.affectedFilesPendingEmit = concatenate(state.affectedFilesPendingEmit, actualAffectedFilesPendingEmit);
Copy link
Member

Choose a reason for hiding this comment

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

Add test in src/testRunner/unittests/tscWatch/emitAndErrorUpdates.ts that has host.writeFile overriding the original one that also checks that file is emitted only once in the repro test case you have mentioned.

// affectedFilesPendingEmitIndex === undefined
// - means the emit state.affectedFilesPendingEmit was undefined before adding current affected files
// so start from 0 as array would be affectedFilesPendingEmit
Expand Down