fix: correctly handle empty view! {} in hot-reloading code (closes #2421) (#2478)

This commit is contained in:
Greg Johnston 2024-04-01 16:23:29 -04:00 committed by GitHub
parent 41f3c46830
commit b79037b96f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -78,12 +78,20 @@ impl ViewMacros {
for view in visitor.views {
let span = view.span();
let id = span_to_stable_id(path, span.start().line);
let tokens = view.tokens.clone().into_iter();
// TODO handle class = ...
let rsx =
rstml::parse2(tokens.collect::<proc_macro2::TokenStream>())?;
let template = LNode::parse_view(rsx)?;
views.push(MacroInvocation { id, template });
if view.tokens.is_empty() {
views.push(MacroInvocation {
id,
template: LNode::Fragment(Vec::new()),
});
} else {
let tokens = view.tokens.clone().into_iter();
// TODO handle class = ...
let rsx = rstml::parse2(
tokens.collect::<proc_macro2::TokenStream>(),
)?;
let template = LNode::parse_view(rsx)?;
views.push(MacroInvocation { id, template });
}
}
Ok(views)
}