Skip to content

Commit 6fb0f68

Browse files
authored
Merge pull request #26944 from Microsoft/casingOfTypeReferenceDirectives
Lowercase type reference directives when determining to reuse program structure (just like when we create new program)
2 parents 8f654f0 + 88d5b04 commit 6fb0f68

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,8 @@ namespace ts {
11781178
}
11791179
}
11801180
if (resolveTypeReferenceDirectiveNamesWorker) {
1181-
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, x => x.fileName);
1181+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
1182+
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, ref => ref.fileName.toLocaleLowerCase());
11821183
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFilePath);
11831184
// ensure that types resolutions are still correct
11841185
const resolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, resolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, typeDirectiveIsEqualTo);

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9555,6 +9555,65 @@ export function Test2() {
95559555
});
95569556
});
95579557

9558+
describe("tsserverProjectSystem typeReferenceDirectives", () => {
9559+
it("when typeReferenceDirective contains UpperCasePackage", () => {
9560+
const projectLocation = "/user/username/projects/myproject";
9561+
const libProjectLocation = `${projectLocation}/lib`;
9562+
const typeLib: File = {
9563+
path: `${libProjectLocation}/@types/UpperCasePackage/index.d.ts`,
9564+
content: `declare class BrokenTest {
9565+
constructor(name: string, width: number, height: number, onSelect: Function);
9566+
Name: string;
9567+
SelectedFile: string;
9568+
}`
9569+
};
9570+
const appLib: File = {
9571+
path: `${libProjectLocation}/@app/lib/index.d.ts`,
9572+
content: `/// <reference types="UpperCasePackage" />
9573+
declare class TestLib {
9574+
issue: BrokenTest;
9575+
constructor();
9576+
test(): void;
9577+
}`
9578+
};
9579+
const testProjectLocation = `${projectLocation}/test`;
9580+
const testFile: File = {
9581+
path: `${testProjectLocation}/test.ts`,
9582+
content: `class TestClass1 {
9583+
9584+
constructor() {
9585+
var l = new TestLib();
9586+
9587+
}
9588+
9589+
public test2() {
9590+
var x = new BrokenTest('',0,0,null);
9591+
9592+
}
9593+
}`
9594+
};
9595+
const testConfig: File = {
9596+
path: `${testProjectLocation}/tsconfig.json`,
9597+
content: JSON.stringify({
9598+
compilerOptions: {
9599+
module: "amd",
9600+
typeRoots: ["../lib/@types", "../lib/@app"]
9601+
}
9602+
})
9603+
};
9604+
9605+
const files = [typeLib, appLib, testFile, testConfig, libFile];
9606+
const host = createServerHost(files);
9607+
const service = createProjectService(host);
9608+
service.openClientFile(testFile.path);
9609+
checkNumberOfProjects(service, { configuredProjects: 1 });
9610+
const project = service.configuredProjects.get(testConfig.path)!;
9611+
checkProjectActualFiles(project, files.map(f => f.path));
9612+
host.writeFile(appLib.path, appLib.content.replace("test()", "test2()"));
9613+
host.checkTimeoutQueueLengthAndRun(2);
9614+
});
9615+
});
9616+
95589617
describe("tsserverProjectSystem project references", () => {
95599618
const aTs: File = {
95609619
path: "/a/a.ts",

0 commit comments

Comments
 (0)