File tree Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -3068,9 +3068,11 @@ namespace ts.projectSystem {
3068
3068
projectService . openClientFile ( file1 . path ) ;
3069
3069
3070
3070
const project = projectService . inferredProjects [ 0 ] ;
3071
- const sourceFile = project . getSourceFile ( < Path > file1 . path ) ;
3072
- assert . isTrue ( "test" in sourceFile . resolvedModules ) ;
3073
- assert . equal ( ( < ResolvedModule > sourceFile . resolvedModules [ "test" ] ) . resolvedFileName , moduleFile . path ) ;
3071
+ const sourceFileForFile1 = project . getSourceFile ( < Path > file1 . path ) ;
3072
+ const sourceFileForModuleFile = project . getSourceFile ( < Path > moduleFile . path ) ;
3073
+
3074
+ assert . isNotNull ( sourceFileForFile1 ) ;
3075
+ assert . isNotNull ( sourceFileForModuleFile ) ;
3074
3076
} ) ;
3075
3077
} ) ;
3076
3078
Original file line number Diff line number Diff line change @@ -1072,19 +1072,17 @@ namespace ts.server {
1072
1072
? this . inferredProjects [ 0 ]
1073
1073
: new InferredProject ( this , this . documentRegistry , this . compilerOptionsForInferredProjects ) ;
1074
1074
1075
+ if ( root . scriptKind === ScriptKind . JS || root . scriptKind === ScriptKind . JSX ) {
1076
+ project . isJsInferredProject = true ;
1077
+ }
1078
+
1075
1079
project . addRoot ( root ) ;
1076
1080
1077
1081
this . directoryWatchers . startWatchingContainingDirectoriesForFile (
1078
1082
root . fileName ,
1079
1083
project ,
1080
1084
fileName => this . onConfigFileAddedForInferredProject ( fileName ) ) ;
1081
1085
1082
- if ( root . scriptKind === ScriptKind . JS || root . scriptKind === ScriptKind . JSX ) {
1083
- const options = project . getCompilerOptions ( ) ;
1084
- options . maxNodeModuleJsDepth = 2 ;
1085
- project . setCompilerOptions ( options ) ;
1086
- }
1087
-
1088
1086
project . updateGraph ( ) ;
1089
1087
1090
1088
if ( ! useExistingProject ) {
Original file line number Diff line number Diff line change @@ -566,9 +566,6 @@ namespace ts.server {
566
566
567
567
setCompilerOptions ( compilerOptions : CompilerOptions ) {
568
568
if ( compilerOptions ) {
569
- if ( this . projectKind === ProjectKind . Inferred ) {
570
- compilerOptions . allowJs = true ;
571
- }
572
569
compilerOptions . allowNonTsExtensions = true ;
573
570
if ( changesAffectModuleResolution ( this . compilerOptions , compilerOptions ) ) {
574
571
// reset cached unresolved imports if changes in compiler options affected module resolution
@@ -715,6 +712,26 @@ namespace ts.server {
715
712
}
716
713
} ) ( ) ;
717
714
715
+ private _isJsInferredProject = false ;
716
+ set isJsInferredProject ( newValue : boolean ) {
717
+ if ( newValue && ! this . _isJsInferredProject ) {
718
+ this . setCompilerOptions ( this . getCompilerOptions ( ) ) ;
719
+ }
720
+ this . _isJsInferredProject = newValue ;
721
+ }
722
+
723
+ setCompilerOptions ( newOptions : CompilerOptions ) {
724
+ if ( ! newOptions ) {
725
+ return ;
726
+ }
727
+
728
+ if ( this . _isJsInferredProject && typeof newOptions . maxNodeModuleJsDepth !== "number" ) {
729
+ newOptions . maxNodeModuleJsDepth = 2 ;
730
+ }
731
+ newOptions . allowJs = true ;
732
+ super . setCompilerOptions ( newOptions ) ;
733
+ }
734
+
718
735
// Used to keep track of what directories are watched for this project
719
736
directoriesWatchedForTsconfig : string [ ] = [ ] ;
720
737
You can’t perform that action at this time.
0 commit comments