Skip to content

Commit

Permalink
fix: DocumentRegistry - Ensure any file paths sent from the compiler …
Browse files Browse the repository at this point in the history
…api are normalized.
  • Loading branch information
dsherret committed Aug 19, 2018
1 parent 8577d38 commit 1c06559
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/factories/CompilerFactory.ts
Expand Up @@ -38,13 +38,14 @@ export class CompilerFactory {
private readonly sourceFileMovedEventContainer = new EventContainer<SourceFile>();
private readonly sourceFileRemovedEventContainer = new EventContainer<SourceFile>();

readonly documentRegistry = new DocumentRegistry();
readonly documentRegistry: DocumentRegistry;

/**
* Initializes a new instance of CompilerFactory.
* @param context - Project context.
*/
constructor(private readonly context: ProjectContext) {
this.documentRegistry = new DocumentRegistry(context.fileSystemWrapper);
this.directoryCache = new DirectoryCache(context);

// prevent memory leaks when the document registry key changes by just reseting it
Expand Down
5 changes: 5 additions & 0 deletions src/factories/DocumentRegistry.ts
@@ -1,12 +1,16 @@
/* barrel:ignore */
import { ts, CompilerOptions, ScriptKind, ScriptTarget } from "../typescript";
import { KeyValueCache } from "../utils";
import { FileSystemWrapper } from "../fileSystem";
import * as errors from "../errors";

export class DocumentRegistry implements ts.DocumentRegistry {
private readonly sourceFileCacheByFilePath = new KeyValueCache<string, ts.SourceFile>();
private static readonly initialVersion = "0";

constructor(private readonly fileSystemWrapper: FileSystemWrapper) {
}

removeSourceFile(fileName: string) {
this.sourceFileCacheByFilePath.removeByKey(fileName);
}
Expand Down Expand Up @@ -74,6 +78,7 @@ export class DocumentRegistry implements ts.DocumentRegistry {
}

private updateSourceFile(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: ts.IScriptSnapshot, version: string): ts.SourceFile {
fileName = this.fileSystemWrapper.getStandardizedAbsolutePath(fileName);
const newSourceFile = this.createCompilerSourceFile(fileName, scriptSnapshot, compilationSettings, version);
this.sourceFileCacheByFilePath.set(fileName, newSourceFile);
return newSourceFile;
Expand Down

0 comments on commit 1c06559

Please sign in to comment.