Skip to content

Commit 140ebcd

Browse files
author
Andy Hanson
committed
More specific type for sourceDirectory, and add fourslash test
1 parent 4363ca4 commit 140ebcd

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/compiler/moduleSpecifiers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.moduleSpecifiers {
99
export function getModuleSpecifier(
1010
compilerOptions: CompilerOptions,
1111
importingSourceFile: SourceFile,
12-
importingSourceFileName: string,
12+
importingSourceFileName: Path,
1313
toFileName: string,
1414
host: ModuleSpecifierResolutionHost,
1515
files: ReadonlyArray<SourceFile>,
@@ -49,10 +49,10 @@ namespace ts.moduleSpecifiers {
4949
readonly moduleResolutionKind: ModuleResolutionKind;
5050
readonly addJsExtension: boolean;
5151
readonly getCanonicalFileName: GetCanonicalFileName;
52-
readonly sourceDirectory: string;
52+
readonly sourceDirectory: Path;
5353
}
5454
// importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
55-
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: string, host: ModuleSpecifierResolutionHost): Info {
55+
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: Path, host: ModuleSpecifierResolutionHost): Info {
5656
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
5757
const addJsExtension = usesJsExtensionOnImports(importingSourceFile);
5858
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : true);
@@ -271,7 +271,7 @@ namespace ts.moduleSpecifiers {
271271
moduleFileName: string,
272272
host: ModuleSpecifierResolutionHost,
273273
getCanonicalFileName: (file: string) => string,
274-
sourceDirectory: string,
274+
sourceDirectory: Path,
275275
): string | undefined {
276276
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs) {
277277
// nothing to do here

src/harness/harnessLanguageService.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ namespace Harness.LanguageService {
155155
this.vfs.mkdirpSync(ts.getDirectoryPath(newPath));
156156
this.vfs.renameSync(oldPath, newPath);
157157

158-
const updater = ts.getPathUpdater(oldPath, newPath, ts.createGetCanonicalFileName(/*useCaseSensitiveFileNames*/ false));
158+
const updater = ts.getPathUpdater(oldPath, newPath, ts.createGetCanonicalFileName(this.useCaseSensitiveFileNames()));
159159
this.scriptInfos.forEach((scriptInfo, key) => {
160160
const newFileName = updater(key);
161161
if (newFileName !== undefined) {
@@ -189,6 +189,10 @@ namespace Harness.LanguageService {
189189
assert.isOk(script);
190190
return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position);
191191
}
192+
193+
useCaseSensitiveFileNames() {
194+
return !this.vfs.ignoreCase;
195+
}
192196
}
193197

194198
/// Native adapter
@@ -251,7 +255,6 @@ namespace Harness.LanguageService {
251255
return 0;
252256
}
253257

254-
255258
log = ts.noop;
256259
trace = ts.noop;
257260
error = ts.noop;

src/services/getEditsForFileRename.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ namespace ts {
104104
): void {
105105
const allFiles = program.getSourceFiles();
106106
for (const sourceFile of allFiles) {
107-
const newFromOld = oldToNew(sourceFile.fileName);
108-
const newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.fileName;
107+
const newFromOld = oldToNew(sourceFile.path) as Path;
108+
const newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
109109
const newImportFromDirectory = getDirectoryPath(newImportFromPath);
110110

111111
const oldFromNew: string | undefined = newToOld(sourceFile.fileName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /howNow/node_modules/brownCow/index.d.ts
4+
////export const foo: number;
5+
6+
// @Filename: /howNow/a.ts
7+
////foo;
8+
9+
// Before fixing this bug, we compared a canonicalized `hownow` to a non-canonicalized `howNow`.
10+
11+
goTo.file("/howNow/a.ts");
12+
verify.importFixAtPosition([
13+
`import { foo } from "brownCow";
14+
15+
foo;`,
16+
]);

0 commit comments

Comments
 (0)