diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b477c97fec8..a4b25b08d23 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -284,10 +284,24 @@ module ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { + export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { try { var text = sys.readFile(fileName); - return { config: /\S/.test(text) ? JSON.parse(text) : {} }; + return parseConfigFileText(fileName, text); + } + catch (e) { + return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; + } + } + + /** + * Parse the text of the tsconfig.json file + * @param fileName The path to the config file + * @param jsonText The text of the config file + */ + export function parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } { + try { + return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; diff --git a/src/services/shims.ts b/src/services/shims.ts index ddcc32b8640..5c08e503b1c 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -804,7 +804,7 @@ module ts { () => { let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - let result = this.parseConfigFileText(fileName, text); + let result = parseConfigFileText(fileName, text); if (result.error) { return { @@ -824,15 +824,6 @@ module ts { }); } - private parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } { - try { - return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; - } - catch (e) { - return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; - } - } - public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()",