Skip to content

Commit 1f09af9

Browse files
author
Andy
authored
simplify isFileSystemCaseSensitive test (microsoft#17169)
1 parent c60774b commit 1f09af9

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/compiler/sys.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,16 @@ namespace ts {
196196
if (platform === "win32" || platform === "win64") {
197197
return false;
198198
}
199-
// convert current file name to upper case / lower case and check if file exists
200-
// (guards against cases when name is already all uppercase or lowercase)
201-
return !fileExists(__filename.toUpperCase()) || !fileExists(__filename.toLowerCase());
199+
// If this file exists under a different case, we must be case-insensitve.
200+
return !fileExists(swapCase(__filename));
201+
}
202+
203+
/** Convert all lowercase chars to uppercase, and vice-versa */
204+
function swapCase(s: string): string {
205+
return s.replace(/\w/g, (ch) => {
206+
const up = ch.toUpperCase();
207+
return ch === up ? ch.toLowerCase() : up;
208+
});
202209
}
203210

204211
const platform: string = _os.platform();

0 commit comments

Comments
 (0)