mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Use inherited setCompilerOptions for inferred project
This commit is contained in:
@@ -1072,6 +1072,10 @@ namespace ts.server {
|
||||
? this.inferredProjects[0]
|
||||
: new InferredProject(this, this.documentRegistry, this.compilerOptionsForInferredProjects);
|
||||
|
||||
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
|
||||
project.isJsInferredProject = true;
|
||||
}
|
||||
|
||||
project.addRoot(root);
|
||||
|
||||
this.directoryWatchers.startWatchingContainingDirectoriesForFile(
|
||||
@@ -1079,12 +1083,6 @@ namespace ts.server {
|
||||
project,
|
||||
fileName => this.onConfigFileAddedForInferredProject(fileName));
|
||||
|
||||
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
|
||||
const options = project.getCompilerOptions();
|
||||
options.maxNodeModuleJsDepth = 2;
|
||||
project.setCompilerOptions(options);
|
||||
}
|
||||
|
||||
project.updateGraph();
|
||||
|
||||
if (!useExistingProject) {
|
||||
|
||||
@@ -566,9 +566,6 @@ namespace ts.server {
|
||||
|
||||
setCompilerOptions(compilerOptions: CompilerOptions) {
|
||||
if (compilerOptions) {
|
||||
if (this.projectKind === ProjectKind.Inferred) {
|
||||
compilerOptions.allowJs = true;
|
||||
}
|
||||
compilerOptions.allowNonTsExtensions = true;
|
||||
if (changesAffectModuleResolution(this.compilerOptions, compilerOptions)) {
|
||||
// reset cached unresolved imports if changes in compiler options affected module resolution
|
||||
@@ -715,6 +712,26 @@ namespace ts.server {
|
||||
}
|
||||
})();
|
||||
|
||||
private _isJsInferredProject = false;
|
||||
set isJsInferredProject(newValue: boolean) {
|
||||
if (newValue && !this._isJsInferredProject) {
|
||||
this.setCompilerOptions(this.getCompilerOptions());
|
||||
}
|
||||
this._isJsInferredProject = newValue;
|
||||
}
|
||||
|
||||
setCompilerOptions(newOptions: CompilerOptions) {
|
||||
if (!newOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isJsInferredProject && typeof newOptions.maxNodeModuleJsDepth !== "number") {
|
||||
newOptions.maxNodeModuleJsDepth = 2;
|
||||
}
|
||||
newOptions.allowJs = true;
|
||||
super.setCompilerOptions(newOptions);
|
||||
}
|
||||
|
||||
// Used to keep track of what directories are watched for this project
|
||||
directoriesWatchedForTsconfig: string[] = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user