Skip to content

Commit

Permalink
Avoid pushing to rootFileNames with version
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Mar 22, 2020
1 parent 366ac0b commit 92cf961
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,16 @@ export function create (rawOptions: CreateOptions = {}): Register {
const service = ts.createLanguageService(serviceHost, registry)

const updateMemoryCache = (contents: string, fileName: string) => {
const fileVersion = fileVersions.get(fileName) || 0

// Add to `rootFiles` when discovered for the first time.
if (fileVersion === 0) {
if (!fileVersions.has(fileName)) {
rootFileNames.push(fileName)
}

const previousVersion = fileVersions.get(fileName) || 0
const previousContents = fileContents.get(fileName)
// Avoid incrementing cache when nothing has changed.
if (contents !== previousContents) {
fileVersions.set(fileName, fileVersion + 1)
fileVersions.set(fileName, previousVersion + 1)
fileContents.set(fileName, contents)
// Increment project version for every file change.
projectVersion++
Expand Down

0 comments on commit 92cf961

Please sign in to comment.