@@ -2569,6 +2569,153 @@ func TestTscIncremental(t *testing.T) {
25692569 }
25702570}
25712571
2572+ func TestTscIncrementalDeletion (t * testing.T ) {
2573+ t .Parallel ()
2574+ for _ , mode := range []struct {
2575+ name string
2576+ args []string
2577+ }{
2578+ {},
2579+ {" with single threaded" , []string {"--singleThreaded" }},
2580+ {" with one checker" , []string {"--checkers" , "1" }},
2581+ } {
2582+ config := func (options string ) string {
2583+ return `{"compilerOptions":{"incremental":true,"noEmit":true,"types":[]` + options + `},"files":["a.ts"]}`
2584+ }
2585+ (& tscInput {
2586+ subScenario : "lib and target changes delete mixed library files" + mode .name ,
2587+ commandLineArgs : mode .args ,
2588+ files : FileMap {
2589+ "/home/src/workspaces/project/tsconfig.json" : config (`,"target":"esnext"` ),
2590+ "/home/src/workspaces/project/a.ts" : `export const values = [3, 1, 2].toSorted();` ,
2591+ getTestLibPathFor ("es5" ): tscDefaultLibContent ,
2592+ getTestLibPathFor ("esnext.array" ): stringtestutil .Dedent (`
2593+ /// <reference no-default-lib="true"/>
2594+ interface Array<T> {
2595+ toSorted(): T[];
2596+ }
2597+ ` ),
2598+ getTestLibPathFor ("decorators" ): stringtestutil .Dedent (`
2599+ /// <reference no-default-lib="true"/>
2600+ export {};
2601+ ` ),
2602+ getTestLibPathFor ("esnext.full" ): stringtestutil .Dedent (`
2603+ /// <reference no-default-lib="true"/>
2604+ /// <reference lib="es5"/>
2605+ /// <reference lib="esnext.array"/>
2606+ /// <reference lib="decorators"/>
2607+ ` ),
2608+ getTestLibPathFor ("es2020" ): stringtestutil .Dedent (`
2609+ /// <reference no-default-lib="true"/>
2610+ /// <reference lib="es5"/>
2611+ ` ),
2612+ getTestLibPathFor ("es2020.full" ): stringtestutil .Dedent (`
2613+ /// <reference no-default-lib="true"/>
2614+ /// <reference lib="es5"/>
2615+ ` ),
2616+ },
2617+ edits : []* tscEdit {
2618+ {caption : "narrow lib" , edit : func (sys * TestSys ) {
2619+ sys .writeFileNoError ("/home/src/workspaces/project/tsconfig.json" , config (`,"target":"esnext","lib":["es2020"]` ))
2620+ }},
2621+ noChange ,
2622+ {caption : "restore lib" , edit : func (sys * TestSys ) {
2623+ sys .writeFileNoError ("/home/src/workspaces/project/tsconfig.json" , config (`,"target":"esnext"` ))
2624+ }},
2625+ {caption : "narrow target" , edit : func (sys * TestSys ) {
2626+ sys .writeFileNoError ("/home/src/workspaces/project/tsconfig.json" , config (`,"target":"es2020"` ))
2627+ }},
2628+ noChange ,
2629+ {caption : "restore target" , edit : func (sys * TestSys ) {
2630+ sys .writeFileNoError ("/home/src/workspaces/project/tsconfig.json" , config (`,"target":"esnext"` ))
2631+ }},
2632+ noChange ,
2633+ },
2634+ }).run (t , "incremental" )
2635+ (& tscInput {
2636+ subScenario : "mixed file deletion with add and change" + mode .name ,
2637+ commandLineArgs : mode .args ,
2638+ files : FileMap {
2639+ "/home/src/workspaces/project/tsconfig.json" : `{"compilerOptions":{"incremental":true,"noEmit":true,"types":[]}}` ,
2640+ "/home/src/workspaces/project/consumer.ts" : `declare const value: RemovedGlobal; value.property;` ,
2641+ "/home/src/workspaces/project/global.d.ts" : `interface RemovedGlobal { property: string; }` ,
2642+ "/home/src/workspaces/project/module.d.ts" : `export interface ModuleOnly { property: string; }` ,
2643+ "/home/src/workspaces/project/changed.ts" : `export const changed = 1;` ,
2644+ },
2645+ edits : []* tscEdit {
2646+ {caption : "delete global and non-global files while adding and changing sources" , edit : func (sys * TestSys ) {
2647+ sys .removeNoError ("/home/src/workspaces/project/global.d.ts" )
2648+ sys .removeNoError ("/home/src/workspaces/project/module.d.ts" )
2649+ sys .replaceFileText ("/home/src/workspaces/project/changed.ts" , "1" , "2" )
2650+ sys .writeFileNoError ("/home/src/workspaces/project/added.ts" , `export const added = 1;` )
2651+ }},
2652+ noChange ,
2653+ {caption : "restore global file" , edit : func (sys * TestSys ) {
2654+ sys .writeFileNoError ("/home/src/workspaces/project/global.d.ts" , `interface RemovedGlobal { property: number; }` )
2655+ }},
2656+ {caption : "delete ordinary source file" , edit : func (sys * TestSys ) {
2657+ sys .removeNoError ("/home/src/workspaces/project/added.ts" )
2658+ }},
2659+ noChange ,
2660+ },
2661+ }).run (t , "incremental" )
2662+ for _ , cleared := range []bool {false , true } {
2663+ library := tscDefaultLibContent + "\n interface LibraryConsumer { property: RemovedGlobal; }"
2664+ global := "interface RemovedGlobal {}"
2665+ if cleared {
2666+ library = tscDefaultLibContent + "\n interface Shared<T> {}"
2667+ global = "interface Shared<T, U> {}"
2668+ }
2669+ (& tscInput {
2670+ subScenario : fmt .Sprintf ("retained library diagnostics after global deletion cleared %t%s" , cleared , mode .name ),
2671+ commandLineArgs : mode .args ,
2672+ files : FileMap {
2673+ "/home/src/workspaces/project/tsconfig.json" : `{"compilerOptions":{"incremental":true,"noEmit":true,"types":[],"lib":["es5"]}}` ,
2674+ "/home/src/workspaces/project/consumer.ts" : "export const unchanged = 1;" ,
2675+ "/home/src/workspaces/project/global.d.ts" : global ,
2676+ "/home/src/workspaces/project/module.d.ts" : "export interface Unrelated {}" ,
2677+ getTestLibPathFor ("es5" ): library ,
2678+ },
2679+ edits : []* tscEdit {
2680+ {caption : "delete global and module declarations" , edit : func (sys * TestSys ) {
2681+ sys .removeNoError ("/home/src/workspaces/project/global.d.ts" )
2682+ sys .removeNoError ("/home/src/workspaces/project/module.d.ts" )
2683+ }},
2684+ noChange ,
2685+ {caption : "restore global declaration" , edit : func (sys * TestSys ) {
2686+ sys .writeFileNoError ("/home/src/workspaces/project/global.d.ts" , global )
2687+ }},
2688+ noChange ,
2689+ },
2690+ }).run (t , "incremental" )
2691+ }
2692+ }
2693+ for _ , composite := range []bool {false , true } {
2694+ (& tscInput {
2695+ subScenario : fmt .Sprintf ("unchecked deleted paths with no emit composite %t" , composite ),
2696+ files : FileMap {
2697+ "/home/src/workspaces/project/tsconfig.json" : fmt .Sprintf (`{"compilerOptions":{"incremental":true,"noCheck":true,"noEmit":true,"composite":%t,"types":[]}}` , composite ),
2698+ "/home/src/workspaces/project/stable.ts" : "export const stable = 1;" ,
2699+ },
2700+ edits : []* tscEdit {
2701+ {caption : "add unchecked sources" , edit : func (sys * TestSys ) {
2702+ sys .writeFileNoError ("/home/src/workspaces/project/first.ts" , "export const first = 1;" )
2703+ sys .writeFileNoError ("/home/src/workspaces/project/second.ts" , "export const second = 1;" )
2704+ }},
2705+ {caption : "delete unchecked sources" , edit : func (sys * TestSys ) {
2706+ sys .removeNoError ("/home/src/workspaces/project/first.ts" )
2707+ sys .removeNoError ("/home/src/workspaces/project/second.ts" )
2708+ }},
2709+ noChange ,
2710+ {caption : "enable checking and emit" , edit : func (sys * TestSys ) {
2711+ sys .replaceFileText ("/home/src/workspaces/project/tsconfig.json" , `"noCheck":true,"noEmit":true` , `"noCheck":false,"noEmit":false` )
2712+ }},
2713+ noChange ,
2714+ },
2715+ }).run (t , "incremental" )
2716+ }
2717+ }
2718+
25722719func TestTscLibraryResolution (t * testing.T ) {
25732720 t .Parallel ()
25742721 getTscLibraryResolutionFileMap := func (libReplacement bool ) FileMap {
0 commit comments