From 6ae67b684336b39bed7cb6cb087ad2131baf88c7 Mon Sep 17 00:00:00 2001 From: Farookh Zaheer Siddiqui <129654632+FarukhS52@users.noreply.github.com> Date: Sat, 28 Oct 2023 21:00:53 +0530 Subject: [PATCH 1/4] Fix Typo (#3495) * Update CONTRIBUTING.md * Update README.md --- CONTRIBUTING.md | 2 +- examples/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d7c4ebaf738..b3e09b36958 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -75,7 +75,7 @@ and follow the repository's README. ## Writing APIs -When building new APIs, think about what it would be like to use them. Would this API cause confusing and hard to pin error mesages? Would this API integrate well with other APIs? Is it intuitive to use this API? +When building new APIs, think about what it would be like to use them. Would this API cause confusing and hard to pin error messages? Would this API integrate well with other APIs? Is it intuitive to use this API? Below, you can find some useful guidance and best practices on how to write APIs. These are only _guidelines_ and while they are helpful and should be followed where possible, in some cases, it may not be possible to do so. diff --git a/examples/README.md b/examples/README.md index 1b5a01fa937..e196494df3e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,7 +3,7 @@ ## How to Run The examples are built with [trunk](https://github.com/thedodd/trunk). -Once you have the development envrionment fully set up (see [documentation](https://yew.rs/docs/next/getting-started/introduction)), +Once you have the development environment fully set up (see [documentation](https://yew.rs/docs/next/getting-started/introduction)), running an example is as easy as running a single command: ```bash From bae0141f981b7ffe5abf79c5f2310463894f593e Mon Sep 17 00:00:00 2001 From: Tim Kurdov Date: Sat, 28 Oct 2023 16:36:56 +0100 Subject: [PATCH 2/4] 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); From 40ed8a205df22dc88e1fd90235ac52b8b1c9a4af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 29 Oct 2023 00:45:06 +0900 Subject: [PATCH 3/4] Bump the cargo-deps group with 5 updates (#3490) Bumps the cargo-deps group with 5 updates: | Package | From | To | | --- | --- | --- | | [serde](https://github.com/serde-rs/serde) | `1.0.189` | `1.0.190` | | [futures](https://github.com/rust-lang/futures-rs) | `0.3.28` | `0.3.29` | | [clap](https://github.com/clap-rs/clap) | `4.4.6` | `4.4.7` | | [base64](https://github.com/marshallpierce/rust-base64) | `0.21.4` | `0.21.5` | | [fake](https://github.com/cksac/fake-rs) | `2.8.0` | `2.9.1` | Updates `serde` from 1.0.189 to 1.0.190 - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.189...v1.0.190) Updates `futures` from 0.3.28 to 0.3.29 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.28...0.3.29) Updates `clap` from 4.4.6 to 4.4.7 - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.4.6...v4.4.7) Updates `base64` from 0.21.4 to 0.21.5 - [Changelog](https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md) - [Commits](https://github.com/marshallpierce/rust-base64/compare/v0.21.4...v0.21.5) Updates `fake` from 2.8.0 to 2.9.1 - [Commits](https://github.com/cksac/fake-rs/commits) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: futures dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: base64 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: fake dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 106 +++++++++++++-------------- examples/file_upload/Cargo.toml | 2 +- examples/keyed_list/Cargo.toml | 2 +- examples/simple_ssr/Cargo.toml | 2 +- examples/web_worker_prime/Cargo.toml | 4 +- packages/yew-agent/Cargo.toml | 2 +- tools/benchmark-ssr/Cargo.toml | 2 +- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08dc1cfb29c..b560bd7eaef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,7 +117,7 @@ name = "async_clock" version = "0.0.1" dependencies = [ "chrono", - "futures 0.3.28", + "futures 0.3.29", "gloo-net 0.4.0", "yew", ] @@ -220,9 +220,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "base64ct" @@ -392,9 +392,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" dependencies = [ "clap_builder", "clap_derive", @@ -402,9 +402,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ "anstream", "anstyle", @@ -415,9 +415,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", @@ -427,9 +427,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "cobs" @@ -677,6 +677,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "deunicode" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1abaf4d861455be59f64fd2b55606cb151fce304ede7165f410243ce96bde6" + [[package]] name = "digest" version = "0.10.7" @@ -796,12 +802,12 @@ dependencies = [ [[package]] name = "fake" -version = "2.8.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9af7b0c58ac9d03169e27f080616ce9f64004edca3d2ef4147a811c21b23b319" +checksum = "26221445034074d46b276e13eb97a265ebdb8ed8da705c4dddd3dd20b66b45d2" dependencies = [ + "deunicode", "rand", - "unidecode", ] [[package]] @@ -827,7 +833,7 @@ dependencies = [ name = "file_upload" version = "0.1.0" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "gloo 0.10.0", "js-sys", "web-sys", @@ -928,9 +934,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", @@ -943,9 +949,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", "futures-sink", @@ -953,15 +959,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" dependencies = [ "futures-core", "futures-task", @@ -970,15 +976,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", @@ -987,21 +993,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-channel", "futures-core", @@ -1402,7 +1408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2cbd4c35cc3a2b1fb792318acc06bd514193f6d058173da5cdbcdabe6514303" dependencies = [ "bincode", - "futures 0.3.28", + "futures 0.3.29", "gloo-utils 0.2.0", "gloo-worker-macros", "js-sys", @@ -2271,7 +2277,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b" dependencies = [ - "futures 0.3.28", + "futures 0.3.29", "rustversion", "thiserror", ] @@ -2395,7 +2401,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03b55e106e5791fa5a13abd13c85d6127312e8e09098059ca2bc9b03ca4cf488" dependencies = [ - "futures 0.3.28", + "futures 0.3.29", "gloo 0.8.1", "num_cpus", "once_cell", @@ -2512,7 +2518,7 @@ version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "bytes", "encoding_rs", "futures-core", @@ -2615,7 +2621,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", ] [[package]] @@ -2682,9 +2688,9 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" dependencies = [ "serde_derive", ] @@ -2702,9 +2708,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", @@ -2769,7 +2775,7 @@ version = "0.1.0" dependencies = [ "bytes", "clap", - "futures 0.3.28", + "futures 0.3.29", "log", "reqwest", "serde", @@ -2833,7 +2839,7 @@ dependencies = [ "clap", "env_logger", "function_router", - "futures 0.3.28", + "futures 0.3.29", "hyper", "jemallocator", "log", @@ -3349,12 +3355,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unidecode" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc" - [[package]] name = "url" version = "2.4.0" @@ -3831,7 +3831,7 @@ dependencies = [ "base64ct", "bincode", "console_error_panic_hook", - "futures 0.3.28", + "futures 0.3.29", "gloo 0.10.0", "html-escape", "implicit-clone", @@ -3856,7 +3856,7 @@ dependencies = [ name = "yew-agent" version = "0.3.0" dependencies = [ - "futures 0.3.28", + "futures 0.3.29", "gloo-worker 0.4.1", "serde", "wasm-bindgen", @@ -3938,7 +3938,7 @@ dependencies = [ name = "yew-worker-prime" version = "0.1.0" dependencies = [ - "futures 0.3.28", + "futures 0.3.29", "primes", "serde", "yew", diff --git a/examples/file_upload/Cargo.toml b/examples/file_upload/Cargo.toml index 20adf651a4f..3c4d3817a5e 100644 --- a/examples/file_upload/Cargo.toml +++ b/examples/file_upload/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" [dependencies] js-sys = "0.3" yew = { path = "../../packages/yew", features = ["csr"] } -base64 = "0.21.4" +base64 = "0.21.5" gloo = "0.10" [dependencies.web-sys] diff --git a/examples/keyed_list/Cargo.toml b/examples/keyed_list/Cargo.toml index 3273faed3c4..3b1b9eeb4c6 100644 --- a/examples/keyed_list/Cargo.toml +++ b/examples/keyed_list/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -fake = "2.8.0" +fake = "2.9.1" getrandom = { version = "0.2", features = ["js"] } instant = { version = "0.1", features = ["wasm-bindgen"] } log = "0.4" diff --git a/examples/simple_ssr/Cargo.toml b/examples/simple_ssr/Cargo.toml index b99734e784c..cb602eb4e70 100644 --- a/examples/simple_ssr/Cargo.toml +++ b/examples/simple_ssr/Cargo.toml @@ -15,7 +15,7 @@ required-features = ["ssr"] [dependencies] yew = { path = "../../packages/yew" } reqwest = { version = "0.11.22", features = ["json"] } -serde = { version = "1.0.189", features = ["derive"] } +serde = { version = "1.0.190", features = ["derive"] } uuid = { version = "1.5.0", features = ["serde"] } futures = "0.3" bytes = "1.5" diff --git a/examples/web_worker_prime/Cargo.toml b/examples/web_worker_prime/Cargo.toml index e839c715f59..f33cdccf54e 100644 --- a/examples/web_worker_prime/Cargo.toml +++ b/examples/web_worker_prime/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" [dependencies] yew-agent = { path = "../../packages/yew-agent" } yew = { path = "../../packages/yew", features = ["csr"] } -futures = "0.3.25" +futures = "0.3.29" primes = "0.3.0" -serde = { version = "1.0.189", features = ["derive"] } +serde = { version = "1.0.190", features = ["derive"] } diff --git a/packages/yew-agent/Cargo.toml b/packages/yew-agent/Cargo.toml index f779333d870..2007b54f86f 100644 --- a/packages/yew-agent/Cargo.toml +++ b/packages/yew-agent/Cargo.toml @@ -20,4 +20,4 @@ futures = "0.3" yew-agent-macro = { version = "0.2", path = "../yew-agent-macro" } [dev-dependencies] -serde = "1.0.189" +serde = "1.0.190" diff --git a/tools/benchmark-ssr/Cargo.toml b/tools/benchmark-ssr/Cargo.toml index 28ef89dfc48..4b6ad7e0e4d 100644 --- a/tools/benchmark-ssr/Cargo.toml +++ b/tools/benchmark-ssr/Cargo.toml @@ -12,7 +12,7 @@ tokio = { version = "1.33", features = ["full"] } average = "0.14.1" tabled = "0.14.0" indicatif = "0.17.7" -serde = { version = "1.0.189", features = ["derive"] } +serde = { version = "1.0.190", features = ["derive"] } serde_json = "1.0.107" clap = { version = "4", features = ["derive"] } From d790e1beab825d2c7936108f9050bfc8f2760217 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Sat, 28 Oct 2023 22:24:34 +0500 Subject: [PATCH 4/4] Allow setting JsValue as properties (#3458) * Allow setting JsValue as properties * fix tests & CI * Rc::new * Workaround for Rust <1.72 * more Rc::new * ci green? --- .../yew-macro/src/html_tree/html_element.rs | 49 +++++--- .../yew/src/dom_bundle/btag/attributes.rs | 108 +++++++++--------- packages/yew/src/virtual_dom/mod.rs | 70 ++++++++---- packages/yew/src/virtual_dom/vtag.rs | 11 +- 4 files changed, 145 insertions(+), 93 deletions(-) diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index 83a4faf0059..ee588305de6 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -218,27 +218,35 @@ impl ToTokens for HtmlElement { } }); - fn apply_as(directive: Option<&PropDirective>) -> TokenStream { - match directive { - Some(PropDirective::ApplyAsProperty(token)) => { - quote_spanned!(token.span()=> ::yew::virtual_dom::ApplyAttributeAs::Property) - } - None => quote!(::yew::virtual_dom::ApplyAttributeAs::Attribute), - } - } - /// Try to turn attribute list into a `::yew::virtual_dom::Attributes::Static` fn try_into_static( src: &[(LitStr, Value, Option)], ) -> Option { + if src + .iter() + .any(|(_, _, d)| matches!(d, Some(PropDirective::ApplyAsProperty(_)))) + { + // don't try to make a static attribute list if there are any properties to + // assign + return None; + } let mut kv = Vec::with_capacity(src.len()); for (k, v, directive) in src.iter() { let v = match v { Value::Static(v) => quote! { #v }, Value::Dynamic(_) => return None, }; - let apply_as = apply_as(directive.as_ref()); - kv.push(quote! { ( #k, #v, #apply_as ) }); + let v = match directive { + Some(PropDirective::ApplyAsProperty(token)) => { + quote_spanned!(token.span()=> ::yew::virtual_dom::AttributeOrProperty::Property( + ::std::convert::Into::into(#v) + )) + } + None => quote!(::yew::virtual_dom::AttributeOrProperty::Static( + #v + )), + }; + kv.push(quote! { ( #k, #v) }); } Some(quote! { ::yew::virtual_dom::Attributes::Static(&[#(#kv),*]) }) @@ -251,9 +259,22 @@ impl ToTokens for HtmlElement { try_into_static(&attrs).unwrap_or_else(|| { let keys = attrs.iter().map(|(k, ..)| quote! { #k }); let values = attrs.iter().map(|(_, v, directive)| { - let apply_as = apply_as(directive.as_ref()); - let value = wrap_attr_value(v); - quote! { ::std::option::Option::map(#value, |it| (it, #apply_as)) } + let value = match directive { + Some(PropDirective::ApplyAsProperty(token)) => { + quote_spanned!(token.span()=> ::std::option::Option::Some( + ::yew::virtual_dom::AttributeOrProperty::Property( + ::std::convert::Into::into(#v) + )) + ) + } + None => { + let value = wrap_attr_value(v); + quote! { + ::std::option::Option::map(#value, ::yew::virtual_dom::AttributeOrProperty::Attribute) + } + }, + }; + quote! { #value } }); quote! { ::yew::virtual_dom::Attributes::Dynamic{ diff --git a/packages/yew/src/dom_bundle/btag/attributes.rs b/packages/yew/src/dom_bundle/btag/attributes.rs index e2f41e11498..d56be61021d 100644 --- a/packages/yew/src/dom_bundle/btag/attributes.rs +++ b/packages/yew/src/dom_bundle/btag/attributes.rs @@ -9,7 +9,7 @@ use yew::AttrValue; use super::Apply; use crate::dom_bundle::BSubtree; use crate::virtual_dom::vtag::{InputFields, Value}; -use crate::virtual_dom::{ApplyAttributeAs, Attributes}; +use crate::virtual_dom::{AttributeOrProperty, Attributes}; impl Apply for Value { type Bundle = Self; @@ -92,23 +92,23 @@ impl Attributes { #[cold] fn apply_diff_index_maps( el: &Element, - new: &IndexMap, - old: &IndexMap, + new: &IndexMap, + old: &IndexMap, ) { for (key, value) in new.iter() { match old.get(key) { Some(old_value) => { if value != old_value { - Self::set(el, key, value.0.as_ref(), value.1); + Self::set(el, key, value); } } - None => Self::set(el, key, value.0.as_ref(), value.1), + None => Self::set(el, key, value), } } - for (key, (_, apply_as)) in old.iter() { + for (key, value) in old.iter() { if !new.contains_key(key) { - Self::remove(el, key, *apply_as); + Self::remove(el, key, value); } } } @@ -117,26 +117,17 @@ impl Attributes { /// Works with any [Attributes] variants. #[cold] fn apply_diff_as_maps<'a>(el: &Element, new: &'a Self, old: &'a Self) { - fn collect(src: &Attributes) -> HashMap<&str, (&str, ApplyAttributeAs)> { + fn collect(src: &Attributes) -> HashMap<&str, &AttributeOrProperty> { use Attributes::*; match src { - Static(arr) => (*arr) - .iter() - .map(|(k, v, apply_as)| (*k, (*v, *apply_as))) - .collect(), + Static(arr) => (*arr).iter().map(|(k, v)| (*k, v)).collect(), Dynamic { keys, values } => keys .iter() .zip(values.iter()) - .filter_map(|(k, v)| { - v.as_ref() - .map(|(v, apply_as)| (*k, (v.as_ref(), *apply_as))) - }) - .collect(), - IndexMap(m) => m - .iter() - .map(|(k, (v, apply_as))| (k.as_ref(), (v.as_ref(), *apply_as))) + .filter_map(|(k, v)| v.as_ref().map(|v| (*k, v))) .collect(), + IndexMap(m) => m.iter().map(|(k, v)| (k.as_ref(), v)).collect(), } } @@ -149,37 +140,39 @@ impl Attributes { Some(old) => old != new, None => true, } { - Self::set(el, k, new.0, new.1); + Self::set(el, k, new); } } // Remove missing - for (k, (_, apply_as)) in old.iter() { + for (k, old_value) in old.iter() { if !new.contains_key(k) { - Self::remove(el, k, *apply_as); + Self::remove(el, k, old_value); } } } - fn set(el: &Element, key: &str, value: &str, apply_as: ApplyAttributeAs) { - match apply_as { - ApplyAttributeAs::Attribute => el + fn set(el: &Element, key: &str, value: &AttributeOrProperty) { + match value { + AttributeOrProperty::Attribute(value) => el + .set_attribute(intern(key), value) + .expect("invalid attribute key"), + AttributeOrProperty::Static(value) => el .set_attribute(intern(key), value) .expect("invalid attribute key"), - ApplyAttributeAs::Property => { + AttributeOrProperty::Property(value) => { let key = JsValue::from_str(key); - let value = JsValue::from_str(value); - js_sys::Reflect::set(el.as_ref(), &key, &value).expect("could not set property"); + js_sys::Reflect::set(el.as_ref(), &key, value).expect("could not set property"); } } } - fn remove(el: &Element, key: &str, apply_as: ApplyAttributeAs) { - match apply_as { - ApplyAttributeAs::Attribute => el + fn remove(el: &Element, key: &str, old_value: &AttributeOrProperty) { + match old_value { + AttributeOrProperty::Attribute(_) | AttributeOrProperty::Static(_) => el .remove_attribute(intern(key)) .expect("could not remove attribute"), - ApplyAttributeAs::Property => { + AttributeOrProperty::Property(_) => { let key = JsValue::from_str(key); js_sys::Reflect::set(el.as_ref(), &key, &JsValue::UNDEFINED) .expect("could not remove property"); @@ -195,20 +188,20 @@ impl Apply for Attributes { fn apply(self, _root: &BSubtree, el: &Element) -> Self { match &self { Self::Static(arr) => { - for (k, v, apply_as) in arr.iter() { - Self::set(el, k, v, *apply_as); + for (k, v) in arr.iter() { + Self::set(el, k, v); } } Self::Dynamic { keys, values } => { for (k, v) in keys.iter().zip(values.iter()) { - if let Some((v, apply_as)) = v { - Self::set(el, k, v, *apply_as) + if let Some(v) = v { + Self::set(el, k, v) } } } Self::IndexMap(m) => { - for (k, (v, apply_as)) in m.iter() { - Self::set(el, k, v, *apply_as) + for (k, v) in m.iter() { + Self::set(el, k, v) } } } @@ -248,7 +241,7 @@ impl Apply for Attributes { } macro_rules! set { ($new:expr) => { - Self::set(el, key!(), $new.0.as_ref(), $new.1) + Self::set(el, key!(), $new) }; } @@ -260,7 +253,7 @@ impl Apply for Attributes { } (Some(new), None) => set!(new), (None, Some(old)) => { - Self::remove(el, key!(), old.1); + Self::remove(el, key!(), old); } (None, None) => (), } @@ -282,6 +275,7 @@ impl Apply for Attributes { #[cfg(target_arch = "wasm32")] #[cfg(test)] mod tests { + use std::rc::Rc; use std::time::Duration; use gloo::utils::document; @@ -303,10 +297,11 @@ mod tests { #[test] fn properties_are_set() { - let attrs = Attributes::Static(&[ - ("href", "https://example.com/", ApplyAttributeAs::Property), - ("alt", "somewhere", ApplyAttributeAs::Property), - ]); + let attrs = indexmap::indexmap! { + AttrValue::Static("href") => AttributeOrProperty::Property(JsValue::from_str("https://example.com/")), + AttrValue::Static("alt") => AttributeOrProperty::Property(JsValue::from_str("somewhere")), + }; + let attrs = Attributes::IndexMap(Rc::new(attrs)); let (element, btree) = create_element(); attrs.apply(&btree, &element); assert_eq!( @@ -329,10 +324,11 @@ mod tests { #[test] fn respects_apply_as() { - let attrs = Attributes::Static(&[ - ("href", "https://example.com/", ApplyAttributeAs::Attribute), - ("alt", "somewhere", ApplyAttributeAs::Property), - ]); + let attrs = indexmap::indexmap! { + AttrValue::Static("href") => AttributeOrProperty::Attribute(AttrValue::from("https://example.com/")), + AttrValue::Static("alt") => AttributeOrProperty::Property(JsValue::from_str("somewhere")), + }; + let attrs = Attributes::IndexMap(Rc::new(attrs)); let (element, btree) = create_element(); attrs.apply(&btree, &element); assert_eq!( @@ -352,7 +348,7 @@ mod tests { #[test] fn class_is_always_attrs() { - let attrs = Attributes::Static(&[("class", "thing", ApplyAttributeAs::Attribute)]); + let attrs = Attributes::Static(&[("class", AttributeOrProperty::Static("thing"))]); let (element, btree) = create_element(); attrs.apply(&btree, &element); @@ -363,10 +359,10 @@ mod tests { async fn macro_syntax_works() { #[function_component] fn Comp() -> Html { - html! { } + html! { } } - let output = gloo::utils::document().get_element_by_id("output").unwrap(); + let output = document().get_element_by_id("output").unwrap(); yew::Renderer::::with_root(output.clone()).render(); gloo::timers::future::sleep(Duration::from_secs(1)).await; @@ -384,5 +380,13 @@ mod tests { "abc", "property `alt` not set properly" ); + + assert!( + Reflect::get(element.as_ref(), &JsValue::from_str("data-bool")) + .expect("no alt") + .as_bool() + .expect("not a bool"), + "property `alt` not set properly" + ); } } diff --git a/packages/yew/src/virtual_dom/mod.rs b/packages/yew/src/virtual_dom/mod.rs index 6ede1e6e074..7b5aac47f5b 100644 --- a/packages/yew/src/virtual_dom/mod.rs +++ b/packages/yew/src/virtual_dom/mod.rs @@ -25,6 +25,7 @@ use std::hint::unreachable_unchecked; use std::rc::Rc; use indexmap::IndexMap; +use wasm_bindgen::JsValue; #[doc(inline)] pub use self::key::Key; @@ -172,22 +173,29 @@ mod feat_ssr { } } -/// Defines if the [`Attributes`] is set as element's attribute or property +/// Defines if the [`Attributes`] is set as element's attribute or property and its value. #[allow(missing_docs)] -#[derive(PartialEq, Eq, Copy, Clone, Debug)] -pub enum ApplyAttributeAs { - Attribute, - Property, +#[derive(PartialEq, Clone, Debug)] +pub enum AttributeOrProperty { + // This exists as a workaround to support Rust <1.72 + // Previous versions of Rust did not See + // `AttributeOrProperty::Attribute(AttrValue::Static(_))` as `'static` that html! macro + // used, and thus failed with "temporary value dropped while borrowed" + // + // See: https://github.com/yewstack/yew/pull/3458#discussion_r1350362215 + Static(&'static str), + Attribute(AttrValue), + Property(JsValue), } /// A collection of attributes for an element -#[derive(PartialEq, Eq, Clone, Debug)] +#[derive(PartialEq, Clone, Debug)] pub enum Attributes { /// Static list of attributes. /// /// Allows optimizing comparison to a simple pointer equality check and reducing allocations, /// if the attributes do not change on a node. - Static(&'static [(&'static str, &'static str, ApplyAttributeAs)]), + Static(&'static [(&'static str, AttributeOrProperty)]), /// Static list of attribute keys with possibility to exclude attributes and dynamic attribute /// values. @@ -200,12 +208,12 @@ pub enum Attributes { /// Attribute values. Matches [keys](Attributes::Dynamic::keys). Optional attributes are /// designated by setting [None]. - values: Box<[Option<(AttrValue, ApplyAttributeAs)>]>, + values: Box<[Option]>, }, /// IndexMap is used to provide runtime attribute deduplication in cases where the html! macro /// was not used to guarantee it. - IndexMap(Rc>), + IndexMap(Rc>), } impl Attributes { @@ -216,21 +224,31 @@ impl Attributes { /// Return iterator over attribute key-value pairs. /// This function is suboptimal and does not inline well. Avoid on hot paths. + /// + /// This function only returns attributes pub fn iter<'a>(&'a self) -> Box + 'a> { match self { - Self::Static(arr) => Box::new(arr.iter().map(|(k, v, _)| (*k, *v as &'a str))), - Self::Dynamic { keys, values } => Box::new( - keys.iter() - .zip(values.iter()) - .filter_map(|(k, v)| v.as_ref().map(|(v, _)| (*k, v.as_ref()))), - ), - Self::IndexMap(m) => Box::new(m.iter().map(|(k, (v, _))| (k.as_ref(), v.as_ref()))), + Self::Static(arr) => Box::new(arr.iter().filter_map(|(k, v)| match v { + AttributeOrProperty::Attribute(v) => Some((*k, v.as_ref())), + AttributeOrProperty::Property(_) => None, + AttributeOrProperty::Static(v) => Some((*k, v)), + })), + Self::Dynamic { keys, values } => { + Box::new(keys.iter().zip(values.iter()).filter_map(|(k, v)| match v { + Some(AttributeOrProperty::Attribute(v)) => Some((*k, v.as_ref())), + _ => None, + })) + } + Self::IndexMap(m) => Box::new(m.iter().filter_map(|(k, v)| match v { + AttributeOrProperty::Attribute(v) => Some((k.as_ref(), v.as_ref())), + _ => None, + })), } } /// Get a mutable reference to the underlying `IndexMap`. /// If the attributes are stored in the `Vec` variant, it will be converted. - pub fn get_mut_index_map(&mut self) -> &mut IndexMap { + pub fn get_mut_index_map(&mut self) -> &mut IndexMap { macro_rules! unpack { () => { match self { @@ -245,9 +263,7 @@ impl Attributes { Self::IndexMap(m) => Rc::make_mut(m), Self::Static(arr) => { *self = Self::IndexMap(Rc::new( - arr.iter() - .map(|(k, v, ty)| ((*k).into(), ((*v).into(), *ty))) - .collect(), + arr.iter().map(|(k, v)| ((*k).into(), v.clone())).collect(), )); unpack!() } @@ -269,7 +285,7 @@ impl From> for Attributes { fn from(map: IndexMap) -> Self { let v = map .into_iter() - .map(|(k, v)| (k, (v, ApplyAttributeAs::Attribute))) + .map(|(k, v)| (k, AttributeOrProperty::Attribute(v))) .collect(); Self::IndexMap(Rc::new(v)) } @@ -279,7 +295,17 @@ impl From> for Attributes { fn from(v: IndexMap<&'static str, AttrValue>) -> Self { let v = v .into_iter() - .map(|(k, v)| (AttrValue::Static(k), (v, ApplyAttributeAs::Attribute))) + .map(|(k, v)| (AttrValue::Static(k), (AttributeOrProperty::Attribute(v)))) + .collect(); + Self::IndexMap(Rc::new(v)) + } +} + +impl From> for Attributes { + fn from(v: IndexMap<&'static str, JsValue>) -> Self { + let v = v + .into_iter() + .map(|(k, v)| (AttrValue::Static(k), (AttributeOrProperty::Property(v)))) .collect(); Self::IndexMap(Rc::new(v)) } diff --git a/packages/yew/src/virtual_dom/vtag.rs b/packages/yew/src/virtual_dom/vtag.rs index 60f70c53c14..0b0d9699049 100644 --- a/packages/yew/src/virtual_dom/vtag.rs +++ b/packages/yew/src/virtual_dom/vtag.rs @@ -6,9 +6,10 @@ use std::mem; use std::ops::{Deref, DerefMut}; use std::rc::Rc; +use wasm_bindgen::JsValue; use web_sys::{HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement}; -use super::{ApplyAttributeAs, AttrValue, Attributes, Key, Listener, Listeners, VNode}; +use super::{AttrValue, AttributeOrProperty, Attributes, Key, Listener, Listeners, VNode}; use crate::html::{ImplicitClone, IntoPropValue, NodeRef}; /// SVG namespace string used for creating svg elements @@ -386,17 +387,17 @@ impl VTag { pub fn add_attribute(&mut self, key: &'static str, value: impl Into) { self.attributes.get_mut_index_map().insert( AttrValue::Static(key), - (value.into(), ApplyAttributeAs::Attribute), + AttributeOrProperty::Attribute(value.into()), ); } /// Set the given key as property on the element /// /// [`js_sys::Reflect`] is used for setting properties. - pub fn add_property(&mut self, key: &'static str, value: impl Into) { + pub fn add_property(&mut self, key: &'static str, value: impl Into) { self.attributes.get_mut_index_map().insert( AttrValue::Static(key), - (value.into(), ApplyAttributeAs::Property), + AttributeOrProperty::Property(value.into()), ); } @@ -412,7 +413,7 @@ impl VTag { pub fn __macro_push_attr(&mut self, key: &'static str, value: impl IntoPropValue) { self.attributes.get_mut_index_map().insert( AttrValue::from(key), - (value.into_prop_value(), ApplyAttributeAs::Property), + AttributeOrProperty::Attribute(value.into_prop_value()), ); }