mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(migrations): gracefully handle metadata parsing errors in signal migration (#58413)
In 1P, we saw that a type of a target wasn't resolvable, referenced in a `hostBindings#directive` field. This breaks the entire pipeline; so we should handle gracefully but report an error. Worst case scenario here is that we would miss some references to the given directive/component. This is acceptable and we can continue investigation why that given target was broken; especially since the file was part of the target inputs- but seemingly not in the `tsconfig`. PR Close #58413
This commit is contained in:
parent
7f10343659
commit
0d955f67ed
1 changed files with 15 additions and 3 deletions
|
|
@ -14,6 +14,7 @@ import {FatalDiagnosticError} from '@angular/compiler-cli/src/ngtsc/diagnostics'
|
|||
import {Reference, ReferenceEmitter} from '@angular/compiler-cli/src/ngtsc/imports';
|
||||
import {
|
||||
DecoratorInputTransform,
|
||||
DirectiveMeta,
|
||||
DtsMetadataReader,
|
||||
InputMapping,
|
||||
} from '@angular/compiler-cli/src/ngtsc/metadata';
|
||||
|
|
@ -74,9 +75,20 @@ function extractDtsInput(node: ts.Node, metadataReader: DtsMetadataReader): Extr
|
|||
return null;
|
||||
}
|
||||
|
||||
const directiveMetadata = metadataReader.getDirectiveMetadata(
|
||||
new Reference(node.parent as ClassDeclaration),
|
||||
);
|
||||
let directiveMetadata: DirectiveMeta | null = null;
|
||||
|
||||
// Getting directive metadata can throw errors when e.g. types referenced
|
||||
// in the `.d.ts` aren't resolvable. This seems to be unexpected and shouldn't
|
||||
// result in the entire migration to be failing.
|
||||
try {
|
||||
directiveMetadata = metadataReader.getDirectiveMetadata(
|
||||
new Reference(node.parent as ClassDeclaration),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('Unexpected error. Gracefully ignoring.');
|
||||
console.error('Could not parse directive metadata:', e);
|
||||
return null;
|
||||
}
|
||||
const inputMapping = directiveMetadata?.inputs.getByClassPropertyName(node.name.text);
|
||||
|
||||
// Signal inputs are never tracked and migrated.
|
||||
|
|
|
|||
Loading…
Reference in a new issue