simplify isFileSystemCaseSensitive test (#17169)

This commit is contained in:
Andy 2017-07-20 10:02:59 -07:00 committed by GitHub
parent c60774b4c6
commit 1f09af9ab6

View File

@ -196,9 +196,16 @@ namespace ts {
if (platform === "win32" || platform === "win64") {
return false;
}
// convert current file name to upper case / lower case and check if file exists
// (guards against cases when name is already all uppercase or lowercase)
return !fileExists(__filename.toUpperCase()) || !fileExists(__filename.toLowerCase());
// If this file exists under a different case, we must be case-insensitve.
return !fileExists(swapCase(__filename));
}
/** Convert all lowercase chars to uppercase, and vice-versa */
function swapCase(s: string): string {
return s.replace(/\w/g, (ch) => {
const up = ch.toUpperCase();
return ch === up ? ch.toLowerCase() : up;
});
}
const platform: string = _os.platform();