Skip to content

Commit 28603e0

Browse files
committed
More updates to program reuse with different option changes
1 parent 155cbf9 commit 28603e0

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ namespace ts {
357357
name: "lib",
358358
type: libMap
359359
},
360-
affectsModuleResolution: true,
360+
affectsProgramStructure: true,
361361
showInSimplifiedHelpView: true,
362362
category: Diagnostics.Basic_Options,
363363
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation,
@@ -701,7 +701,6 @@ namespace ts {
701701
name: "types",
702702
type: "string"
703703
},
704-
affectsModuleResolution: true,
705704
showInSimplifiedHelpView: true,
706705
category: Diagnostics.Module_Resolution_Options,
707706
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation,
@@ -871,7 +870,7 @@ namespace ts {
871870
{
872871
name: "noLib",
873872
type: "boolean",
874-
affectsModuleResolution: true,
873+
affectsProgramStructure: true,
875874
category: Diagnostics.Advanced_Options,
876875
description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts,
877876
// We are not returning a sourceFile for lib file when asked by the program,
@@ -898,7 +897,7 @@ namespace ts {
898897
{
899898
name: "disableSizeLimit",
900899
type: "boolean",
901-
affectsSourceFile: true,
900+
affectsProgramStructure: true,
902901
category: Diagnostics.Advanced_Options,
903902
description: Diagnostics.Disable_size_limitations_on_JavaScript_projects
904903
},
@@ -1070,6 +1069,10 @@ namespace ts {
10701069
export const sourceFileAffectingCompilerOptions: readonly CommandLineOption[] = optionDeclarations.filter(option =>
10711070
!!option.affectsSourceFile || !!option.affectsModuleResolution || !!option.affectsBindDiagnostics);
10721071

1072+
/* @internal */
1073+
export const optionsAffectingProgramStructure: readonly CommandLineOption[] =
1074+
optionDeclarations.filter(option => !!option.affectsProgramStructure);
1075+
10731076
/* @internal */
10741077
export const transpileOptionValueCompilerOptions: readonly CommandLineOption[] = optionDeclarations.filter(option =>
10751078
hasProperty(option, "transpileOptionValue"));

src/compiler/program.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,7 @@ namespace ts {
668668
if (!program) return false;
669669
// If any compiler options change, we can't reuse old source file even if version match
670670
// The change in options like these could result in change in syntax tree or `sourceFile.bindDiagnostics`.
671-
const oldOptions = program.getCompilerOptions();
672-
return !!sourceFileAffectingCompilerOptions.some(option =>
673-
!isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
671+
return optionsHaveChanges(program.getCompilerOptions(), newOptions, sourceFileAffectingCompilerOptions);
674672
}
675673

676674
function createCreateProgramOptions(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): CreateProgramOptions {
@@ -1427,7 +1425,7 @@ namespace ts {
14271425

14281426
if (!arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
14291427
// 'lib' references has changed. Matches behavior in changesAffectModuleResolution
1430-
return StructureIsReused.Not;
1428+
structureIsReused = StructureIsReused.SafeModules;
14311429
}
14321430

14331431
if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
@@ -1523,7 +1521,7 @@ namespace ts {
15231521
return structureIsReused;
15241522
}
15251523

1526-
if (host.hasChangedAutomaticTypeDirectiveNames?.()) {
1524+
if (changesAffectingProgramStructure(oldOptions, options) || host.hasChangedAutomaticTypeDirectiveNames?.()) {
15271525
return StructureIsReused.SafeModules;
15281526
}
15291527

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6003,6 +6003,7 @@ namespace ts {
60036003
affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics
60046004
affectsEmit?: true; // true if the options affects emit
60056005
transpileOptionValue?: boolean | undefined; // If set this means that the option should be set to this value when transpiling
6006+
affectsProgramStructure?: true; // true if program should be reconstructed from root files if option changes and does not affect module resolution as affectsModuleResolution indirectly means program needs to reconstructed
60066007
}
60076008

60086009
/* @internal */

src/compiler/utilities.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ namespace ts {
9696
}
9797

9898
export function optionsHaveModuleResolutionChanges(oldOptions: CompilerOptions, newOptions: CompilerOptions) {
99-
return moduleResolutionOptionDeclarations.some(o =>
99+
return optionsHaveChanges(oldOptions, newOptions, moduleResolutionOptionDeclarations);
100+
}
101+
102+
export function changesAffectingProgramStructure(oldOptions: CompilerOptions, newOptions: CompilerOptions) {
103+
return optionsHaveChanges(oldOptions, newOptions, optionsAffectingProgramStructure);
104+
}
105+
106+
export function optionsHaveChanges(oldOptions: CompilerOptions, newOptions: CompilerOptions, optionDeclarations: readonly CommandLineOption[]) {
107+
return oldOptions !== newOptions && optionDeclarations.some(o =>
100108
!isJsonEqual(getCompilerOptionValue(oldOptions, o), getCompilerOptionValue(newOptions, o)));
101109
}
102110

@@ -5969,13 +5977,11 @@ namespace ts {
59695977
}
59705978

59715979
export function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
5972-
return oldOptions !== newOptions &&
5973-
semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
5980+
return optionsHaveChanges(oldOptions, newOptions, semanticDiagnosticsOptionDeclarations);
59745981
}
59755982

59765983
export function compilerOptionsAffectEmit(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
5977-
return oldOptions !== newOptions &&
5978-
affectsEmitOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
5984+
return optionsHaveChanges(oldOptions, newOptions, affectsEmitOptionDeclarations);
59795985
}
59805986

59815987
export function getCompilerOptionValue(options: CompilerOptions, option: CommandLineOption): unknown {

tests/baselines/reference/tscWatch/programUpdates/correctly-handles-changes-in-lib-section-of-config-file.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Output::
8888

8989
Program root files: ["/src/app.ts"]
9090
Program options: {"module":1,"target":1,"noImplicitAny":true,"sourceMap":false,"lib":["lib.es5.d.ts","lib.es2015.promise.d.ts"],"watch":true,"project":"/src/tsconfig.json","configFilePath":"/src/tsconfig.json"}
91-
Program structureReused: Not
91+
Program structureReused: SafeModules
9292
Program files::
9393
/compiler/lib.es5.d.ts
9494
/compiler/lib.es2015.promise.d.ts
@@ -112,10 +112,10 @@ WatchedFiles::
112112
FsWatches::
113113

114114
FsWatchesRecursive::
115-
/src:
116-
{"directoryName":"/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
117115
/src/node_modules/@types:
118116
{"directoryName":"/src/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
117+
/src:
118+
{"directoryName":"/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
119119

120120
exitCode:: ExitStatus.undefined
121121

0 commit comments

Comments
 (0)