@@ -35,6 +35,7 @@ export interface TestTscCompile extends TestTscCompileLikeBase {
35
35
baselineReadFileCalls ?: boolean ;
36
36
baselinePrograms ?: boolean ;
37
37
baselineDependencies ?: boolean ;
38
+ baselineModulesAndTypeRefs ?: boolean ;
38
39
}
39
40
40
41
export type CommandLineProgram = [ ts . Program , ts . BuilderProgram ?] ;
@@ -206,6 +207,11 @@ export function testTscCompile(input: TestTscCompile) {
206
207
baselinePrograms ( baseline , getPrograms ! , ts . emptyArray , baselineDependencies ) ;
207
208
sys . write ( baseline . join ( "\n" ) ) ;
208
209
}
210
+ if ( input . baselineModulesAndTypeRefs ) {
211
+ const baseline : string [ ] = [ ] ;
212
+ baselineModulesAndTypeRefs ( baseline , getPrograms ! ( ) ) ;
213
+ sys . write ( baseline . join ( "\n" ) ) ;
214
+ }
209
215
if ( baselineReadFileCalls ) {
210
216
sys . write ( `readFiles:: ${ JSON . stringify ( actualReadFileMap , /*replacer*/ undefined , " " ) } ` ) ;
211
217
}
@@ -249,6 +255,40 @@ function storeDtsSignatures(sys: TscCompileSystem, programs: readonly CommandLin
249
255
}
250
256
}
251
257
258
+ function baselineCache < T > ( baseline : string [ ] , cacheType : string , cache : ts . ModeAwareCache < T > | undefined ) {
259
+ if ( ! cache ?. size ( ) ) return ;
260
+ baseline . push ( `${ cacheType } :` ) ;
261
+ cache . forEach ( ( resolved , key , mode ) => baseline . push ( `${ key } : ${ mode ? ts . getNameOfCompilerOptionValue ( mode , ts . moduleOptionDeclaration . type ) + ": " : "" } ${ JSON . stringify (
262
+ { ...resolved , refCount : undefined , files : undefined , isInvalidated : undefined , } ,
263
+ /*replacer*/ undefined ,
264
+ 2 ,
265
+ ) } `) ) ;
266
+ }
267
+
268
+ export function baselineModulesAndTypeRefs ( baseline : string [ ] , programs : readonly CommandLineProgram [ ] ) {
269
+ for ( const [ program ] of programs ) {
270
+ for ( const f of program . getSourceFiles ( ) ) {
271
+ if ( ! f . resolvedModules && ! f . resolvedTypeReferenceDirectiveNames && ! f . packageJsonScope ) continue ;
272
+ baseline . push ( `File: ${ f . fileName } ` ) ;
273
+ if ( f . packageJsonScope ) {
274
+ baseline . push ( `packageJsonScope:: ${ JSON . stringify (
275
+ f . packageJsonScope ,
276
+ /*replacer*/ undefined ,
277
+ 2 ,
278
+ ) } `) ;
279
+ }
280
+ baselineCache ( baseline , "resolvedModules" , f . resolvedModules ) ;
281
+ baselineCache ( baseline , "resolvedTypeReferenceDirectiveNames" , f . resolvedTypeReferenceDirectiveNames ) ;
282
+ baseline . push ( "" ) ;
283
+ }
284
+ const autoTypes = program . getAutomaticTypeDirectiveResolutions ( ) ;
285
+ if ( autoTypes . size ( ) ) {
286
+ baselineCache ( baseline , "automaticTypeDirectiveResolutions" , autoTypes ) ;
287
+ baseline . push ( "" ) ;
288
+ }
289
+ }
290
+ }
291
+
252
292
export function baselinePrograms ( baseline : string [ ] , getPrograms : ( ) => readonly CommandLineProgram [ ] , oldPrograms : readonly ( CommandLineProgram | undefined ) [ ] , baselineDependencies : boolean | undefined ) {
253
293
const programs = getPrograms ( ) ;
254
294
for ( let i = 0 ; i < programs . length ; i ++ ) {
@@ -903,7 +943,7 @@ export interface VerifyTscWithEditsInput extends TestTscCompile {
903
943
*/
904
944
export function verifyTsc ( {
905
945
subScenario, fs, scenario, commandLineArgs, environmentVariables,
906
- baselineSourceMap, modifyFs, baselineReadFileCalls, baselinePrograms,
946
+ baselineSourceMap, modifyFs, baselineReadFileCalls, baselinePrograms, baselineDependencies , baselineModulesAndTypeRefs ,
907
947
edits
908
948
} : VerifyTscWithEditsInput ) {
909
949
describe ( `tsc ${ commandLineArgs . join ( " " ) } ${ scenario } :: ${ subScenario } ` , ( ) => {
@@ -921,6 +961,8 @@ export function verifyTsc({
921
961
baselineSourceMap,
922
962
baselineReadFileCalls,
923
963
baselinePrograms,
964
+ baselineDependencies,
965
+ baselineModulesAndTypeRefs,
924
966
environmentVariables,
925
967
} ) ;
926
968
edits ?. forEach ( (
@@ -937,6 +979,8 @@ export function verifyTsc({
937
979
baselineSourceMap,
938
980
baselineReadFileCalls,
939
981
baselinePrograms,
982
+ baselineDependencies,
983
+ baselineModulesAndTypeRefs,
940
984
environmentVariables,
941
985
} ) ) ;
942
986
} ) ;
0 commit comments