-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #394 - Handle inconsistent file path casings on case insensitive…
… file systems.
- Loading branch information
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect } from "chai"; | ||
import { SourceFile } from "../../compiler"; | ||
import { Project } from "../../Project"; | ||
import { VirtualFileSystemHost, FileSystemHost } from "../../fileSystem"; | ||
|
||
describe("tests for issue #394", () => { | ||
it("should get the original source file with correct casing when the module specifier has incorrect casing and using a case insensitive file system", () => { | ||
const fileSystem: FileSystemHost = new VirtualFileSystemHost(); | ||
const sourceFiles: SourceFile[] = []; | ||
fileSystem.fileExistsSync = filePath => sourceFiles.some(s => s.getFilePath().toLowerCase() === filePath.toLowerCase()); | ||
fileSystem.readFileSync = filePath => { | ||
const searchingFile = sourceFiles.find(s => s.getFilePath().toLowerCase() === filePath.toLowerCase()); | ||
return searchingFile == null ? "" : searchingFile.getFullText(); | ||
}; | ||
fileSystem.isCaseSensitive = () => false; | ||
|
||
const project = new Project({ fileSystem }); | ||
const interfaceSourceFile = project.createSourceFile("/folder/MyInterface.ts", "export interface MyInterface {}"); | ||
const sourceFile = project.createSourceFile("/folder/main.ts", "import { MyInterface } from './myInterface';\n\nlet myVar: MyInterface;"); | ||
sourceFiles.push(interfaceSourceFile, sourceFile); | ||
const varDeclaration = sourceFile.getVariableDeclarationOrThrow("myVar"); | ||
const declarations = varDeclaration.getType().getSymbolOrThrow().getDeclarations(); | ||
|
||
expect(declarations[0].getSourceFile().getFilePath()).to.equal("/folder/MyInterface.ts"); | ||
expect(declarations[0].getSourceFile()).to.equal(interfaceSourceFile); | ||
}); | ||
|
||
it("should not be able to get the source file symbol when the module specifier has incorrect casing and using a case sensitive file system", () => { | ||
const project = new Project({ useVirtualFileSystem: true }); | ||
const interfaceSourceFile = project.createSourceFile("/folder/MyInterface.ts", "export interface MyInterface {}"); | ||
const sourceFile = project.createSourceFile("/folder/main.ts", "import { MyInterface } from './myInterface';\n\nlet myVar: MyInterface;"); | ||
const varDeclaration = sourceFile.getVariableDeclarationOrThrow("myVar"); | ||
const symbol = varDeclaration.getType().getSymbol(); | ||
|
||
expect(symbol).to.be.undefined; | ||
}); | ||
}); |
I'm not sure if there's a better way of doing this, but this should cover most scenarios.