Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions packages/yew-macro/src/props/prop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::html_tree::HtmlDashedName;
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::{
cmp::Ordering,
convert::TryFrom,
Expand All @@ -11,23 +9,9 @@ use syn::{
Block, Expr, ExprBlock, Stmt, Token,
};

pub enum PropPunct {
Eq(Token![=]),
Colon(Token![:]),
}
impl ToTokens for PropPunct {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
Self::Eq(p) => p.to_tokens(tokens),
Self::Colon(p) => p.to_tokens(tokens),
}
}
}

pub struct Prop {
pub label: HtmlDashedName,
/// Punctuation between `label` and `value`.
pub punct: Option<PropPunct>,
pub value: Expr,
}
impl Parse for Prop {
Expand All @@ -46,11 +30,7 @@ impl Parse for Prop {
));
}
let value = strip_braces(input.parse::<Expr>()?)?;
Ok(Self {
label,
punct: Some(PropPunct::Eq(equals)),
value,
})
Ok(Self { label, value })
}
}

Expand Down
31 changes: 8 additions & 23 deletions packages/yew-macro/src/props/prop_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{ComponentProps, Prop, PropPunct, Props, SortedPropList};
use super::{ComponentProps, Prop, Props, SortedPropList};
use crate::html_tree::HtmlDashedName;
use proc_macro2::TokenStream;
use quote::{quote_spanned, ToTokens};
Expand Down Expand Up @@ -42,40 +42,25 @@ fn is_associated_properties(ty: &TypePath) -> bool {

struct PropValue {
label: HtmlDashedName,
colon_token: Option<Token![:]>,
value: Expr,
}
impl Parse for PropValue {
fn parse(input: ParseStream) -> syn::Result<Self> {
let label = input.parse()?;
let (colon_token, value) = if input.peek(Token![:]) {
let colon_token = input.parse()?;
let value = input.parse()?;
(Some(colon_token), value)
let value = if input.peek(Token![:]) {
let _colon_token: Token![:] = input.parse()?;
input.parse()?
} else {
let value = syn::parse_quote!(#label);
(None, value)
syn::parse_quote!(#label)
};
Ok(Self {
label,
colon_token,
value,
})
Ok(Self { label, value })
}
}

impl From<PropValue> for Prop {
fn from(prop_value: PropValue) -> Prop {
let PropValue {
label,
colon_token,
value,
} = prop_value;
Prop {
label,
punct: colon_token.map(PropPunct::Colon),
value,
}
let PropValue { label, value } = prop_value;
Prop { label, value }
}
}

Expand Down