From 2e57f00169985d006ab439e4ea244c155a629f10 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 6 Jul 2022 10:07:17 -0700 Subject: [PATCH 1/2] Protect against a language service host mutating its underlying source for `getScriptFileNames` --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 8f0e274cba6c9..76071dfba5eec 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1283,7 +1283,7 @@ namespace ts { lastTypesRootVersion = typeRootsVersion; } - const rootFileNames = host.getScriptFileNames(); + const rootFileNames = host.getScriptFileNames().slice(); // Get a fresh cache of the host information const newSettings = host.getCompilationSettings() || getDefaultCompilerOptions(); From e84f0f9e92eba0885d490c5cbb74e06ee6e7261f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 6 Jul 2022 10:48:22 -0700 Subject: [PATCH 2/2] Add comment --- src/services/services.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index 76071dfba5eec..bfa8c73a66e13 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1283,6 +1283,9 @@ namespace ts { lastTypesRootVersion = typeRootsVersion; } + // This array is retained by the program and will be used to determine if the program is up to date, + // so we need to make a copy in case the host mutates the underlying array - otherwise it would look + // like every program always has the host's current list of root files. const rootFileNames = host.getScriptFileNames().slice(); // Get a fresh cache of the host information