Minor clean up to make it more readable.
This commit is contained in:
parent
5c44a0ff3e
commit
f8424d0b0c
|
@ -284,12 +284,13 @@ module ts {
|
|||
* Read tsconfig.json file
|
||||
* @param fileName The path to the config file
|
||||
*/
|
||||
export function readConfigFile(fileName: string): any {
|
||||
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
|
||||
try {
|
||||
var text = sys.readFile(fileName);
|
||||
return /\S/.test(text) ? JSON.parse(text) : {};
|
||||
return { config: /\S/.test(text) ? JSON.parse(text) : {} };
|
||||
}
|
||||
catch (e) {
|
||||
return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -208,15 +208,15 @@ module ts {
|
|||
|
||||
if (!cachedProgram) {
|
||||
if (configFileName) {
|
||||
try {
|
||||
var configObject = readConfigFile(configFileName);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, configFileName, e.message));
|
||||
|
||||
let result = readConfigFile(configFileName);
|
||||
if (result.error) {
|
||||
reportDiagnostic(result.error);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
}
|
||||
var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName));
|
||||
|
||||
let configObject = result.config;
|
||||
let configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName));
|
||||
if (configParseResult.errors.length > 0) {
|
||||
reportDiagnostics(configParseResult.errors);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
|
@ -233,7 +233,7 @@ module ts {
|
|||
compilerHost.getSourceFile = getSourceFile;
|
||||
}
|
||||
|
||||
var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
|
||||
let compileResult = compile(rootFileNames, compilerOptions, compilerHost);
|
||||
|
||||
if (!compilerOptions.watch) {
|
||||
return sys.exit(compileResult.exitStatus);
|
||||
|
|
|
@ -804,20 +804,17 @@ module ts {
|
|||
() => {
|
||||
let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
|
||||
|
||||
try {
|
||||
var json = /\S/.test(text) ? JSON.parse(text) : {};
|
||||
}
|
||||
catch (e) {
|
||||
let result = this.parseConfigFileText(fileName, text);
|
||||
|
||||
if (result.error) {
|
||||
return {
|
||||
options: {},
|
||||
files: [],
|
||||
errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message), '\r\n')
|
||||
}
|
||||
errors: [realizeDiagnostic(result.error, '/r/n')]
|
||||
};
|
||||
}
|
||||
|
||||
if (json) {
|
||||
var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName)));
|
||||
}
|
||||
var configFile = parseConfigFile(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName)));
|
||||
|
||||
return {
|
||||
options: configFile.options,
|
||||
|
@ -827,6 +824,15 @@ 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()",
|
||||
|
|
Loading…
Reference in a new issue