Skip to content

Commit

Permalink
fix: compiler crashes are not handled (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
volnyansky authored Oct 29, 2023
1 parent d3b462e commit d461689
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/typescript/worker/lib/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,32 @@ export function invalidateDiagnostics(): void {

export function getDiagnosticsOfProgram(program: ts.Program | ts.BuilderProgram): ts.Diagnostic[] {
const programDiagnostics: ts.Diagnostic[] = [];

if (config.diagnosticOptions.syntactic) {
programDiagnostics.push(...program.getSyntacticDiagnostics());
}
if (config.diagnosticOptions.global) {
programDiagnostics.push(...program.getGlobalDiagnostics());
}
if (config.diagnosticOptions.semantic) {
programDiagnostics.push(...program.getSemanticDiagnostics());
}
if (config.diagnosticOptions.declaration) {
programDiagnostics.push(...program.getDeclarationDiagnostics());
try {
if (config.diagnosticOptions.syntactic) {
programDiagnostics.push(...program.getSyntacticDiagnostics());
}
if (config.diagnosticOptions.global) {
programDiagnostics.push(...program.getGlobalDiagnostics());
}
if (config.diagnosticOptions.semantic) {
programDiagnostics.push(...program.getSemanticDiagnostics());
}
if (config.diagnosticOptions.declaration) {
programDiagnostics.push(...program.getDeclarationDiagnostics());
}
} catch (e) {
if (e instanceof Error) {
programDiagnostics.push({
code: 1,
category: 1,
messageText: `TSC compiler crashed: ${e.message}
${e.stack}`,
file: undefined,
start: undefined,
length: undefined,
});
}
}

return programDiagnostics;
}

Expand Down

0 comments on commit d461689

Please sign in to comment.