Skip to content

Commit 17d2c8b

Browse files
committed
Handle dts change as well as signature update when exported module affects dts but not js file
1 parent db8c6ee commit 17d2c8b

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/compiler/builder.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ namespace ts {
340340
// Set the next affected file as seen and remove the cached semantic diagnostics
341341
state.affectedFilesIndex = affectedFilesIndex;
342342
cleanSemanticDiagnosticsOfAffectedFile(state, affectedFile);
343-
handleDtsMayChangeOfAffectedFile(state, affectedFile)
343+
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash);
344344
return affectedFile;
345345
}
346346
seenAffectedFiles.set(affectedFile.path, true);
@@ -451,11 +451,7 @@ namespace ts {
451451
* Add files, that are referencing modules that export entities from affected file as pending emit since dts may change
452452
* Similar to cleanSemanticDiagnosticsOfAffectedFile
453453
*/
454-
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile) {
455-
// If not dts emit, nothing more to do
456-
if (!getEmitDeclarations(state.compilerOptions)) {
457-
return;
458-
}
454+
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
459455

460456
// If affected files is everything except default librarry, then nothing more to do
461457
if (state.allFilesExcludingDefaultLibraryFile === state.affectedFiles) {
@@ -468,10 +464,26 @@ namespace ts {
468464
return;
469465
}
470466

471-
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, filePath) => {
472-
addToAffectedFilesPendingEmit(state, [filePath]);
473-
return false;
474-
});
467+
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
468+
}
469+
470+
/**
471+
* Handle the dts may change, so they need to be added to pending emit if dts emit is enabled,
472+
* Also we need to make sure signature is updated for these files
473+
*/
474+
function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
475+
if (!state.changedFilesSet.has(path)) {
476+
const program = Debug.assertDefined(state.program);
477+
const sourceFile = program.getSourceFileByPath(path);
478+
if (sourceFile) {
479+
BuilderState.updateShapeSignature(state, program, sourceFile, Debug.assertDefined(state.currentAffectedFilesSignatures), cancellationToken, computeHash, state.currentAffectedFilesExportedModulesMap);
480+
// If not dts emit, nothing more to do
481+
if (getEmitDeclarations(state.compilerOptions)) {
482+
addToAffectedFilesPendingEmit(state, [path]);
483+
}
484+
}
485+
}
486+
return false;
475487
}
476488

477489
/**

src/compiler/builderState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ namespace ts.BuilderState {
321321
/**
322322
* Returns if the shape of the signature has changed since last emit
323323
*/
324-
function updateShapeSignature(state: Readonly<BuilderState>, programOfThisState: Program, sourceFile: SourceFile, cacheToUpdateSignature: Map<string>, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache?: ComputingExportedModulesMap) {
324+
export function updateShapeSignature(state: Readonly<BuilderState>, programOfThisState: Program, sourceFile: SourceFile, cacheToUpdateSignature: Map<string>, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache?: ComputingExportedModulesMap) {
325325
Debug.assert(!!sourceFile);
326326
Debug.assert(!exportedModulesMapCache || !!state.exportedModulesMap, "Compute visible to outside map only if visibleToOutsideReferencedMap present in the state");
327327

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export declare const lazyBar: LazyAction<() => void, typeof import("./lazyIndex"
5252
},
5353
"/src/index.ts": {
5454
"version": "-11602502901",
55-
"signature": "18468008756"
55+
"signature": "6256067474"
5656
}
5757
},
5858
"options": {

0 commit comments

Comments
 (0)