diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index dbf9bf670e6..a766a9c4230 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -3067,12 +3067,15 @@ namespace ts.projectSystem { const projectService = createProjectService(host); projectService.openClientFile(file1.path); - const project = projectService.inferredProjects[0]; - const sourceFileForFile1 = project.getSourceFile(file1.path); - const sourceFileForModuleFile = project.getSourceFile(moduleFile.path); + let project = projectService.inferredProjects[0]; + let options = project.getCompilerOptions(); + assert.isTrue(options.maxNodeModuleJsDepth === 2); - assert.isNotNull(sourceFileForFile1); - assert.isNotNull(sourceFileForModuleFile); + // Assert the option sticks + projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES2016 }); + project = projectService.inferredProjects[0]; + options = project.getCompilerOptions(); + assert.isTrue(options.maxNodeModuleJsDepth === 2); }); }); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index eba0dbb119c..2b87fdf1cc7 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1073,7 +1073,7 @@ namespace ts.server { : new InferredProject(this, this.documentRegistry, this.compilerOptionsForInferredProjects); if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) { - project.isJsInferredProject = true; + project.setAsJsInferredProject(); } project.addRoot(root); diff --git a/src/server/project.ts b/src/server/project.ts index ca3950a48a8..5178820b3c4 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -713,14 +713,14 @@ namespace ts.server { })(); private _isJsInferredProject = false; - set isJsInferredProject(newValue: boolean) { - if (newValue && !this._isJsInferredProject) { - this.setCompilerOptions(this.getCompilerOptions()); - } - this._isJsInferredProject = newValue; + + setAsJsInferredProject() { + this._isJsInferredProject = true; + this.setCompilerOptions(); } - setCompilerOptions(newOptions: CompilerOptions) { + setCompilerOptions(newOptions?: CompilerOptions) { + newOptions = newOptions ? newOptions : this.getCompilerOptions(); if (!newOptions) { return; }