New syntax: Only allow children if the component has @children

For compatibility reason, this is also allowed when inheriting
This commit is contained in:
Olivier Goffart 2022-10-28 16:58:51 +02:00 committed by Olivier Goffart
parent 64b248cfa9
commit 84ae4d2928
2 changed files with 19 additions and 7 deletions

View file

@ -467,12 +467,13 @@ impl ElementType {
tr: &TypeRegister,
) -> Result<ElementType, String> {
match self {
Self::Component(component) => {
return component
.root_element
.borrow()
.base_type
.lookup_type_for_child_element(name, tr)
Self::Component(component) if component.child_insertion_point.borrow().is_none() => {
let base_type = component.root_element.borrow().base_type.clone();
if base_type == tr.empty_type() {
return Err(format!("'{}' cannot have children. Only components with @children can have children", component.id));
} else {
return base_type.lookup_type_for_child_element(name, tr);
}
}
Self::Builtin(builtin) => {
if let Some(child_type) = builtin.additional_accepted_child_types.get(name) {