@@ -150,6 +150,7 @@ type Project struct {
150
150
// rootFileNames was a map from Path to { NormalizedPath, ScriptInfo? } in the original code.
151
151
// But the ProjectService owns script infos, so it's not clear why there was an extra pointer.
152
152
rootFileNames * collections.OrderedMap [tspath.Path , string ]
153
+ rootJSFileCount int
153
154
compilerOptions * core.CompilerOptions
154
155
typeAcquisition * core.TypeAcquisition
155
156
parsedCommandLine * tsoptions.ParsedCommandLine
@@ -571,6 +572,12 @@ func (p *Project) updateProgram() bool {
571
572
} else {
572
573
rootFileNames := p .GetRootFileNames ()
573
574
compilerOptions := p .compilerOptions
575
+
576
+ if compilerOptions .MaxNodeModuleJsDepth == nil && p .rootJSFileCount > 0 {
577
+ compilerOptions = compilerOptions .Clone ()
578
+ compilerOptions .MaxNodeModuleJsDepth = ptrTo (2 )
579
+ }
580
+
574
581
p .programConfig = & tsoptions.ParsedCommandLine {
575
582
ParsedConfig : & core.ParsedOptions {
576
583
CompilerOptions : compilerOptions ,
@@ -875,7 +882,7 @@ func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool) {
875
882
p .mu .Lock ()
876
883
defer p .mu .Unlock ()
877
884
if p .isRoot (info ) && p .kind == KindInferred {
878
- p .rootFileNames . Delete (info .path )
885
+ p .deleteRootFileNameOfInferred (info .path )
879
886
p .setTypeAcquisition (nil )
880
887
p .programConfig = nil
881
888
}
@@ -898,13 +905,12 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) {
898
905
if p .isRoot (info ) {
899
906
panic ("script info is already a root" )
900
907
}
901
- p .rootFileNames . Set (info .path , info .fileName )
908
+ p .setRootFileNameOfInferred (info .path , info .fileName )
902
909
p .programConfig = nil
903
910
p .setTypeAcquisition (nil )
904
911
// !!!
905
912
// if p.kind == KindInferred {
906
913
// p.host.startWatchingConfigFilesForInferredProjectRoot(info.path);
907
- // // handle JS toggling
908
914
// }
909
915
info .attachToProject (p )
910
916
p .markAsDirtyLocked ()
@@ -964,6 +970,33 @@ func (p *Project) setRootFiles(rootFileNames []string) {
964
970
}
965
971
}
966
972
973
+ func (p * Project ) setRootFileNameOfInferred (path tspath.Path , fileName string ) {
974
+ if p .kind != KindInferred {
975
+ panic ("setRootFileNameOfInferred called on non-inferred project" )
976
+ }
977
+
978
+ has := p .rootFileNames .Has (path )
979
+ p .rootFileNames .Set (path , fileName )
980
+ if ! has && tspath .HasJSFileExtension (fileName ) {
981
+ p .rootJSFileCount ++
982
+ }
983
+ }
984
+
985
+ func (p * Project ) deleteRootFileNameOfInferred (path tspath.Path ) {
986
+ if p .kind != KindInferred {
987
+ panic ("deleteRootFileNameOfInferred called on non-inferred project" )
988
+ }
989
+
990
+ fileName , ok := p .rootFileNames .Get (path )
991
+ if ! ok {
992
+ return
993
+ }
994
+ p .rootFileNames .Delete (path )
995
+ if tspath .HasJSFileExtension (fileName ) {
996
+ p .rootJSFileCount --
997
+ }
998
+ }
999
+
967
1000
func (p * Project ) clearSourceMapperCache () {
968
1001
// !!!
969
1002
}
@@ -1080,6 +1113,7 @@ func (p *Project) Close() {
1080
1113
}
1081
1114
}
1082
1115
p .rootFileNames = nil
1116
+ p .rootJSFileCount = 0
1083
1117
p .parsedCommandLine = nil
1084
1118
p .programConfig = nil
1085
1119
p .checkerPool = nil
0 commit comments