Forbid usage of @children in repeated or conditional element

It leads to compiler panic, or errors in the generated code.
This commit is contained in:
Olivier Goffart 2022-10-31 13:34:18 +01:00 committed by Olivier Goffart
parent 01d666083f
commit 53090ab489
2 changed files with 34 additions and 2 deletions

View file

@ -953,22 +953,36 @@ impl Element {
tr,
));
} else if se.kind() == SyntaxKind::RepeatedElement {
let mut sub_child_insertion_point = None;
let rep = Element::from_repeated_node(
se.into(),
&r,
component_child_insertion_point,
&mut sub_child_insertion_point,
diag,
tr,
);
if let Some((_, se)) = sub_child_insertion_point {
diag.push_error(
"The @children placeholder cannot appear in a repeated element".into(),
&se,
)
}
r.borrow_mut().children.push(rep);
} else if se.kind() == SyntaxKind::ConditionalElement {
let mut sub_child_insertion_point = None;
let rep = Element::from_conditional_node(
se.into(),
r.borrow().base_type.clone(),
component_child_insertion_point,
&mut sub_child_insertion_point,
diag,
tr,
);
if let Some((_, se)) = sub_child_insertion_point {
diag.push_error(
"The @children placeholder cannot appear in a conditional element".into(),
&se,
)
}
r.borrow_mut().children.push(rep);
} else if se.kind() == SyntaxKind::ChildrenPlaceholder {
if children_placeholder.is_some() {