From 8002369871ec706fe6f04606e8850c224e61bbca Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 6 Jul 2022 10:49:01 -0700 Subject: [PATCH] Protect against a language service host mutating its underlying source for `getScriptFileNames` (#49813) * Protect against a language service host mutating its underlying source for `getScriptFileNames` * Add comment --- src/services/services.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 8f0e274cba6..bfa8c73a66e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1283,7 +1283,10 @@ namespace ts { lastTypesRootVersion = typeRootsVersion; } - const rootFileNames = host.getScriptFileNames(); + // 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 const newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();