@@ -3181,7 +3181,7 @@ namespace ts.projectSystem {
3181
3181
const projectLocation = "/user/username/projects/project" ;
3182
3182
const file1 : FileOrFolder = {
3183
3183
path : `${ projectLocation } /src/file1.ts` ,
3184
- content : `import { y } from "./file1 "; let x = 10;`
3184
+ content : `import { y } from "./file2 "; let x = 10;`
3185
3185
} ;
3186
3186
const file2 : FileOrFolder = {
3187
3187
path : `${ projectLocation } /src/file2.ts` ,
@@ -3259,6 +3259,53 @@ namespace ts.projectSystem {
3259
3259
// Allow allowNonTsExtensions will be set to true for deferred extensions.
3260
3260
assert . isTrue ( configuredProject . getCompilerOptions ( ) . allowNonTsExtensions ) ;
3261
3261
} ) ;
3262
+
3263
+ it ( "Orphan source files are handled correctly on watch trigger" , ( ) => {
3264
+ const projectLocation = "/user/username/projects/project" ;
3265
+ const file1 : FileOrFolder = {
3266
+ path : `${ projectLocation } /src/file1.ts` ,
3267
+ content : `export let x = 10;`
3268
+ } ;
3269
+ const file2 : FileOrFolder = {
3270
+ path : `${ projectLocation } /src/file2.ts` ,
3271
+ content : "export let y = 10;"
3272
+ } ;
3273
+ const configContent1 = JSON . stringify ( {
3274
+ files : [ "src/file1.ts" , "src/file2.ts" ]
3275
+ } ) ;
3276
+ const config : FileOrFolder = {
3277
+ path : `${ projectLocation } /tsconfig.json` ,
3278
+ content : configContent1
3279
+ } ;
3280
+ const files = [ file1 , file2 , libFile , config ] ;
3281
+ const host = createServerHost ( files ) ;
3282
+ const service = createProjectService ( host ) ;
3283
+ service . openClientFile ( file1 . path ) ;
3284
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) , [ file1 . path , file2 . path , libFile . path , config . path ] ) ;
3285
+
3286
+ const configContent2 = JSON . stringify ( {
3287
+ files : [ "src/file1.ts" ]
3288
+ } ) ;
3289
+ config . content = configContent2 ;
3290
+ host . reloadFS ( files ) ;
3291
+ host . runQueuedTimeoutCallbacks ( ) ;
3292
+
3293
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) , [ file1 . path , libFile . path , config . path ] ) ;
3294
+ verifyFile2InfoIsOrphan ( ) ;
3295
+
3296
+ file2 . content += "export let z = 10;" ;
3297
+ host . reloadFS ( files ) ;
3298
+ host . runQueuedTimeoutCallbacks ( ) ;
3299
+
3300
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) , [ file1 . path , libFile . path , config . path ] ) ;
3301
+ verifyFile2InfoIsOrphan ( ) ;
3302
+
3303
+ function verifyFile2InfoIsOrphan ( ) {
3304
+ const info = service . getScriptInfoForPath ( file2 . path as Path ) ;
3305
+ assert . isDefined ( info ) ;
3306
+ assert . equal ( info . containingProjects . length , 0 ) ;
3307
+ }
3308
+ } ) ;
3262
3309
} ) ;
3263
3310
3264
3311
describe ( "tsserverProjectSystem Proper errors" , ( ) => {
0 commit comments