|
9 | 9 | import {AST, TmplAstNode} from '@angular/compiler'; |
10 | 10 | import {CompilerOptions, ConfigurationHost, readConfiguration} from '@angular/compiler-cli'; |
11 | 11 | import {NgCompiler} from '@angular/compiler-cli/src/ngtsc/core'; |
12 | | -import {ErrorCode, ngErrorCode} from '@angular/compiler-cli/src/ngtsc/diagnostics'; |
| 12 | +import { |
| 13 | + ErrorCode, |
| 14 | + isFatalDiagnosticError, |
| 15 | + ngErrorCode, |
| 16 | +} from '@angular/compiler-cli/src/ngtsc/diagnostics'; |
13 | 17 | import {absoluteFrom, AbsoluteFsPath} from '@angular/compiler-cli/src/ngtsc/file_system'; |
14 | 18 | import {PerfPhase} from '@angular/compiler-cli/src/ngtsc/perf'; |
15 | 19 | import {FileUpdate, ProgramDriver} from '@angular/compiler-cli/src/ngtsc/program_driver'; |
@@ -141,11 +145,20 @@ export class LanguageService { |
141 | 145 | const components = compiler.getComponentsWithTemplateFile(fileName); |
142 | 146 | for (const component of components) { |
143 | 147 | if (ts.isClassDeclaration(component)) { |
144 | | - diagnostics.push( |
145 | | - ...compiler |
146 | | - .getTemplateTypeChecker() |
147 | | - .getSuggestionDiagnosticsForComponent(component, this.tsLS), |
148 | | - ); |
| 148 | + try { |
| 149 | + diagnostics.push( |
| 150 | + ...compiler |
| 151 | + .getTemplateTypeChecker() |
| 152 | + .getSuggestionDiagnosticsForComponent(component, this.tsLS), |
| 153 | + ); |
| 154 | + } catch (e) { |
| 155 | + // Type check code may throw fatal diagnostic errors if e.g. the type check |
| 156 | + // block cannot be generated. In this case, we consider that there are no available suggestion diagnostics. |
| 157 | + if (isFatalDiagnosticError(e)) { |
| 158 | + continue; |
| 159 | + } |
| 160 | + throw e; |
| 161 | + } |
149 | 162 | } |
150 | 163 | } |
151 | 164 | } |
|
0 commit comments