@@ -1095,13 +1095,13 @@ namespace ts {
10951095 // As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
10961096 // The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
10971097 const maxNodeModulesJsDepth = typeof options . maxNodeModuleJsDepth === "number" ? options . maxNodeModuleJsDepth : 2 ;
1098- let currentNodeModulesJsDepth = 0 ;
1098+ let currentNodeModulesDepth = 0 ;
10991099
11001100 // If a module has some of its imports skipped due to being at the depth limit under node_modules, then track
11011101 // this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed.
11021102 const modulesWithElidedImports : Map < boolean > = { } ;
11031103
1104- // Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled.
1104+ // Track source files that are source files found by searching under node_modules, as these shouldn't be compiled.
11051105 const sourceFilesFoundSearchingNodeModules : Map < boolean > = { } ;
11061106
11071107 const start = new Date ( ) . getTime ( ) ;
@@ -1918,9 +1918,20 @@ namespace ts {
19181918 reportFileNamesDifferOnlyInCasingError ( fileName , file . fileName , refFile , refPos , refEnd ) ;
19191919 }
19201920
1921+ // If the file was previously found via a node_modules search, but is now being processed as a root file,
1922+ // then everything it sucks in may also be marked incorrectly, and needs to be checked again.
1923+ if ( file && lookUp ( sourceFilesFoundSearchingNodeModules , file . path ) && currentNodeModulesDepth == 0 ) {
1924+ if ( ! options . noResolve ) {
1925+ processReferencedFiles ( file , getDirectoryPath ( fileName ) , isDefaultLib ) ;
1926+ processTypeReferenceDirectives ( file ) ;
1927+ }
1928+
1929+ modulesWithElidedImports [ file . path ] = false ;
1930+ processImportedModules ( file , getDirectoryPath ( fileName ) ) ;
1931+ }
19211932 // See if we need to reprocess the imports due to prior skipped imports
1922- if ( file && lookUp ( modulesWithElidedImports , file . path ) ) {
1923- if ( currentNodeModulesJsDepth < maxNodeModulesJsDepth ) {
1933+ else if ( file && lookUp ( modulesWithElidedImports , file . path ) ) {
1934+ if ( currentNodeModulesDepth < maxNodeModulesJsDepth ) {
19241935 modulesWithElidedImports [ file . path ] = false ;
19251936 processImportedModules ( file , getDirectoryPath ( fileName ) ) ;
19261937 }
@@ -2075,13 +2086,17 @@ namespace ts {
20752086 const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension ( resolution . resolvedFileName ) ;
20762087
20772088 if ( isFromNodeModulesSearch ) {
2078- sourceFilesFoundSearchingNodeModules [ resolvedPath ] = true ;
2089+ currentNodeModulesDepth ++ ;
20792090 }
2080- if ( isJsFileFromNodeModules ) {
2081- currentNodeModulesJsDepth ++ ;
2091+
2092+ if ( currentNodeModulesDepth > 0 ) {
2093+ // If its already present with false, its a root file also. Don't override this.
2094+ if ( ! hasProperty ( sourceFilesFoundSearchingNodeModules , resolvedPath ) ) {
2095+ sourceFilesFoundSearchingNodeModules [ resolvedPath ] = true ;
2096+ }
20822097 }
20832098
2084- const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth ;
2099+ const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth ;
20852100 const shouldAddFile = resolution && ! options . noResolve && i < file . imports . length && ! elideImport ;
20862101
20872102 if ( elideImport ) {
@@ -2096,8 +2111,8 @@ namespace ts {
20962111 file . imports [ i ] . end ) ;
20972112 }
20982113
2099- if ( isJsFileFromNodeModules ) {
2100- currentNodeModulesJsDepth -- ;
2114+ if ( isFromNodeModulesSearch ) {
2115+ currentNodeModulesDepth -- ;
21012116 }
21022117 }
21032118 }
0 commit comments