Skip to content

Commit

Permalink
Add compile error when comment and doctype tags are used within view!
Browse files Browse the repository at this point in the history
Currently, these tags are not displayed in the rendered view. Instead
of silently doing so, this change introduces a compile error with a
helpful message.
  • Loading branch information
thinety committed Feb 22, 2024
1 parent ffa0c09 commit b44863b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
34 changes: 32 additions & 2 deletions leptos_macro/src/view/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,22 @@ pub(crate) fn node_to_tokens(
global_class,
view_marker,
),
Node::Comment(_) | Node::Doctype(_) => Some(quote! {}),
Node::Comment(_) => {
proc_macro_error::emit_error!(
node,
"comment tags do not show up in rendered output\nsupport for \
this is coming in leptos 0.7"
);
Some(quote! {})
}
Node::Doctype(_) => {
proc_macro_error::emit_error!(
node,
"doctype tags do not show up in rendered output\nsupport for \
this is coming in leptos 0.7"
);
Some(quote! {})
}
Node::Text(node) => Some(quote! {
::leptos::leptos_dom::html::text(#node)
}),
Expand Down Expand Up @@ -333,7 +348,22 @@ pub(crate) fn element_to_tokens(
.unwrap_or_default(),
false,
),
Node::Comment(_) | Node::Doctype(_) => (quote! {}, false),
Node::Comment(_) => {
proc_macro_error::emit_error!(
node,
"comment tags do not show up in rendered \
output\nsupport for this is coming in leptos 0.7"
);
(quote! {}, false)
}
Node::Doctype(_) => {
proc_macro_error::emit_error!(
node,
"doctype tags do not show up in rendered \
output\nsupport for this is coming in leptos 0.7"
);
(quote! {}, false)
}
};
if is_static {
quote! {
Expand Down
34 changes: 32 additions & 2 deletions leptos_macro/src/view/server_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ pub(crate) fn root_node_to_tokens_ssr(
global_class,
view_marker,
),
Node::Comment(_) | Node::Doctype(_) => quote! {},
Node::Comment(_) => {
proc_macro_error::emit_error!(
node,
"comment tags do not show up in rendered output\nsupport for \
this is coming in leptos 0.7"
);
quote! {}
}
Node::Doctype(_) => {
proc_macro_error::emit_error!(
node,
"doctype tags do not show up in rendered output\nsupport for \
this is coming in leptos 0.7"
);
quote! {}
}
Node::Text(node) => {
quote! {
::leptos::leptos_dom::html::text(#node)
Expand Down Expand Up @@ -386,7 +401,22 @@ fn element_to_tokens_ssr(
Span::call_site(),
"You can't nest a fragment inside an element."
),
Node::Comment(_) | Node::Doctype(_) => {}
Node::Comment(_) => {
proc_macro_error::emit_error!(
child,
"comment tags do not show up in rendered \
output\nsupport for this is coming in leptos \
0.7"
);
}
Node::Doctype(_) => {
proc_macro_error::emit_error!(
child,
"doctype tags do not show up in rendered \
output\nsupport for this is coming in leptos \
0.7"
);
}
}
}
}
Expand Down

0 comments on commit b44863b

Please sign in to comment.