mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Remove unused punct field from props (#1969)
This commit is contained in:
parent
b3ed684f0b
commit
26d42ba2a9
@ -1,6 +1,4 @@
|
||||
use crate::html_tree::HtmlDashedName;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
convert::TryFrom,
|
||||
@ -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 {
|
||||
@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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};
|
||||
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user