Skip to content

Commit f06413b

Browse files
authored
Merge pull request #10035 from zhengbli/9522
Recreate program if baseUrl or paths changed in tsconfig
2 parents 6caa261 + f78b909 commit f06413b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/services/services.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,14 +3090,16 @@ namespace ts {
30903090

30913091
const oldSettings = program && program.getCompilerOptions();
30923092
const newSettings = hostCache.compilationSettings();
3093-
const changesInCompilationSettingsAffectSyntax = oldSettings &&
3093+
const shouldCreateNewSourceFiles = oldSettings &&
30943094
(oldSettings.target !== newSettings.target ||
30953095
oldSettings.module !== newSettings.module ||
30963096
oldSettings.moduleResolution !== newSettings.moduleResolution ||
30973097
oldSettings.noResolve !== newSettings.noResolve ||
30983098
oldSettings.jsx !== newSettings.jsx ||
30993099
oldSettings.allowJs !== newSettings.allowJs ||
3100-
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit);
3100+
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit ||
3101+
oldSettings.baseUrl !== newSettings.baseUrl ||
3102+
!mapIsEqualTo(oldSettings.paths, newSettings.paths));
31013103

31023104
// Now create a new compiler
31033105
const compilerHost: CompilerHost = {
@@ -3149,7 +3151,7 @@ namespace ts {
31493151
const oldSourceFiles = program.getSourceFiles();
31503152
const oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldSettings);
31513153
for (const oldSourceFile of oldSourceFiles) {
3152-
if (!newProgram.getSourceFile(oldSourceFile.fileName) || changesInCompilationSettingsAffectSyntax) {
3154+
if (!newProgram.getSourceFile(oldSourceFile.fileName) || shouldCreateNewSourceFiles) {
31533155
documentRegistry.releaseDocumentWithKey(oldSourceFile.path, oldSettingsKey);
31543156
}
31553157
}
@@ -3183,7 +3185,7 @@ namespace ts {
31833185
// Check if the language version has changed since we last created a program; if they are the same,
31843186
// it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
31853187
// can not be reused. we have to dump all syntax trees and create new ones.
3186-
if (!changesInCompilationSettingsAffectSyntax) {
3188+
if (!shouldCreateNewSourceFiles) {
31873189
// Check if the old program had this file already
31883190
const oldSourceFile = program && program.getSourceFileByPath(path);
31893191
if (oldSourceFile) {

0 commit comments

Comments
 (0)