Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza1311 committed Aug 14, 2022
1 parent 3b9fa16 commit b8cf9b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/yew-macro/src/html_tree/html_element.rs
Expand Up @@ -246,13 +246,17 @@ 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),
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<PropDirective>)]) -> Option<TokenStream> {
fn try_into_static(
src: &[(LitStr, Value, Option<PropDirective>)],
) -> Option<TokenStream> {
let mut kv = Vec::with_capacity(src.len());
for (k, v, directive) in src.iter() {
let v = match v {
Expand Down
17 changes: 13 additions & 4 deletions packages/yew-macro/src/props/prop.rs
Expand Up @@ -26,7 +26,10 @@ pub struct Prop {
}
impl Parse for Prop {
fn parse(input: ParseStream) -> syn::Result<Self> {
let directive = input.parse::<Token![~]>().map(|parsed| PropDirective::ApplyAsProperty(parsed)).ok();
let directive = input
.parse::<Token![~]>()
.map(|parsed| PropDirective::ApplyAsProperty(parsed))
.ok();
if input.peek(Brace) {
Self::parse_shorthand_prop_assignment(input, directive)
} else {
Expand Down Expand Up @@ -77,7 +80,10 @@ impl Prop {
}

/// Parse a prop of the form `label={value}`
fn parse_prop_assignment(input: ParseStream, directive: Option<PropDirective>) -> syn::Result<Self> {
fn parse_prop_assignment(
input: ParseStream,
directive: Option<PropDirective>,
) -> syn::Result<Self> {
let label = input.parse::<HtmlDashedName>()?;
let equals = input.parse::<Token![=]>().map_err(|_| {
syn::Error::new_spanned(
Expand Down Expand Up @@ -125,8 +131,11 @@ fn parse_prop_value(input: &ParseBuffer) -> syn::Result<Expr> {
Expr::Lit(_) => Ok(expr),
ref exp => Err(syn::Error::new_spanned(
&expr,
format!("the property value must be either a literal or enclosed in braces. Consider \
adding braces around your expression.: {:#?}", exp),
format!(
"the property value must be either a literal or enclosed in braces. Consider \
adding braces around your expression.: {:#?}",
exp
),
)),
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/yew/src/dom_bundle/btag/attributes.rs
Expand Up @@ -367,7 +367,10 @@ mod tests {

gloo::timers::future::sleep(Duration::from_secs(1)).await;
let element = output.query_selector("a").unwrap().unwrap();
assert_eq!(element.get_attribute("href").unwrap(), "https://example.com/");
assert_eq!(
element.get_attribute("href").unwrap(),
"https://example.com/"
);

assert_eq!(
Reflect::get(element.as_ref(), &JsValue::from_str("alt"))
Expand Down

0 comments on commit b8cf9b8

Please sign in to comment.