From 17d2c8bcfb92872f8015427bab59ebb60ef1bab6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 16 Apr 2019 13:25:54 -0700 Subject: [PATCH] Handle dts change as well as signature update when exported module affects dts but not js file --- src/compiler/builder.ts | 32 +++++++++++++------ src/compiler/builderState.ts | 2 +- .../inferred-type-from-transitive-module.js | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index aaba45901ff..2d6551cb377 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -340,7 +340,7 @@ namespace ts { // Set the next affected file as seen and remove the cached semantic diagnostics state.affectedFilesIndex = affectedFilesIndex; cleanSemanticDiagnosticsOfAffectedFile(state, affectedFile); - handleDtsMayChangeOfAffectedFile(state, affectedFile) + handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash); return affectedFile; } seenAffectedFiles.set(affectedFile.path, true); @@ -451,11 +451,7 @@ namespace ts { * Add files, that are referencing modules that export entities from affected file as pending emit since dts may change * Similar to cleanSemanticDiagnosticsOfAffectedFile */ - function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile) { - // If not dts emit, nothing more to do - if (!getEmitDeclarations(state.compilerOptions)) { - return; - } + function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) { // If affected files is everything except default librarry, then nothing more to do if (state.allFilesExcludingDefaultLibraryFile === state.affectedFiles) { @@ -468,10 +464,26 @@ namespace ts { return; } - forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, filePath) => { - addToAffectedFilesPendingEmit(state, [filePath]); - return false; - }); + forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash)); + } + + /** + * Handle the dts may change, so they need to be added to pending emit if dts emit is enabled, + * Also we need to make sure signature is updated for these files + */ + function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) { + if (!state.changedFilesSet.has(path)) { + const program = Debug.assertDefined(state.program); + const sourceFile = program.getSourceFileByPath(path); + if (sourceFile) { + BuilderState.updateShapeSignature(state, program, sourceFile, Debug.assertDefined(state.currentAffectedFilesSignatures), cancellationToken, computeHash, state.currentAffectedFilesExportedModulesMap); + // If not dts emit, nothing more to do + if (getEmitDeclarations(state.compilerOptions)) { + addToAffectedFilesPendingEmit(state, [path]); + } + } + } + return false; } /** diff --git a/src/compiler/builderState.ts b/src/compiler/builderState.ts index b7f01b838fd..58b189d9e81 100644 --- a/src/compiler/builderState.ts +++ b/src/compiler/builderState.ts @@ -321,7 +321,7 @@ namespace ts.BuilderState { /** * Returns if the shape of the signature has changed since last emit */ - function updateShapeSignature(state: Readonly, programOfThisState: Program, sourceFile: SourceFile, cacheToUpdateSignature: Map, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache?: ComputingExportedModulesMap) { + export function updateShapeSignature(state: Readonly, programOfThisState: Program, sourceFile: SourceFile, cacheToUpdateSignature: Map, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache?: ComputingExportedModulesMap) { Debug.assert(!!sourceFile); Debug.assert(!exportedModulesMapCache || !!state.exportedModulesMap, "Compute visible to outside map only if visibleToOutsideReferencedMap present in the state"); diff --git a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js index 0dca3e32654..89e21796e61 100644 --- a/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js +++ b/tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js @@ -52,7 +52,7 @@ export declare const lazyBar: LazyAction<() => void, typeof import("./lazyIndex" }, "/src/index.ts": { "version": "-11602502901", - "signature": "18468008756" + "signature": "6256067474" } }, "options": {