Instead of checking if file exists before file read, handle exceptions from file read (#36244)

Fixes #36236
This commit is contained in:
Sheetal Nandi
2020-01-16 17:24:03 -08:00
committed by GitHub
parent 8517df6fa2
commit 57925d4e35

View File

@@ -1559,10 +1559,13 @@ namespace ts {
}
function readFileWorker(fileName: string, _encoding?: string): string | undefined {
if (!fileExists(fileName)) {
let buffer: Buffer;
try {
buffer = _fs.readFileSync(fileName);
}
catch (e) {
return undefined;
}
const buffer = _fs.readFileSync(fileName);
let len = buffer.length;
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,