From aac8b3fae54035ab2cc494ad28e91037823ad149 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Oct 2014 14:48:43 -0700 Subject: [PATCH 1/2] Removed Diagnostics from sys.ts in order to avoid cyclical build dependency. Specifically, processDiagnosticMessages.ts was dependent on sys.ts, which was dependent on the rest of the compiler, which meant that in a broken state of diagnostics, you could never compile processDiagnosticMessages.ts. --- src/compiler/sys.ts | 8 +++++++- src/compiler/tsc.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2f5ff604df3..e0837c6aa0c 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -27,6 +27,10 @@ declare var module: any; declare var process: any; declare var global: any; +enum SystemError { + UnsupportedFileEncoding +} + var sys: System = (function () { function getWScriptSystem(): System { @@ -68,7 +72,9 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + if (e.number === -2147024809) { + e.systemError = SystemError.UnsupportedFileEncoding; + } } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1c..e6e48e32e41 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -71,6 +71,15 @@ module ts { return true; } + + function getSystemErrorMessage(e: SystemError): string { + switch (e) { + case SystemError.UnsupportedFileEncoding: + return getDiagnosticText(Diagnostics.Unsupported_file_encoding); + default: + Debug.assert("Unreachable code in 'getSystemErrorMessage'"); + } + } function countLines(program: Program): number { var count = 0; @@ -149,7 +158,7 @@ module ts { } catch (e) { if (onError) { - onError(e.message); + onError(e.systemError ? getSystemErrorMessage(e.systemError) : e.message); } text = ""; } From b371b02ea08e7b0fda739e1796511f07538ce9d5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 Oct 2014 15:08:04 -0700 Subject: [PATCH 2/2] Addressed CR feedback. --- src/compiler/sys.ts | 8 +------- src/compiler/tsc.ts | 18 +++++++----------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index e0837c6aa0c..57ad0260cb6 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -27,10 +27,6 @@ declare var module: any; declare var process: any; declare var global: any; -enum SystemError { - UnsupportedFileEncoding -} - var sys: System = (function () { function getWScriptSystem(): System { @@ -72,9 +68,7 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - if (e.number === -2147024809) { - e.systemError = SystemError.UnsupportedFileEncoding; - } + throw e; } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e6e48e32e41..52dac9695de 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -71,15 +71,6 @@ module ts { return true; } - - function getSystemErrorMessage(e: SystemError): string { - switch (e) { - case SystemError.UnsupportedFileEncoding: - return getDiagnosticText(Diagnostics.Unsupported_file_encoding); - default: - Debug.assert("Unreachable code in 'getSystemErrorMessage'"); - } - } function countLines(program: Program): number { var count = 0; @@ -151,14 +142,19 @@ module ts { // otherwise use toLowerCase as a canonical form. return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - + + // returned by CScript sys environment + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.systemError ? getSystemErrorMessage(e.systemError) : e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? + getDiagnosticText(Diagnostics.Unsupported_file_encoding) : + e.message); } text = ""; }