From 1f09af9ab6f1883b2e6aa9e21bf6fdc76e1bc2d1 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 20 Jul 2017 10:02:59 -0700 Subject: [PATCH] simplify isFileSystemCaseSensitive test (#17169) --- src/compiler/sys.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 62ce272e96c..9c6d4bb795d 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -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();