Fix error messages with invalid change callback

This commit is contained in:
Olivier Goffart 2024-06-27 17:51:05 +02:00
parent 36ccc9d658
commit a63618fcfe
2 changed files with 47 additions and 1 deletions

View file

@ -1363,7 +1363,24 @@ impl Element {
}
let Some(prop) = parser::identifier_text(&ch.DeclaredIdentifier()) else { continue };
let lookup_result = r.lookup_property(&prop);
if lookup_result.property_visibility == PropertyVisibility::Private
if !lookup_result.is_valid() {
diag.push_error(
format!("Property '{prop}' does not exist"),
&ch.DeclaredIdentifier(),
);
} else if !lookup_result.property_type.is_property_type() {
let what = match lookup_result.property_type {
Type::Function { .. } => "a function",
Type::Callback { .. } => "a callback",
_ => "not a property",
};
diag.push_error(
format!(
"Change callback can only be set on properties, and '{prop}' is {what}"
),
&ch.DeclaredIdentifier(),
);
} else if lookup_result.property_visibility == PropertyVisibility::Private
&& !lookup_result.is_local_to_component
{
diag.push_error(