Skip to content

[vfs] Guard against script filenames being stored as reference #2522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/typescript-vfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TS = typeof import("typescript")
let hasLocalStorage = false
try {
hasLocalStorage = typeof localStorage !== `undefined`
} catch (error) {}
} catch (error) { }

const hasProcess = typeof process !== `undefined`
const shouldDebug = (hasLocalStorage && localStorage.getItem("DEBUG")) || (hasProcess && process.env.DEBUG)
Expand Down Expand Up @@ -541,7 +541,15 @@ export function createVirtualLanguageServiceHost(
getProjectVersion: () => projectVersion.toString(),
getCompilationSettings: () => compilerOptions,
getCustomTransformers: () => customTransformers,
getScriptFileNames: () => fileNames,
// A couple weeks of 4.8 TypeScript nightlies had a bug where the Program's
// list of files was just a reference to the array returned by this host method,
// which means mutations by the host that ought to result in a new Program being
// created were not detected, since the old list of files and the new list of files
// were in fact a reference to the same underlying array. That was fixed in
// https://github.com/microsoft/TypeScript/pull/49813, but since the twoslash runner
// is used in bisecting for changes, it needs to guard against being busted in that
// couple-week period, so we defensively make a slice here.
getScriptFileNames: () => fileNames.slice(),
getScriptSnapshot: fileName => {
const contents = sys.readFile(fileName)
if (contents) {
Expand Down