Skip to content

Lowercase type reference directives when determining to reuse program structure (just like when we create new program) #26944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,8 @@ namespace ts {
}
}
if (resolveTypeReferenceDirectiveNamesWorker) {
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, x => x.fileName);
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, ref => ref.fileName.toLocaleLowerCase());
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFilePath);
// ensure that types resolutions are still correct
const resolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, resolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, typeDirectiveIsEqualTo);
Expand Down
59 changes: 59 additions & 0 deletions src/testRunner/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9555,6 +9555,65 @@ export function Test2() {
});
});

describe("tsserverProjectSystem typeReferenceDirectives", () => {
it("when typeReferenceDirective contains UpperCasePackage", () => {
const projectLocation = "/user/username/projects/myproject";
const libProjectLocation = `${projectLocation}/lib`;
const typeLib: File = {
path: `${libProjectLocation}/@types/UpperCasePackage/index.d.ts`,
content: `declare class BrokenTest {
constructor(name: string, width: number, height: number, onSelect: Function);
Name: string;
SelectedFile: string;
}`
};
const appLib: File = {
path: `${libProjectLocation}/@app/lib/index.d.ts`,
content: `/// <reference types="UpperCasePackage" />
declare class TestLib {
issue: BrokenTest;
constructor();
test(): void;
}`
};
const testProjectLocation = `${projectLocation}/test`;
const testFile: File = {
path: `${testProjectLocation}/test.ts`,
content: `class TestClass1 {

constructor() {
var l = new TestLib();

}

public test2() {
var x = new BrokenTest('',0,0,null);

}
}`
};
const testConfig: File = {
path: `${testProjectLocation}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
typeRoots: ["../lib/@types", "../lib/@app"]
}
})
};

const files = [typeLib, appLib, testFile, testConfig, libFile];
const host = createServerHost(files);
const service = createProjectService(host);
service.openClientFile(testFile.path);
checkNumberOfProjects(service, { configuredProjects: 1 });
const project = service.configuredProjects.get(testConfig.path)!;
checkProjectActualFiles(project, files.map(f => f.path));
host.writeFile(appLib.path, appLib.content.replace("test()", "test2()"));
host.checkTimeoutQueueLengthAndRun(2);
});
});

describe("tsserverProjectSystem project references", () => {
const aTs: File = {
path: "/a/a.ts",
Expand Down