fix(ngcc): handle compilation diagnostics (#31996)
Previously, any diagnostics reported during the compilation of an entry-point would not be shown to the user, but either be ignored or cause a hard crash in case of a `FatalDiagnosticError`. This is unfortunate, as such error instances contain information on which code was responsible for producing the error, whereas only its error message would not. Therefore, it was quite hard to determine where the error originates from. This commit introduces behavior to deal with error diagnostics in a more graceful way. Such diagnostics will still cause the compilation to fail, however the error message now contains formatted diagnostics. Closes #31977 Resolves FW-1374 PR Close #31996
This commit is contained in:
@ -130,7 +130,13 @@ export class DecorationAnalyzer {
|
||||
|
||||
protected analyzeClass(symbol: ClassSymbol): AnalyzedClass|null {
|
||||
const decorators = this.reflectionHost.getDecoratorsOfSymbol(symbol);
|
||||
return analyzeDecorators(symbol, decorators, this.handlers);
|
||||
const analyzedClass = analyzeDecorators(symbol, decorators, this.handlers);
|
||||
if (analyzedClass !== null && analyzedClass.diagnostics !== undefined) {
|
||||
for (const diagnostic of analyzedClass.diagnostics) {
|
||||
this.diagnosticHandler(diagnostic);
|
||||
}
|
||||
}
|
||||
return analyzedClass;
|
||||
}
|
||||
|
||||
protected migrateFile(migrationHost: MigrationHost, analyzedFile: AnalyzedFile): void {
|
||||
|
@ -6,9 +6,12 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {isFatalDiagnosticError} from '../../../src/ngtsc/diagnostics';
|
||||
import {AbsoluteFsPath, absoluteFromSourceFile, relative} from '../../../src/ngtsc/file_system';
|
||||
import {ClassSymbol, Decorator} from '../../../src/ngtsc/reflection';
|
||||
import {DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
|
||||
|
||||
import {AnalyzedClass, MatchingHandler} from './types';
|
||||
|
||||
export function isWithinPackage(packagePath: AbsoluteFsPath, sourceFile: ts.SourceFile): boolean {
|
||||
@ -59,11 +62,19 @@ export function analyzeDecorators(
|
||||
const matches: {handler: DecoratorHandler<any, any>, analysis: any}[] = [];
|
||||
const allDiagnostics: ts.Diagnostic[] = [];
|
||||
for (const {handler, detected} of detections) {
|
||||
const {analysis, diagnostics} = handler.analyze(declaration, detected.metadata);
|
||||
if (diagnostics !== undefined) {
|
||||
allDiagnostics.push(...diagnostics);
|
||||
try {
|
||||
const {analysis, diagnostics} = handler.analyze(declaration, detected.metadata);
|
||||
if (diagnostics !== undefined) {
|
||||
allDiagnostics.push(...diagnostics);
|
||||
}
|
||||
matches.push({handler, analysis});
|
||||
} catch (e) {
|
||||
if (isFatalDiagnosticError(e)) {
|
||||
allDiagnostics.push(e.toDiagnostic());
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
matches.push({handler, analysis});
|
||||
}
|
||||
return {
|
||||
name: symbol.name,
|
||||
|
Reference in New Issue
Block a user