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

This commit is contained in:
Sheetal Nandi 2018-09-06 13:26:44 -07:00
parent 8f654f0f1e
commit 88d5b04c70
2 changed files with 61 additions and 1 deletions

View file

@ -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);

View file

@ -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",