From b44863b16420ff39417336d6361edfe150de3e81 Mon Sep 17 00:00:00 2001 From: Thiago Trannin <51510921+thinety@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:15:21 -0300 Subject: [PATCH] Add compile error when comment and doctype tags are used within `view!` 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. --- leptos_macro/src/view/client_builder.rs | 34 ++++++++++++++++++++++-- leptos_macro/src/view/server_template.rs | 34 ++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/leptos_macro/src/view/client_builder.rs b/leptos_macro/src/view/client_builder.rs index 15e0151c4a..4487243c7f 100644 --- a/leptos_macro/src/view/client_builder.rs +++ b/leptos_macro/src/view/client_builder.rs @@ -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) }), @@ -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! { diff --git a/leptos_macro/src/view/server_template.rs b/leptos_macro/src/view/server_template.rs index 57e51ca635..c0d4ee552b 100644 --- a/leptos_macro/src/view/server_template.rs +++ b/leptos_macro/src/view/server_template.rs @@ -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) @@ -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" + ); + } } } }