mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Always return empty object when converting the json sourcefile into actual json object, allowing to continue compilation even if there are errors in the tsconfig files
This commit is contained in:
@@ -874,7 +874,7 @@ namespace ts {
|
||||
text = readFile(fileName);
|
||||
}
|
||||
catch (e) {
|
||||
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
|
||||
return { config: {}, error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
|
||||
}
|
||||
return parseConfigFileTextToJson(fileName, text);
|
||||
}
|
||||
@@ -1011,10 +1011,7 @@ namespace ts {
|
||||
knownRootOptions: Map<CommandLineOption> | undefined,
|
||||
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
|
||||
if (!sourceFile.jsonObject) {
|
||||
if (sourceFile.endOfFileToken) {
|
||||
return {};
|
||||
}
|
||||
return undefined;
|
||||
return {};
|
||||
}
|
||||
|
||||
return convertObjectLiteralExpressionToJson(sourceFile.jsonObject, knownRootOptions,
|
||||
|
||||
@@ -225,17 +225,11 @@ namespace ts {
|
||||
|
||||
const result = parseJsonText(configFileName, cachedConfigFileText);
|
||||
reportDiagnostics(result.parseDiagnostics, /* compilerHost */ undefined);
|
||||
if (!result.endOfFileToken) {
|
||||
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
return;
|
||||
}
|
||||
|
||||
const cwd = sys.getCurrentDirectory();
|
||||
const configParseResult = parseJsonSourceFileConfigFileContent(result, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), commandLine.options, getNormalizedAbsolutePath(configFileName, cwd));
|
||||
if (configParseResult.errors.length > 0) {
|
||||
reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined);
|
||||
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
return;
|
||||
}
|
||||
reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined);
|
||||
|
||||
if (isWatchSet(configParseResult.options)) {
|
||||
if (!sys.watchFile) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* host */ undefined);
|
||||
|
||||
@@ -222,16 +222,9 @@ class ProjectRunner extends RunnerBase {
|
||||
readFile
|
||||
};
|
||||
const configParseResult = ts.parseJsonSourceFileConfigFileContent(result, configParseHost, ts.getDirectoryPath(configFileName), compilerOptions);
|
||||
if (configParseResult.errors.length > 0) {
|
||||
return {
|
||||
configFileSourceFiles,
|
||||
moduleKind,
|
||||
errors: result.parseDiagnostics.concat(configParseResult.errors)
|
||||
};
|
||||
}
|
||||
inputFiles = configParseResult.fileNames;
|
||||
compilerOptions = configParseResult.options;
|
||||
errors = result.parseDiagnostics;
|
||||
errors = result.parseDiagnostics.concat(configParseResult.errors);
|
||||
}
|
||||
|
||||
const projectCompilerResult = compileProjectFiles(moduleKind, configFileSourceFiles, () => inputFiles, getSourceFileText, writeFile, compilerOptions);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ts {
|
||||
|
||||
function assertParseError(jsonText: string) {
|
||||
const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
|
||||
assert.isTrue(undefined === parsed.config);
|
||||
assert.deepEqual(parsed.config, {});
|
||||
assert.isTrue(undefined !== parsed.error);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace ts.JsTyping {
|
||||
|
||||
if (!safeList) {
|
||||
const result = readConfigFile(safeListPath, (path: string) => host.readFile(path));
|
||||
safeList = result.config ? createMapFromTemplate<string>(result.config) : EmptySafeList;
|
||||
safeList = createMapFromTemplate<string>(result.config);
|
||||
}
|
||||
|
||||
const filesToWatch: string[] = [];
|
||||
@@ -163,20 +163,18 @@ namespace ts.JsTyping {
|
||||
filesToWatch.push(jsonPath);
|
||||
}
|
||||
const result = readConfigFile(jsonPath, (path: string) => host.readFile(path));
|
||||
if (result.config) {
|
||||
const jsonConfig: PackageJson = result.config;
|
||||
if (jsonConfig.dependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.dependencies));
|
||||
}
|
||||
if (jsonConfig.devDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.devDependencies));
|
||||
}
|
||||
if (jsonConfig.optionalDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.optionalDependencies));
|
||||
}
|
||||
if (jsonConfig.peerDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.peerDependencies));
|
||||
}
|
||||
const jsonConfig: PackageJson = result.config;
|
||||
if (jsonConfig.dependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.dependencies));
|
||||
}
|
||||
if (jsonConfig.devDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.devDependencies));
|
||||
}
|
||||
if (jsonConfig.optionalDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.optionalDependencies));
|
||||
}
|
||||
if (jsonConfig.peerDependencies) {
|
||||
mergeTypings(getOwnKeys(jsonConfig.peerDependencies));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,9 +220,6 @@ namespace ts.JsTyping {
|
||||
continue;
|
||||
}
|
||||
const result = readConfigFile(normalizedFileName, (path: string) => host.readFile(path));
|
||||
if (!result.config) {
|
||||
continue;
|
||||
}
|
||||
const packageJson: PackageJson = result.config;
|
||||
|
||||
// npm 3's package.json contains a "_requiredBy" field
|
||||
|
||||
@@ -1110,17 +1110,6 @@ namespace ts {
|
||||
const text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
|
||||
|
||||
const result = parseJsonText(fileName, text);
|
||||
|
||||
if (!result.endOfFileToken) {
|
||||
return {
|
||||
options: {},
|
||||
typeAcquisition: {},
|
||||
files: [],
|
||||
raw: {},
|
||||
errors: realizeDiagnostics(result.parseDiagnostics, "\r\n")
|
||||
};
|
||||
}
|
||||
|
||||
const normalizedFileName = normalizeSlashes(fileName);
|
||||
const configFile = parseJsonSourceFileConfigFileContent(result, this.host, getDirectoryPath(normalizedFileName), /*existingOptions*/ {}, normalizedFileName);
|
||||
|
||||
@@ -1248,4 +1237,4 @@ namespace TypeScript.Services {
|
||||
// TODO: it should be moved into a namespace though.
|
||||
|
||||
/* @internal */
|
||||
const toolsVersion = "2.4";
|
||||
const toolsVersion = "2.4";
|
||||
|
||||
Reference in New Issue
Block a user