Skip to content
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
Copy Markdown
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
Copy Markdown
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