Skip to content

Commit a1e77ed

Browse files
authored
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
1 parent 02787cf commit a1e77ed

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

src/compiler/builder.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ namespace ts {
348348
* This is to allow the callers to be able to actually remove affected file only when the operation is complete
349349
* eg. if during diagnostics check cancellation token ends up cancelling the request, the affected file should be retained
350350
*/
351-
function getNextAffectedFile(state: BuilderProgramState, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash): SourceFile | Program | undefined {
351+
function getNextAffectedFile(state: BuilderProgramState, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost): SourceFile | Program | undefined {
352352
while (true) {
353353
const { affectedFiles } = state;
354354
if (affectedFiles) {
@@ -359,7 +359,7 @@ namespace ts {
359359
if (!seenAffectedFiles.has(affectedFile.resolvedPath)) {
360360
// Set the next affected file as seen and remove the cached semantic diagnostics
361361
state.affectedFilesIndex = affectedFilesIndex;
362-
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash);
362+
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash, host);
363363
return affectedFile;
364364
}
365365
affectedFilesIndex++;
@@ -437,7 +437,7 @@ namespace ts {
437437
* Handles semantic diagnostics and dts emit for affectedFile and files, that are referencing modules that export entities from affected file
438438
* This is because even though js emit doesnt change, dts emit / type used can change resulting in need for dts emit and js change
439439
*/
440-
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
440+
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost) {
441441
removeSemanticDiagnosticsOf(state, affectedFile.resolvedPath);
442442

443443
// If affected files is everything except default library, then nothing more to do
@@ -471,15 +471,15 @@ namespace ts {
471471
}
472472

473473
if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
474-
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
474+
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash, host));
475475
}
476476
}
477477

478478
/**
479479
* Handle the dts may change, so they need to be added to pending emit if dts emit is enabled,
480480
* Also we need to make sure signature is updated for these files
481481
*/
482-
function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash): void {
482+
function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash, host: BuilderProgramHost): void {
483483
removeSemanticDiagnosticsOf(state, path);
484484

485485
if (!state.changedFilesSet.has(path)) {
@@ -499,7 +499,7 @@ namespace ts {
499499
cancellationToken,
500500
computeHash,
501501
state.currentAffectedFilesExportedModulesMap,
502-
/* useFileVersionAsSignature */ true
502+
!host.disableUseFileVersionAsSignature
503503
);
504504
// If not dts emit, nothing more to do
505505
if (getEmitDeclarations(state.compilerOptions)) {
@@ -755,13 +755,18 @@ namespace ts {
755755
const signature = state.currentAffectedFilesSignatures && state.currentAffectedFilesSignatures.get(key);
756756
const actualSignature = signature ?? value.signature;
757757
return value.version === actualSignature ?
758-
value.affectsGlobalScope ?
759-
{ version: value.version, signature: undefined, affectsGlobalScope: true, impliedFormat: value.impliedFormat } :
758+
value.affectsGlobalScope || value.impliedFormat ?
759+
// If file version is same as signature, dont serialize signature
760+
{ version: value.version, signature: undefined, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat } :
761+
// If file info only contains version and signature and both are same we can just write string
760762
value.version :
761-
actualSignature !== undefined ?
763+
actualSignature !== undefined ? // If signature is not same as version, encode signature in the fileInfo
762764
signature === undefined ?
765+
// If we havent computed signature, use fileInfo as is
763766
value :
767+
// Serialize fileInfo with new updated signature
764768
{ version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat } :
769+
// Signature of the FileInfo is undefined, serialize it as false
765770
{ version: value.version, signature: false, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat };
766771
});
767772

@@ -1043,7 +1048,7 @@ namespace ts {
10431048
* in that order would be used to write the files
10441049
*/
10451050
function emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult> {
1046-
let affected = getNextAffectedFile(state, cancellationToken, computeHash);
1051+
let affected = getNextAffectedFile(state, cancellationToken, computeHash, host);
10471052
let emitKind = BuilderFileEmit.Full;
10481053
let isPendingEmitFile = false;
10491054
if (!affected) {
@@ -1156,7 +1161,7 @@ namespace ts {
11561161
*/
11571162
function getSemanticDiagnosticsOfNextAffectedFile(cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<readonly Diagnostic[]> {
11581163
while (true) {
1159-
const affected = getNextAffectedFile(state, cancellationToken, computeHash);
1164+
const affected = getNextAffectedFile(state, cancellationToken, computeHash, host);
11601165
if (!affected) {
11611166
// Done
11621167
return undefined;

src/compiler/builderState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace ts {
8181
export interface FileInfo {
8282
readonly version: string;
8383
signature: string | undefined;
84-
affectsGlobalScope: boolean | undefined;
84+
affectsGlobalScope: true | undefined;
8585
impliedFormat: number | undefined;
8686
}
8787

tests/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-across-projects-resolve-correctly.js

+22-13
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ LassieDog.getDogConfig = () => LASSIE_CONFIG;
191191

192192

193193
//// [/src/src-dogs/tsconfig.tsbuildinfo]
194-
{"program":{"fileNames":["../../lib/lib.es2020.full.d.ts","../src-types/dogconfig.d.ts","../src-types/index.d.ts","./dogconfig.ts","./dog.ts","./lassie/lassieconfig.ts","./lassie/lassiedog.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},"-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n","-5608794531-export * from './dogconfig.js';\r\n","1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n","6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n","4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n","-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n","-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n"],"options":{"composite":true,"declaration":true,"module":100},"fileIdsList":[[3,4],[3],[3,7],[5,6],[2]],"referencedMap":[[5,1],[4,2],[8,3],[6,2],[7,4],[3,5]],"exportedModulesMap":[[5,1],[4,2],[8,3],[6,2],[7,4],[3,5]],"semanticDiagnosticsPerFile":[1,5,4,8,6,7,2,3]},"version":"FakeTSVersion"}
194+
{"program":{"fileNames":["../../lib/lib.es2020.full.d.ts","../src-types/dogconfig.d.ts","../src-types/index.d.ts","./dogconfig.ts","./dog.ts","./lassie/lassieconfig.ts","./lassie/lassiedog.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n","impliedFormat":99},{"version":"-5608794531-export * from './dogconfig.js';\r\n","impliedFormat":99},{"version":"1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n","impliedFormat":99},{"version":"6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n","impliedFormat":99},{"version":"4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n","impliedFormat":99},{"version":"-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n","impliedFormat":99},{"version":"-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n","impliedFormat":99}],"options":{"composite":true,"declaration":true,"module":100},"fileIdsList":[[3,4],[3],[3,7],[5,6],[2]],"referencedMap":[[5,1],[4,2],[8,3],[6,2],[7,4],[3,5]],"exportedModulesMap":[[5,1],[4,2],[8,3],[6,2],[7,4],[3,5]],"semanticDiagnosticsPerFile":[1,5,4,8,6,7,2,3]},"version":"FakeTSVersion"}
195195

196196
//// [/src/src-dogs/tsconfig.tsbuildinfo.readable.baseline.txt]
197197
{
@@ -235,31 +235,38 @@ LassieDog.getDogConfig = () => LASSIE_CONFIG;
235235
},
236236
"../src-types/dogconfig.d.ts": {
237237
"version": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n",
238-
"signature": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n"
238+
"signature": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n",
239+
"impliedFormat": 99
239240
},
240241
"../src-types/index.d.ts": {
241242
"version": "-5608794531-export * from './dogconfig.js';\r\n",
242-
"signature": "-5608794531-export * from './dogconfig.js';\r\n"
243+
"signature": "-5608794531-export * from './dogconfig.js';\r\n",
244+
"impliedFormat": 99
243245
},
244246
"./dogconfig.ts": {
245247
"version": "1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n",
246-
"signature": "1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n"
248+
"signature": "1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n",
249+
"impliedFormat": 99
247250
},
248251
"./dog.ts": {
249252
"version": "6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n",
250-
"signature": "6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n"
253+
"signature": "6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n",
254+
"impliedFormat": 99
251255
},
252256
"./lassie/lassieconfig.ts": {
253257
"version": "4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n",
254-
"signature": "4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n"
258+
"signature": "4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n",
259+
"impliedFormat": 99
255260
},
256261
"./lassie/lassiedog.ts": {
257262
"version": "-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n",
258-
"signature": "-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n"
263+
"signature": "-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n",
264+
"impliedFormat": 99
259265
},
260266
"./index.ts": {
261267
"version": "-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n",
262-
"signature": "-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n"
268+
"signature": "-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n",
269+
"impliedFormat": 99
263270
}
264271
},
265272
"options": {
@@ -325,7 +332,7 @@ LassieDog.getDogConfig = () => LASSIE_CONFIG;
325332
]
326333
},
327334
"version": "FakeTSVersion",
328-
"size": 1802
335+
"size": 2019
329336
}
330337

331338
//// [/src/src-types/dogconfig.d.ts]
@@ -347,7 +354,7 @@ export * from './dogconfig.js';
347354

348355

349356
//// [/src/src-types/tsconfig.tsbuildinfo]
350-
{"program":{"fileNames":["../../lib/lib.es2020.full.d.ts","./dogconfig.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},"-5575793279-export interface DogConfig {\n name: string;\n}","-6189272282-export * from './dogconfig.js';"],"options":{"composite":true,"declaration":true,"module":100},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[[3,1]],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
357+
{"program":{"fileNames":["../../lib/lib.es2020.full.d.ts","./dogconfig.ts","./index.ts"],"fileInfos":[{"version":"-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }","affectsGlobalScope":true,"impliedFormat":1},{"version":"-5575793279-export interface DogConfig {\n name: string;\n}","impliedFormat":99},{"version":"-6189272282-export * from './dogconfig.js';","impliedFormat":99}],"options":{"composite":true,"declaration":true,"module":100},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[[3,1]],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
351358

352359
//// [/src/src-types/tsconfig.tsbuildinfo.readable.baseline.txt]
353360
{
@@ -371,11 +378,13 @@ export * from './dogconfig.js';
371378
},
372379
"./dogconfig.ts": {
373380
"version": "-5575793279-export interface DogConfig {\n name: string;\n}",
374-
"signature": "-5575793279-export interface DogConfig {\n name: string;\n}"
381+
"signature": "-5575793279-export interface DogConfig {\n name: string;\n}",
382+
"impliedFormat": 99
375383
},
376384
"./index.ts": {
377385
"version": "-6189272282-export * from './dogconfig.js';",
378-
"signature": "-6189272282-export * from './dogconfig.js';"
386+
"signature": "-6189272282-export * from './dogconfig.js';",
387+
"impliedFormat": 99
379388
}
380389
},
381390
"options": {
@@ -400,6 +409,6 @@ export * from './dogconfig.js';
400409
]
401410
},
402411
"version": "FakeTSVersion",
403-
"size": 829
412+
"size": 891
404413
}
405414

0 commit comments

Comments
 (0)