More refactoring

This commit is contained in:
Paul van Brenk 2015-04-22 18:09:55 -07:00
parent f8424d0b0c
commit 8955d7ba57
2 changed files with 17 additions and 12 deletions

View File

@ -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) };

View File

@ -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()",