Skip to content

Commit 8955d7b

Browse files
author
Paul van Brenk
committed
More refactoring
1 parent f8424d0 commit 8955d7b

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,24 @@ module ts {
284284
* Read tsconfig.json file
285285
* @param fileName The path to the config file
286286
*/
287-
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
287+
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
288288
try {
289289
var text = sys.readFile(fileName);
290-
return { config: /\S/.test(text) ? JSON.parse(text) : {} };
290+
return parseConfigFileText(fileName, text);
291+
}
292+
catch (e) {
293+
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
294+
}
295+
}
296+
297+
/**
298+
* Parse the text of the tsconfig.json file
299+
* @param fileName The path to the config file
300+
* @param jsonText The text of the config file
301+
*/
302+
export function parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
303+
try {
304+
return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
291305
}
292306
catch (e) {
293307
return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };

src/services/shims.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ module ts {
804804
() => {
805805
let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
806806

807-
let result = this.parseConfigFileText(fileName, text);
807+
let result = parseConfigFileText(fileName, text);
808808

809809
if (result.error) {
810810
return {
@@ -824,15 +824,6 @@ module ts {
824824
});
825825
}
826826

827-
private parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
828-
try {
829-
return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
830-
}
831-
catch (e) {
832-
return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
833-
}
834-
}
835-
836827
public getDefaultCompilationSettings(): string {
837828
return this.forwardJSONCall(
838829
"getDefaultCompilationSettings()",

0 commit comments

Comments
 (0)