Fix the issue with not serializing impliedFormat when signature and version of the file are same (#48614)

* When checking for incremental correctness always calculate signature

* Fix the issue with not serializing impliedFormat when signature == version of the file
This commit is contained in:
Sheetal Nandi
2022-04-11 12:39:57 -07:00
committed by GitHub
parent 02787cfde1
commit a1e77edfdf
4 changed files with 49 additions and 32 deletions

View File

@@ -348,7 +348,7 @@ namespace ts {
* This is to allow the callers to be able to actually remove affected file only when the operation is complete
* eg. if during diagnostics check cancellation token ends up cancelling the request, the affected file should be retained
*/
function getNextAffectedFile(state: BuilderProgramState, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash): SourceFile | Program | undefined {
function getNextAffectedFile(state: BuilderProgramState, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost): SourceFile | Program | undefined {
while (true) {
const { affectedFiles } = state;
if (affectedFiles) {
@@ -359,7 +359,7 @@ namespace ts {
if (!seenAffectedFiles.has(affectedFile.resolvedPath)) {
// Set the next affected file as seen and remove the cached semantic diagnostics
state.affectedFilesIndex = affectedFilesIndex;
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash);
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash, host);
return affectedFile;
}
affectedFilesIndex++;
@@ -437,7 +437,7 @@ namespace ts {
* Handles semantic diagnostics and dts emit for affectedFile and files, that are referencing modules that export entities from affected file
* This is because even though js emit doesnt change, dts emit / type used can change resulting in need for dts emit and js change
*/
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost) {
removeSemanticDiagnosticsOf(state, affectedFile.resolvedPath);
// If affected files is everything except default library, then nothing more to do
@@ -471,7 +471,7 @@ namespace ts {
}
if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash, host));
}
}
@@ -479,7 +479,7 @@ namespace ts {
* 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): void {
function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost): void {
removeSemanticDiagnosticsOf(state, path);
if (!state.changedFilesSet.has(path)) {
@@ -499,7 +499,7 @@ namespace ts {
cancellationToken,
computeHash,
state.currentAffectedFilesExportedModulesMap,
/* useFileVersionAsSignature */ true
!host.disableUseFileVersionAsSignature
);
// If not dts emit, nothing more to do
if (getEmitDeclarations(state.compilerOptions)) {
@@ -755,13 +755,18 @@ namespace ts {
const signature = state.currentAffectedFilesSignatures && state.currentAffectedFilesSignatures.get(key);
const actualSignature = signature ?? value.signature;
return value.version === actualSignature ?
value.affectsGlobalScope ?
{ version: value.version, signature: undefined, affectsGlobalScope: true, impliedFormat: value.impliedFormat } :
value.affectsGlobalScope || value.impliedFormat ?
// If file version is same as signature, dont serialize signature
{ version: value.version, signature: undefined, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat } :
// If file info only contains version and signature and both are same we can just write string
value.version :
actualSignature !== undefined ?
actualSignature !== undefined ? // If signature is not same as version, encode signature in the fileInfo
signature === undefined ?
// If we havent computed signature, use fileInfo as is
value :
// Serialize fileInfo with new updated signature
{ version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat } :
// Signature of the FileInfo is undefined, serialize it as false
{ version: value.version, signature: false, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat };
});
@@ -1043,7 +1048,7 @@ namespace ts {
* in that order would be used to write the files
*/
function emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult> {
let affected = getNextAffectedFile(state, cancellationToken, computeHash);
let affected = getNextAffectedFile(state, cancellationToken, computeHash, host);
let emitKind = BuilderFileEmit.Full;
let isPendingEmitFile = false;
if (!affected) {
@@ -1156,7 +1161,7 @@ namespace ts {
*/
function getSemanticDiagnosticsOfNextAffectedFile(cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<readonly Diagnostic[]> {
while (true) {
const affected = getNextAffectedFile(state, cancellationToken, computeHash);
const affected = getNextAffectedFile(state, cancellationToken, computeHash, host);
if (!affected) {
// Done
return undefined;

View File

@@ -81,7 +81,7 @@ namespace ts {
export interface FileInfo {
readonly version: string;
signature: string | undefined;
affectsGlobalScope: boolean | undefined;
affectsGlobalScope: true | undefined;
impliedFormat: number | undefined;
}