Merge pull request #21244 from Microsoft/allowNonExistentInputInGetDirectories

Fix the invalid file/directory location when getting file system entries for caching the results
This commit is contained in:
Sheetal Nandi 2018-01-17 15:39:49 -08:00 committed by GitHub
commit 8e35c3103d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View file

@ -20,6 +20,7 @@ namespace ts {
/* @internal */
namespace ts {
export const emptyArray: never[] = [] as never[];
/** Create a MapLike with good performance. */
function createDictionaryObject<T>(): MapLike<T> {
const map = Object.create(/*prototype*/ null); // tslint:disable-line:no-null-keyword
@ -3070,6 +3071,10 @@ namespace ts {
readonly directories: string[];
}
export const emptyFileSystemEntries: FileSystemEntries = {
files: emptyArray,
directories: emptyArray
};
export function createCachedDirectoryStructureHost(host: DirectoryStructureHost): CachedDirectoryStructureHost {
const cachedReadDirectoryResult = createMap<MutableFileSystemEntries>();
const getCurrentDirectory = memoize(() => host.getCurrentDirectory());
@ -3211,7 +3216,7 @@ namespace ts {
if (path === rootDirPath) {
return result;
}
return getCachedFileSystemEntries(path) || createCachedFileSystemEntries(dir, path);
return tryReadDirectory(dir, path) || emptyFileSystemEntries;
}
}

View file

@ -398,7 +398,7 @@ namespace ts {
return { files, directories };
}
catch (e) {
return { files: [], directories: [] };
return emptyFileSystemEntries;
}
}

View file

@ -2,7 +2,6 @@
/* @internal */
namespace ts {
export const emptyArray: never[] = [] as never[];
export const resolvingEmptyArray: never[] = [] as never[];
export const emptyMap: ReadonlyMap<never> = createMap<never>();
export const emptyUnderscoreEscapedMap: ReadonlyUnderscoreEscapedMap<never> = emptyMap as ReadonlyUnderscoreEscapedMap<never>;

View file

@ -4200,6 +4200,32 @@ namespace ts.projectSystem {
// Since no file from the configured project is open, it would be closed immediately
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
});
it("should tolerate invalid include files that start in subDirectory", () => {
const projectFolder = "/user/username/projects/myproject";
const f = {
path: `${projectFolder}/src/server/index.ts`,
content: "let x = 1"
};
const config = {
path: `${projectFolder}/src/server/tsconfig.json`,
content: JSON.stringify({
compiler: {
module: "commonjs",
outDir: "../../build"
},
include: [
"../src/**/*.ts"
]
})
};
const host = createServerHost([f, config, libFile], { useCaseSensitiveFileNames: true });
const projectService = createProjectService(host);
projectService.openClientFile(f.path);
// Since no file from the configured project is open, it would be closed immediately
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
});
});
describe("tsserverProjectSystem reload", () => {