Skip to content

Commit 8002369

Browse files
authored
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
1 parent 8687940 commit 8002369

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/services/services.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,10 @@ namespace ts {
12831283
lastTypesRootVersion = typeRootsVersion;
12841284
}
12851285

1286-
const rootFileNames = host.getScriptFileNames();
1286+
// This array is retained by the program and will be used to determine if the program is up to date,
1287+
// so we need to make a copy in case the host mutates the underlying array - otherwise it would look
1288+
// like every program always has the host's current list of root files.
1289+
const rootFileNames = host.getScriptFileNames().slice();
12871290

12881291
// Get a fresh cache of the host information
12891292
const newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();

0 commit comments

Comments
 (0)