fix(ivy): don't crash on an unknown localref target (#33454)
Previously the template binder would crash when encountering an unknown localref (# reference) such as `<div #ref="foo">` when no directive has `exportAs: "foo"`. With this commit, the compiler instead generates a template diagnostic error informing the user about the invalid reference. PR Close #33454
This commit is contained in:
@ -260,16 +260,16 @@ class DirectiveBinder<DirectiveT extends DirectiveMeta> implements Visitor {
|
||||
// This could be a reference to a component if there is one.
|
||||
dirTarget = directives.find(dir => dir.isComponent) || null;
|
||||
} else {
|
||||
// This is a reference to a directive exported via exportAs. One should exist.
|
||||
// This should be a reference to a directive exported via exportAs.
|
||||
dirTarget =
|
||||
directives.find(
|
||||
dir => dir.exportAs !== null && dir.exportAs.some(value => value === ref.value)) ||
|
||||
null;
|
||||
|
||||
// Check if a matching directive was found, and error if it wasn't.
|
||||
// Check if a matching directive was found.
|
||||
if (dirTarget === null) {
|
||||
// TODO(alxhub): Return an error value here that can be used for template validation.
|
||||
throw new Error(`Assertion error: failed to find directive with exportAs: ${ref.value}`);
|
||||
// No matching directive was found - this reference points to an unknown target. Leave it
|
||||
// unmapped.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user