@@ -1095,13 +1095,13 @@ namespace ts {
1095
1095
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
1096
1096
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
1097
1097
const maxNodeModulesJsDepth = typeof options . maxNodeModuleJsDepth === "number" ? options . maxNodeModuleJsDepth : 2 ;
1098
- let currentNodeModulesJsDepth = 0 ;
1098
+ let currentNodeModulesDepth = 0 ;
1099
1099
1100
1100
// If a module has some of its imports skipped due to being at the depth limit under node_modules, then track
1101
1101
// this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed.
1102
1102
const modulesWithElidedImports : Map < boolean > = { } ;
1103
1103
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.
1105
1105
const sourceFilesFoundSearchingNodeModules : Map < boolean > = { } ;
1106
1106
1107
1107
const start = new Date ( ) . getTime ( ) ;
@@ -1918,9 +1918,20 @@ namespace ts {
1918
1918
reportFileNamesDifferOnlyInCasingError ( fileName , file . fileName , refFile , refPos , refEnd ) ;
1919
1919
}
1920
1920
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
+ }
1921
1932
// 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 ) {
1924
1935
modulesWithElidedImports [ file . path ] = false ;
1925
1936
processImportedModules ( file , getDirectoryPath ( fileName ) ) ;
1926
1937
}
@@ -2075,13 +2086,17 @@ namespace ts {
2075
2086
const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension ( resolution . resolvedFileName ) ;
2076
2087
2077
2088
if ( isFromNodeModulesSearch ) {
2078
- sourceFilesFoundSearchingNodeModules [ resolvedPath ] = true ;
2089
+ currentNodeModulesDepth ++ ;
2079
2090
}
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
+ }
2082
2097
}
2083
2098
2084
- const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth ;
2099
+ const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth ;
2085
2100
const shouldAddFile = resolution && ! options . noResolve && i < file . imports . length && ! elideImport ;
2086
2101
2087
2102
if ( elideImport ) {
@@ -2096,8 +2111,8 @@ namespace ts {
2096
2111
file . imports [ i ] . end ) ;
2097
2112
}
2098
2113
2099
- if ( isJsFileFromNodeModules ) {
2100
- currentNodeModulesJsDepth -- ;
2114
+ if ( isFromNodeModulesSearch ) {
2115
+ currentNodeModulesDepth -- ;
2101
2116
}
2102
2117
}
2103
2118
}
0 commit comments