Skip to content

Commit

Permalink
Implement dynamic tags (#1266)
Browse files Browse the repository at this point in the history
* implement dynamic tags

* very minor code cleanup

* Add hint to 'closing tag with body' error

* correcting a few ill-formed quote_spanned usages

* improve html prop error message

* use 'fragment' instead of 'tag'

* add runtime checks for dynamic tags

* fix tests for stdweb

By only running it for web-sys. I know, I know.
But seriously, stdweb doesn't seem to have a way to get Element.tagName...

* allow entire ascii range for dynamic tag names

* handle weird lettercasing for tag names
  • Loading branch information
siku2 authored May 28, 2020
1 parent 1b7831a commit 1c2dff1
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 63 deletions.
2 changes: 1 addition & 1 deletion yew-macro/src/html_tree/html_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl ToTokens for HtmlComponent {
};

let key = if let Some(key) = props.key() {
quote_spanned! { key.span() => Some(#key) }
quote_spanned! { key.span()=> Some(#key) }
} else {
quote! {None }
};
Expand Down
8 changes: 7 additions & 1 deletion yew-macro/src/html_tree/html_dashed_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use syn::ext::IdentExt;
use syn::parse::{Parse, ParseStream, Result as ParseResult};
use syn::Token;

#[derive(PartialEq)]
#[derive(Clone, PartialEq)]
pub struct HtmlDashedName {
pub name: Ident,
pub extended: Vec<(Token![-], Ident)>,
Expand All @@ -22,6 +22,12 @@ impl HtmlDashedName {
extended: Vec::new(),
}
}

pub fn to_ascii_lowercase_string(&self) -> String {
let mut s = self.to_string();
s.make_ascii_lowercase();
s
}
}

impl fmt::Display for HtmlDashedName {
Expand Down
8 changes: 4 additions & 4 deletions yew-macro/src/html_tree/html_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Parse for HtmlList {
return match input.parse::<HtmlListClose>() {
Ok(close) => Err(syn::Error::new_spanned(
close,
"this closing tag has no corresponding opening tag",
"this closing fragment has no corresponding opening fragment",
)),
Err(err) => Err(err),
};
Expand All @@ -38,7 +38,7 @@ impl Parse for HtmlList {
if !HtmlList::verify_end(input.cursor()) {
return Err(syn::Error::new_spanned(
open,
"this opening tag has no corresponding closing tag",
"this opening fragment has no corresponding closing fragment",
));
}

Expand All @@ -60,9 +60,9 @@ impl ToTokens for HtmlList {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let children = &self.children;
let key = if let Some(key) = &self.key {
quote_spanned! {key.span() => Some(#key)}
quote_spanned! {key.span()=> Some(#key)}
} else {
quote! {None }
quote! {None}
};
tokens.extend(quote! {
::yew::virtual_dom::VNode::VList(
Expand Down
8 changes: 7 additions & 1 deletion yew-macro/src/html_tree/html_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ impl PeekValue<()> for HtmlProp {
impl Parse for HtmlProp {
fn parse(input: ParseStream) -> ParseResult<Self> {
let label = input.parse::<HtmlPropLabel>()?;
input
let equals = input
.parse::<Token![=]>()
.map_err(|_| syn::Error::new_spanned(&label, "this prop doesn't have a value"))?;
if input.is_empty() {
return Err(syn::Error::new_spanned(
equals,
"expected an expression following this equals sign",
));
}
let value = input.parse::<Expr>()?;
// backwards compat
let _ = input.parse::<Token![,]>();
Expand Down
Loading

0 comments on commit 1c2dff1

Please sign in to comment.