From bae0141f981b7ffe5abf79c5f2310463894f593e Mon Sep 17 00:00:00 2001 From: Tim Kurdov Date: Sat, 28 Oct 2023 16:36:56 +0100 Subject: [PATCH] Remove deprecated `class=(...)` syntax (#3497) * removed class=(...) syntax * made DynamicName::expr a group instead of a block * fixed tests, silenced all unused_must_use warnings * fixed wasm test --- .../yew-macro/src/html_tree/html_element.rs | 66 ++++----------- packages/yew-macro/src/props/element.rs | 20 +---- .../yew-macro/tests/html_macro/block-pass.rs | 16 ++-- .../html_macro/component-any-children-pass.rs | 28 +++---- .../tests/html_macro/component-pass.rs | 34 ++++---- .../tests/html_macro/dyn-element-pass.rs | 7 +- .../tests/html_macro/element-fail.rs | 4 - .../tests/html_macro/element-fail.stderr | 84 ++++++------------- .../html_macro/generic-component-pass.rs | 28 +++---- .../tests/html_macro/html-element-pass.rs | 15 ++-- .../tests/html_macro/html-if-pass.rs | 48 +++++------ .../tests/html_macro/html-node-pass.rs | 26 +++--- .../tests/html_macro/iterable-pass.rs | 12 +-- .../yew-macro/tests/html_macro/list-pass.rs | 10 +-- .../yew-macro/tests/html_macro/node-pass.rs | 30 +++---- .../yew-macro/tests/html_macro/svg-pass.rs | 4 +- packages/yew/src/dom_bundle/btag/mod.rs | 4 +- 17 files changed, 172 insertions(+), 264 deletions(-) diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index a501644941b..83a4faf0059 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -1,13 +1,13 @@ -use proc_macro2::{Delimiter, Span, TokenStream}; +use proc_macro2::{Delimiter, Group, Span, TokenStream}; use proc_macro_error::emit_warning; use quote::{quote, quote_spanned, ToTokens}; use syn::buffer::Cursor; use syn::parse::{Parse, ParseStream}; use syn::spanned::Spanned; -use syn::{Block, Expr, Ident, Lit, LitStr, Token}; +use syn::{Expr, Ident, Lit, LitStr, Token}; use super::{HtmlChildrenTree, HtmlDashedName, TagTokens}; -use crate::props::{ClassesForm, ElementProps, Prop, PropDirective}; +use crate::props::{ElementProps, Prop, PropDirective}; use crate::stringify::{Stringify, Value}; use crate::{is_ide_completion, non_capitalized_ascii, Peek, PeekValue}; @@ -190,39 +190,11 @@ impl ToTokens for HtmlElement { )) }, ); - let class_attr = classes.as_ref().and_then(|classes| match classes { - ClassesForm::Tuple(classes) => { - let span = classes.span(); - let classes: Vec<_> = classes.elems.iter().collect(); - let n = classes.len(); - - let deprecation_warning = quote_spanned! {span=> - #[deprecated( - note = "the use of `(...)` with the attribute `class` is deprecated and will be removed in version 0.19. Use the `classes!` macro instead." - )] - fn deprecated_use_of_class() {} - - if false { - deprecated_use_of_class(); - }; - }; - Some(( - LitStr::new("class", span), - Value::Dynamic(quote! { - { - #deprecation_warning - - let mut __yew_classes = ::yew::html::Classes::with_capacity(#n); - #(__yew_classes.push(#classes);)* - __yew_classes - } - }), - None, - )) - } - ClassesForm::Single(classes) => { - match classes.try_into_lit() { + let class_attr = + classes + .as_ref() + .and_then(|classes| match classes.value.try_into_lit() { Some(lit) => { if lit.value().is_empty() { None @@ -235,17 +207,16 @@ impl ToTokens for HtmlElement { } } None => { + let expr = &classes.value; Some(( - LitStr::new("class", classes.span()), + LitStr::new("class", classes.label.span()), Value::Dynamic(quote! { - ::std::convert::Into::<::yew::html::Classes>::into(#classes) + ::std::convert::Into::<::yew::html::Classes>::into(#expr) }), None, )) } - } - } - }); + }); fn apply_as(directive: Option<&PropDirective>) -> TokenStream { match directive { @@ -383,7 +354,7 @@ impl ToTokens for HtmlElement { } TagName::Expr(name) => { let vtag = Ident::new("__yew_vtag", name.span()); - let expr = &name.expr; + let expr = name.expr.as_ref().map(Group::stream); let vtag_name = Ident::new("__yew_vtag_name", expr.span()); let void_children = Ident::new("__yew_void_children", Span::mixed_site()); @@ -411,10 +382,6 @@ impl ToTokens for HtmlElement { // this way we get a nice error message (with the correct span) when the expression // doesn't return a valid value quote_spanned! {expr.span()=> { - #[allow(unused_braces)] - // e.g. html!{<@{"div"}/>} will set `#expr` to `{"div"}` - // (note the extra braces). Hence the need for the `allow`. - // Anyways to remove the braces? let mut #vtag_name = ::std::convert::Into::< ::yew::virtual_dom::AttrValue >::into(#expr); @@ -500,7 +467,7 @@ fn wrap_attr_value(value: T) -> TokenStream { pub struct DynamicName { at: Token![@], - expr: Option, + expr: Option, } impl Peek<'_, ()> for DynamicName { @@ -524,12 +491,7 @@ impl Parse for DynamicName { fn parse(input: ParseStream) -> syn::Result { let at = input.parse()?; // the expression block is optional, closing tags don't have it. - let expr = if input.cursor().group(Delimiter::Brace).is_some() { - Some(input.parse()?) - } else { - None - }; - + let expr = input.parse().ok(); Ok(Self { at, expr }) } } diff --git a/packages/yew-macro/src/props/element.rs b/packages/yew-macro/src/props/element.rs index cd50b71b692..17a90e3f9db 100644 --- a/packages/yew-macro/src/props/element.rs +++ b/packages/yew-macro/src/props/element.rs @@ -2,27 +2,13 @@ use std::collections::HashSet; use once_cell::sync::Lazy; use syn::parse::{Parse, ParseStream}; -use syn::{Expr, ExprTuple}; use super::{Prop, Props, SpecialProps}; -pub enum ClassesForm { - Tuple(ExprTuple), - Single(Box), -} -impl ClassesForm { - fn from_expr(expr: Expr) -> Self { - match expr { - Expr::Tuple(expr_tuple) => ClassesForm::Tuple(expr_tuple), - expr => ClassesForm::Single(Box::new(expr)), - } - } -} - pub struct ElementProps { pub attributes: Vec, pub listeners: Vec, - pub classes: Option, + pub classes: Option, pub booleans: Vec, pub value: Option, pub checked: Option, @@ -42,9 +28,7 @@ impl Parse for ElementProps { let booleans = props.drain_filter(|prop| BOOLEAN_SET.contains(prop.label.to_string().as_str())); - let classes = props - .pop("class") - .map(|prop| ClassesForm::from_expr(prop.value)); + let classes = props.pop("class"); let value = props.pop("value"); let checked = props.pop("checked"); let special = props.special; diff --git a/packages/yew-macro/tests/html_macro/block-pass.rs b/packages/yew-macro/tests/html_macro/block-pass.rs index d8f527e6e46..6a5bd15c632 100644 --- a/packages/yew-macro/tests/html_macro/block-pass.rs +++ b/packages/yew-macro/tests/html_macro/block-pass.rs @@ -37,27 +37,27 @@ pub struct u8; pub struct usize; fn main() { - ::yew::html! { <>{ "Hi" } }; - ::yew::html! { <>{ ::std::format!("Hello") } }; - ::yew::html! { <>{ ::std::string::ToString::to_string("Hello") } }; + _ = ::yew::html! { <>{ "Hi" } }; + _ = ::yew::html! { <>{ ::std::format!("Hello") } }; + _ = ::yew::html! { <>{ ::std::string::ToString::to_string("Hello") } }; let msg = "Hello"; - ::yew::html! {
{ msg }
}; + _ = ::yew::html! {
{ msg }
}; let subview = ::yew::html! { "subview!" }; - ::yew::html! {
{ subview }
}; + _ = ::yew::html! {
{ subview }
}; let subview = || ::yew::html! { "subview!" }; - ::yew::html! {
{ subview() }
}; + _ = ::yew::html! {
{ subview() }
}; - ::yew::html! { + _ = ::yew::html! {
    { for ::std::iter::Iterator::map(0..3, |num| { ::yew::html! { { num } }}) }
}; let item = |num| ::yew::html! {
  • { ::std::format!("item {}!", num) }
  • }; - ::yew::html! { + _ = ::yew::html! {
      { for ::std::iter::Iterator::map(0..3, item) }
    diff --git a/packages/yew-macro/tests/html_macro/component-any-children-pass.rs b/packages/yew-macro/tests/html_macro/component-any-children-pass.rs index c9b9e0f1777..d7b1ab3cb8e 100644 --- a/packages/yew-macro/tests/html_macro/component-any-children-pass.rs +++ b/packages/yew-macro/tests/html_macro/component-any-children-pass.rs @@ -159,10 +159,10 @@ pub fn RenderPropComp(_props: &RenderPropProps) -> ::yew::Html { } fn compile_pass() { - ::yew::html! { }; - ::yew::html! { }; + _ = ::yew::html! { }; + _ = ::yew::html! { }; - ::yew::html! { + _ = ::yew::html! { <> @@ -171,7 +171,7 @@ fn compile_pass() { let props = <::Properties as ::std::default::Default>::default(); let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -183,7 +183,7 @@ fn compile_pass() { }; - ::yew::html! { + _ = ::yew::html! { <> @@ -199,17 +199,17 @@ fn compile_pass() { }; let name_expr = "child"; - ::yew::html! { + _ = ::yew::html! { }; let string = "child"; let int = 1; - ::yew::html! { + _ = ::yew::html! { }; - ::yew::html! { + _ = ::yew::html! { <> as ::std::convert::From<_>>::from(|_| ()))} /> @@ -219,7 +219,7 @@ fn compile_pass() { }; let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -227,7 +227,7 @@ fn compile_pass() { let int = 1; let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -236,7 +236,7 @@ fn compile_pass() { let props = <::Properties as ::std::default::Default>::default(); let child_props = <::Properties as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -292,7 +292,7 @@ fn compile_pass() { ] }; - ::yew::html! { + _ = ::yew::html! { <> { ::std::iter::Iterator::collect::<::yew::virtual_dom::VNode>( @@ -321,9 +321,9 @@ fn compile_pass() { }; - ::yew::html_nested! { 1 }; + _ = ::yew::html_nested! { 1 }; - ::yew::html! { + _ = ::yew::html! { {|_arg| {}} diff --git a/packages/yew-macro/tests/html_macro/component-pass.rs b/packages/yew-macro/tests/html_macro/component-pass.rs index f971f66c4cb..5cc59c4208d 100644 --- a/packages/yew-macro/tests/html_macro/component-pass.rs +++ b/packages/yew-macro/tests/html_macro/component-pass.rs @@ -167,10 +167,10 @@ mod scoped { } fn compile_pass() { - ::yew::html! { }; - ::yew::html! { }; + _ = ::yew::html! { }; + _ = ::yew::html! { }; - ::yew::html! { + _ = ::yew::html! { <> @@ -179,7 +179,7 @@ fn compile_pass() { let props = <::Properties as ::std::default::Default>::default(); let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -191,7 +191,7 @@ fn compile_pass() { }; - ::yew::html! { + _ = ::yew::html! { <> @@ -207,17 +207,17 @@ fn compile_pass() { }; let name_expr = "child"; - ::yew::html! { + _ = ::yew::html! { }; let string = "child"; let int = 1; - ::yew::html! { + _ = ::yew::html! { }; - ::yew::html! { + _ = ::yew::html! { <> as ::std::convert::From<_>>::from(|_| ()))} /> @@ -227,7 +227,7 @@ fn compile_pass() { }; let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -235,7 +235,7 @@ fn compile_pass() { let int = 1; let node_ref = <::yew::NodeRef as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -244,7 +244,7 @@ fn compile_pass() { let props = <::Properties as ::std::default::Default>::default(); let child_props = <::Properties as ::std::default::Default>::default(); - ::yew::html! { + _ = ::yew::html! { <> @@ -287,7 +287,7 @@ fn compile_pass() { }; - ::yew::html! { + _ = ::yew::html! { <> @@ -296,7 +296,7 @@ fn compile_pass() { }; - ::yew::html! { + _ = ::yew::html! { @@ -318,13 +318,13 @@ fn compile_pass() { ::yew::html_nested! { }, ::yew::html_nested! { }, ]; - ::yew::html! { + _ = ::yew::html! { { ::std::clone::Clone::clone(&children) } }; // https://github.com/yewstack/yew/issues/1527 - ::yew::html! { + _ = ::yew::html! { { for children } @@ -343,7 +343,7 @@ fn compile_pass() { ] }; - ::yew::html! { + _ = ::yew::html! { <> { ::std::iter::Iterator::collect::<::yew::virtual_dom::VNode>( @@ -372,7 +372,7 @@ fn compile_pass() { }; - ::yew::html_nested! { 1 }; + _ = ::yew::html_nested! { 1 }; } #[derive( diff --git a/packages/yew-macro/tests/html_macro/dyn-element-pass.rs b/packages/yew-macro/tests/html_macro/dyn-element-pass.rs index 27dd094c0f9..0ab298fe342 100644 --- a/packages/yew-macro/tests/html_macro/dyn-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/dyn-element-pass.rs @@ -43,17 +43,16 @@ fn main() { move || ::std::option::Option::unwrap(::std::iter::Iterator::next(&mut it)) }; - ::yew::html! { + _ = ::yew::html! { <@{ dyn_tag() }> <@{ next_extra_tag() } class="extra-a"/> <@{ next_extra_tag() } class="extra-b"/> }; - ::yew::html! { + _ = ::yew::html! { <@{ - let tag = dyn_tag(); - if tag == "test" { + if dyn_tag() == "test" { "div" } else { "a" diff --git a/packages/yew-macro/tests/html_macro/element-fail.rs b/packages/yew-macro/tests/html_macro/element-fail.rs index ac8f217e0f1..52f494fc67f 100644 --- a/packages/yew-macro/tests/html_macro/element-fail.rs +++ b/packages/yew-macro/tests/html_macro/element-fail.rs @@ -76,11 +76,7 @@ fn compile_fail() { // type mismatch html! { <@{55}> }; - // check for deprecation warning - html! {
    }; - // Missing curly braces - html! {
    }; html! { }; html! { }; html! { }; diff --git a/packages/yew-macro/tests/html_macro/element-fail.stderr b/packages/yew-macro/tests/html_macro/element-fail.stderr index 9a413f6ef4e..11f9e7d631a 100644 --- a/packages/yew-macro/tests/html_macro/element-fail.stderr +++ b/packages/yew-macro/tests/html_macro/element-fail.stderr @@ -142,38 +142,14 @@ error: dynamic closing tags must not have a body (hint: replace it with just ` }; | ^^^^^^^^ -error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { - attrs: [], - paren_token: Paren, - elems: [ - Expr::Lit { - attrs: [], - lit: Lit::Str { - token: "deprecated", - }, - }, - Comma, - Expr::Lit { - attrs: [], - lit: Lit::Str { - token: "warning", - }, - }, - ], - } - --> tests/html_macro/element-fail.rs:83:24 - | -83 | html! {
    }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { attrs: [], paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:84:24 + --> tests/html_macro/element-fail.rs:80:24 | -84 | html! { }; +80 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -181,9 +157,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:85:24 + --> tests/html_macro/element-fail.rs:81:24 | -85 | html! { }; +81 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -197,7 +173,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2632..2636), + span: #0 bytes(2482..2486), }, arguments: PathArguments::None, }, @@ -214,9 +190,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:86:28 + --> tests/html_macro/element-fail.rs:82:28 | -86 | html! { }; +82 | html! { }; | ^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Path { @@ -228,16 +204,16 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2672..2683), + span: #0 bytes(2522..2533), }, arguments: PathArguments::None, }, ], }, } - --> tests/html_macro/element-fail.rs:87:27 + --> tests/html_macro/element-fail.rs:83:27 | -87 | html! { }; +83 | html! { }; | ^^^^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -251,7 +227,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2711..2715), + span: #0 bytes(2561..2565), }, arguments: PathArguments::None, }, @@ -269,7 +245,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2716..2727), + span: #0 bytes(2566..2577), }, arguments: PathArguments::None, }, @@ -278,9 +254,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:88:22 + --> tests/html_macro/element-fail.rs:84:22 | -88 | html! { }; +84 | html! { }; | ^^^^^^^^^^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -294,7 +270,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2755..2759), + span: #0 bytes(2605..2609), }, arguments: PathArguments::None, }, @@ -311,9 +287,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:89:21 + --> tests/html_macro/element-fail.rs:85:21 | -89 | html! { }; +85 | html! { }; | ^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -321,9 +297,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:90:25 + --> tests/html_macro/element-fail.rs:86:25 | -90 | html! { }; +86 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -331,9 +307,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:91:26 + --> tests/html_macro/element-fail.rs:87:26 | -91 | html! { }; +87 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Path { @@ -345,26 +321,18 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2862..2873), + span: #0 bytes(2712..2723), }, arguments: PathArguments::None, }, ], }, } - --> tests/html_macro/element-fail.rs:92:27 + --> tests/html_macro/element-fail.rs:88:27 | -92 | html! { }; +88 | html! { }; | ^^^^^^^^^^^ -warning: use of deprecated function `compile_fail::deprecated_use_of_class`: the use of `(...)` with the attribute `class` is deprecated and will be removed in version 0.19. Use the `classes!` macro instead. - --> tests/html_macro/element-fail.rs:80:25 - | -80 | html! {
    }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(deprecated)]` on by default - error[E0308]: mismatched types --> tests/html_macro/element-fail.rs:36:28 | @@ -662,10 +630,10 @@ error[E0277]: the trait bound `(): IntoPropValue` is not satisfied = note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `implicit_clone::unsync::IString: From<{integer}>` is not satisfied - --> tests/html_macro/element-fail.rs:77:15 + --> tests/html_macro/element-fail.rs:77:16 | 77 | html! { <@{55}> }; - | ^^^^ the trait `From<{integer}>` is not implemented for `implicit_clone::unsync::IString` + | ^^ the trait `From<{integer}>` is not implemented for `implicit_clone::unsync::IString` | = help: the following other types implement trait `From`: > diff --git a/packages/yew-macro/tests/html_macro/generic-component-pass.rs b/packages/yew-macro/tests/html_macro/generic-component-pass.rs index 4aca8a05457..856fff40fd8 100644 --- a/packages/yew-macro/tests/html_macro/generic-component-pass.rs +++ b/packages/yew-macro/tests/html_macro/generic-component-pass.rs @@ -76,24 +76,24 @@ where } fn compile_pass() { - ::yew::html! { /> }; - ::yew::html! { /> }; - ::yew::html! { >> }; - ::yew::html! { >> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { >> }; + _ = ::yew::html! { >> }; - ::yew::html! { > /> }; - ::yew::html! { >>>> }; + _ = ::yew::html! { > /> }; + _ = ::yew::html! { >>>> }; - ::yew::html! { /> }; - ::yew::html! { >> }; - ::yew::html! { /> }; - ::yew::html! { >> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { >> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { >> }; - ::yew::html! { /> }; - ::yew::html! { >> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { >> }; - ::yew::html! { /> }; - ::yew::html! { >> }; + _ = ::yew::html! { /> }; + _ = ::yew::html! { >> }; } fn main() {} diff --git a/packages/yew-macro/tests/html_macro/html-element-pass.rs b/packages/yew-macro/tests/html_macro/html-element-pass.rs index dc81c66db22..5c05322b050 100644 --- a/packages/yew-macro/tests/html_macro/html-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-element-pass.rs @@ -48,7 +48,7 @@ fn compile_pass() { let attr_val_none: ::std::option::Option<::yew::virtual_dom::AttrValue> = ::std::option::Option::None; - ::yew::html! { + _ = ::yew::html! {
    @@ -92,8 +92,7 @@ fn compile_pass() { <@{ - let tag = dyn_tag(); - if tag == "test" { + if dyn_tag() == "test" { "div" } else { "a" @@ -113,17 +112,17 @@ fn compile_pass() { ::yew::html! { { "Hello" } }, ::yew::html! { { "World" } }, ]; - ::yew::html! {
    {children}
    }; + _ = ::yew::html! {
    {children}
    }; // handle misleading angle brackets - ::yew::html! {
    ::default()}>
    }; - ::yew::html! {
    }; + _ = ::yew::html! {
    ::default()}>
    }; + _ = ::yew::html! {
    }; // test for https://github.com/yewstack/yew/issues/2810 - ::yew::html! {
    }; + _ = ::yew::html! {
    }; let option_vnode = ::std::option::Option::Some(::yew::html! {}); - ::yew::html! {
    {option_vnode}
    }; + _ = ::yew::html! {
    {option_vnode}
    }; } fn main() {} diff --git a/packages/yew-macro/tests/html_macro/html-if-pass.rs b/packages/yew-macro/tests/html_macro/html-if-pass.rs index aa95ba9d1d7..59ce730dcbf 100644 --- a/packages/yew-macro/tests/html_macro/html-if-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-if-pass.rs @@ -1,35 +1,35 @@ #![no_implicit_prelude] fn compile_pass_lit() { - ::yew::html! { if true {} }; - ::yew::html! { if true {
    } }; - ::yew::html! { if true {
    } }; - ::yew::html! { if true { <>
    } }; - ::yew::html! { if true { { ::yew::html! {} } } }; - ::yew::html! { if true { { { let _x = 42; ::yew::html! {} } } } }; - ::yew::html! { if true {} else {} }; - ::yew::html! { if true {} else if true {} }; - ::yew::html! { if true {} else if true {} else {} }; - ::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { { text } } }; - ::yew::html! { <>
    if true {}
    }; - ::yew::html! {
    if true {}
    }; + _ = ::yew::html! { if true {} }; + _ = ::yew::html! { if true {
    } }; + _ = ::yew::html! { if true {
    } }; + _ = ::yew::html! { if true { <>
    } }; + _ = ::yew::html! { if true { { ::yew::html! {} } } }; + _ = ::yew::html! { if true { { { let _x = 42; ::yew::html! {} } } } }; + _ = ::yew::html! { if true {} else {} }; + _ = ::yew::html! { if true {} else if true {} }; + _ = ::yew::html! { if true {} else if true {} else {} }; + _ = ::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { { text } } }; + _ = ::yew::html! { <>
    if true {}
    }; + _ = ::yew::html! {
    if true {}
    }; } fn compile_pass_expr() { let condition = true; - ::yew::html! { if condition {} }; - ::yew::html! { if condition {
    } }; - ::yew::html! { if condition {
    } }; - ::yew::html! { if condition { <>
    } }; - ::yew::html! { if condition { { ::yew::html! {} } } }; - ::yew::html! { if condition { { { let _x = 42; ::yew::html! {} } } } }; - ::yew::html! { if condition {} else {} }; - ::yew::html! { if condition {} else if condition {} }; - ::yew::html! { if condition {} else if condition {} else {} }; - ::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { { text } } }; - ::yew::html! { <>
    if condition {}
    }; - ::yew::html! {
    if condition {}
    }; + _ = ::yew::html! { if condition {} }; + _ = ::yew::html! { if condition {
    } }; + _ = ::yew::html! { if condition {
    } }; + _ = ::yew::html! { if condition { <>
    } }; + _ = ::yew::html! { if condition { { ::yew::html! {} } } }; + _ = ::yew::html! { if condition { { { let _x = 42; ::yew::html! {} } } } }; + _ = ::yew::html! { if condition {} else {} }; + _ = ::yew::html! { if condition {} else if condition {} }; + _ = ::yew::html! { if condition {} else if condition {} else {} }; + _ = ::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { { text } } }; + _ = ::yew::html! { <>
    if condition {}
    }; + _ = ::yew::html! {
    if condition {}
    }; } fn main() {} diff --git a/packages/yew-macro/tests/html_macro/html-node-pass.rs b/packages/yew-macro/tests/html_macro/html-node-pass.rs index a8c9dd1f7b3..d1a05d4c759 100644 --- a/packages/yew-macro/tests/html_macro/html-node-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-node-pass.rs @@ -37,23 +37,23 @@ pub struct u8; pub struct usize; fn compile_pass() { - ::yew::html! { "" }; - ::yew::html! { 'a' }; - ::yew::html! { "hello" }; - ::yew::html! { 42 }; - ::yew::html! { 1.234 }; + _ = ::yew::html! { "" }; + _ = ::yew::html! { 'a' }; + _ = ::yew::html! { "hello" }; + _ = ::yew::html! { 42 }; + _ = ::yew::html! { 1.234 }; - ::yew::html! { { "" } }; - ::yew::html! { { 'a' } }; - ::yew::html! { { "hello" } }; - ::yew::html! { { 42 } }; - ::yew::html! { { 1.234 } }; + _ = ::yew::html! { { "" } }; + _ = ::yew::html! { { 'a' } }; + _ = ::yew::html! { { "hello" } }; + _ = ::yew::html! { { 42 } }; + _ = ::yew::html! { { 1.234 } }; - ::yew::html! { ::std::format!("Hello") }; - ::yew::html! { {<::std::string::String as ::std::convert::From<&::std::primitive::str>>::from("Hello") } }; + _ = ::yew::html! { ::std::format!("Hello") }; + _ = ::yew::html! { {<::std::string::String as ::std::convert::From<&::std::primitive::str>>::from("Hello") } }; let msg = "Hello"; - ::yew::html! { msg }; + _ = ::yew::html! { msg }; } fn main() {} diff --git a/packages/yew-macro/tests/html_macro/iterable-pass.rs b/packages/yew-macro/tests/html_macro/iterable-pass.rs index 18eadf7b042..1f41185f3a2 100644 --- a/packages/yew-macro/tests/html_macro/iterable-pass.rs +++ b/packages/yew-macro/tests/html_macro/iterable-pass.rs @@ -45,13 +45,13 @@ fn empty_iter() -> impl ::std::iter::Iterator { } fn main() { - ::yew::html! { for empty_iter() }; - ::yew::html! { for { empty_iter() } }; + _ = ::yew::html! { for empty_iter() }; + _ = ::yew::html! { for { empty_iter() } }; let empty = empty_vec(); - ::yew::html! { for empty }; + _ = ::yew::html! { for empty }; - ::yew::html! { for empty_vec() }; - ::yew::html! { for ::std::iter::IntoIterator::into_iter(empty_vec()) }; - ::yew::html! { for ::std::iter::Iterator::map(0..3, |num| { ::yew::html! { { num } } }) }; + _ = ::yew::html! { for empty_vec() }; + _ = ::yew::html! { for ::std::iter::IntoIterator::into_iter(empty_vec()) }; + _ = ::yew::html! { for ::std::iter::Iterator::map(0..3, |num| { ::yew::html! { { num } } }) }; } diff --git a/packages/yew-macro/tests/html_macro/list-pass.rs b/packages/yew-macro/tests/html_macro/list-pass.rs index 3cbe619eaeb..380e4792d1a 100644 --- a/packages/yew-macro/tests/html_macro/list-pass.rs +++ b/packages/yew-macro/tests/html_macro/list-pass.rs @@ -37,15 +37,15 @@ pub struct u8; pub struct usize; fn main() { - ::yew::html! {}; - ::yew::html! { <> }; - ::yew::html! { + _ = ::yew::html! {}; + _ = ::yew::html! { <> }; + _ = ::yew::html! { <> <> <> }; - ::yew::html! { + _ = ::yew::html! { }; @@ -54,5 +54,5 @@ fn main() { ::yew::html! { { "Hello" } }, ::yew::html! { { "World" } }, ]; - ::yew::html! { <>{ children } }; + _ = ::yew::html! { <>{ children } }; } diff --git a/packages/yew-macro/tests/html_macro/node-pass.rs b/packages/yew-macro/tests/html_macro/node-pass.rs index 1dfaea9c8a1..ed38c3e77cf 100644 --- a/packages/yew-macro/tests/html_macro/node-pass.rs +++ b/packages/yew-macro/tests/html_macro/node-pass.rs @@ -37,23 +37,23 @@ pub struct u8; pub struct usize; fn main() { - ::yew::html! { "" }; - ::yew::html! { 'a' }; - ::yew::html! { "hello" }; - ::yew::html! { "42" }; - ::yew::html! { "1.234" }; - ::yew::html! { "true" }; + _ = ::yew::html! { "" }; + _ = ::yew::html! { 'a' }; + _ = ::yew::html! { "hello" }; + _ = ::yew::html! { "42" }; + _ = ::yew::html! { "1.234" }; + _ = ::yew::html! { "true" }; - ::yew::html! { { "" } }; - ::yew::html! { { 'a' } }; - ::yew::html! { { "hello" } }; - ::yew::html! { { "42" } }; - ::yew::html! { { "1.234" } }; - ::yew::html! { { "true" } }; + _ = ::yew::html! { { "" } }; + _ = ::yew::html! { { 'a' } }; + _ = ::yew::html! { { "hello" } }; + _ = ::yew::html! { { "42" } }; + _ = ::yew::html! { { "1.234" } }; + _ = ::yew::html! { { "true" } }; - ::yew::html! { ::std::format!("Hello") }; - ::yew::html! { ::std::string::ToString::to_string("Hello") }; + _ = ::yew::html! { ::std::format!("Hello") }; + _ = ::yew::html! { ::std::string::ToString::to_string("Hello") }; let msg = "Hello"; - ::yew::html! { msg }; + _ = ::yew::html! { msg }; } diff --git a/packages/yew-macro/tests/html_macro/svg-pass.rs b/packages/yew-macro/tests/html_macro/svg-pass.rs index eb1bb3a0963..f333c265203 100644 --- a/packages/yew-macro/tests/html_macro/svg-pass.rs +++ b/packages/yew-macro/tests/html_macro/svg-pass.rs @@ -39,7 +39,7 @@ pub struct usize; fn main() { // Ensure Rust keywords can be used as element names. // See: #1771 - ::yew::html! { + _ = ::yew::html! { @@ -49,7 +49,7 @@ fn main() { }; // some general SVG - ::yew::html! { + _ = ::yew::html! { diff --git a/packages/yew/src/dom_bundle/btag/mod.rs b/packages/yew/src/dom_bundle/btag/mod.rs index 8a97c1ef33d..a376d3b1fc9 100644 --- a/packages/yew/src/dom_bundle/btag/mod.rs +++ b/packages/yew/src/dom_bundle/btag/mod.rs @@ -830,11 +830,11 @@ mod tests { fn dynamic_tags_work() { let (root, scope, parent) = setup_parent(); - let elem = html! { <@{ + let elem = html! { <@{{ let mut builder = String::new(); builder.push('a'); builder - }/> }; + }}/> }; let (_, mut elem) = elem.attach(&root, &scope, &parent, DomSlot::at_end()); let vtag = assert_btag_mut(&mut elem);