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
This commit is contained in:
Andrew Branch 2022-07-06 10:49:01 -07:00 committed by GitHub
parent 8687940398
commit 8002369871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();