8 files changed
+37
-100
No files matched your search
@@ -175,7 +175,7 @@ impl ToTokens for ToToksCtx<&Element> {
|
|||||||
if let Some(child) = children.next() {
|
if let Some(child) = children.next() {
|
||||||
let mut inner_toks = TokenStream2::new();
|
let mut inner_toks = TokenStream2::new();
|
||||||
self.recurse(child).to_tokens(&mut inner_toks);
|
self.recurse(child).to_tokens(&mut inner_toks);
|
||||||
while let Some(child) = children.next() {
|
for child in children {
|
||||||
quote!(,).to_tokens(&mut inner_toks);
|
quote!(,).to_tokens(&mut inner_toks);
|
||||||
self.recurse(child).to_tokens(&mut inner_toks);
|
self.recurse(child).to_tokens(&mut inner_toks);
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ impl Parse for Element {
|
|||||||
s.parse::<Token![<]>()?;
|
s.parse::<Token![<]>()?;
|
||||||
s.parse::<Token![/]>()?;
|
s.parse::<Token![/]>()?;
|
||||||
let close = Ident::parse_any(s)?;
|
let close = Ident::parse_any(s)?;
|
||||||
if close.to_string() != name.to_string() {
|
if close != name {
|
||||||
return Err(Error::new_spanned(
|
return Err(Error::new_spanned(
|
||||||
close,
|
close,
|
||||||
"closing element does not match opening",
|
"closing element does not match opening",
|
||||||
@@ -271,7 +271,7 @@ impl Parse for Attr {
|
|||||||
// If so, parse into literal tokens
|
// If so, parse into literal tokens
|
||||||
let ty = if name_str.starts_with("on") {
|
let ty = if name_str.starts_with("on") {
|
||||||
// remove the "on" bit
|
// remove the "on" bit
|
||||||
name = Ident::new(&name_str.trim_start_matches("on"), name.span());
|
name = Ident::new(name_str.trim_start_matches("on"), name.span());
|
||||||
let content;
|
let content;
|
||||||
syn::braced!(content in s);
|
syn::braced!(content in s);
|
||||||
// AttrType::Value(content.parse()?)
|
// AttrType::Value(content.parse()?)
|
||||||
@@ -359,6 +359,7 @@ impl ToTokens for ToToksCtx<&TextNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
enum MaybeExpr<T> {
|
enum MaybeExpr<T> {
|
||||||
Literal(T),
|
Literal(T),
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
|
|||||||
@@ -7,12 +7,6 @@ use ::syn::{
|
|||||||
};
|
};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
|
||||||
macro_rules! debug_output {
|
|
||||||
($expr:expr) => {
|
|
||||||
$expr
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
||||||
let IfmtInput {
|
let IfmtInput {
|
||||||
mut format_literal,
|
mut format_literal,
|
||||||
@@ -21,7 +15,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
|||||||
} = input;
|
} = input;
|
||||||
|
|
||||||
let s = format_literal.value();
|
let s = format_literal.value();
|
||||||
let ref mut out_format_literal = String::with_capacity(s.len());
|
let out_format_literal = &mut String::with_capacity(s.len());
|
||||||
|
|
||||||
let mut iterator = s.char_indices().peekable();
|
let mut iterator = s.char_indices().peekable();
|
||||||
while let Some((i, c)) = iterator.next() {
|
while let Some((i, c)) = iterator.next() {
|
||||||
@@ -135,13 +129,13 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
|||||||
});
|
});
|
||||||
format_literal = LitStr::new(out_format_literal, format_literal.span());
|
format_literal = LitStr::new(out_format_literal, format_literal.span());
|
||||||
|
|
||||||
Ok(TokenStream::from(debug_output!(quote! {
|
Ok(quote! {
|
||||||
format_args!(
|
format_args!(
|
||||||
#format_literal
|
#format_literal
|
||||||
#(, #positional_args)*
|
#(, #positional_args)*
|
||||||
#(, #named_args)*
|
#(, #named_args)*
|
||||||
)
|
)
|
||||||
})))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)] // dumb compiler does not see the struct being used...
|
#[allow(dead_code)] // dumb compiler does not see the struct being used...
|
||||||
@@ -199,7 +193,7 @@ where
|
|||||||
where
|
where
|
||||||
Drop: FnOnce(T),
|
Drop: FnOnce(T),
|
||||||
{
|
{
|
||||||
fn drop(self: &'_ mut Self) {
|
fn drop(&'_ mut self) {
|
||||||
use ::core::ptr;
|
use ::core::ptr;
|
||||||
unsafe {
|
unsafe {
|
||||||
// # Safety
|
// # Safety
|
||||||
@@ -217,7 +211,7 @@ where
|
|||||||
{
|
{
|
||||||
type Target = T;
|
type Target = T;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(self: &'_ Self) -> &'_ Self::Target {
|
fn deref(&'_ self) -> &'_ Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +220,7 @@ where
|
|||||||
Drop: FnOnce(T),
|
Drop: FnOnce(T),
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref_mut(self: &'_ mut Self) -> &'_ mut Self::Target {
|
fn deref_mut(&'_ mut self) -> &'_ mut Self::Target {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use syn::{
|
|||||||
Error, Ident, Result, Token,
|
Error, Ident, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum AmbiguousElement<const AS: HtmlOrRsx> {
|
pub enum AmbiguousElement<const AS: HtmlOrRsx> {
|
||||||
Element(Element<AS>),
|
Element(Element<AS>),
|
||||||
Component(Component<AS>),
|
Component(Component<AS>),
|
||||||
@@ -30,7 +31,6 @@ impl Parse for AmbiguousElement<AS_RSX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If not an absolute path, then parse the ident and check if it's a valid tag
|
// If not an absolute path, then parse the ident and check if it's a valid tag
|
||||||
|
|
||||||
if let Ok(pat) = input.fork().parse::<syn::Path>() {
|
if let Ok(pat) = input.fork().parse::<syn::Path>() {
|
||||||
if pat.segments.len() > 1 {
|
if pat.segments.len() > 1 {
|
||||||
return input
|
return input
|
||||||
@@ -80,57 +80,6 @@ impl Parse for AmbiguousElement<AS_HTML> {
|
|||||||
} else {
|
} else {
|
||||||
Err(Error::new(input.span(), "Not a valid Html tag"))
|
Err(Error::new(input.span(), "Not a valid Html tag"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// input.parse::<Token![>]>()?;
|
|
||||||
|
|
||||||
// let mut children = Vec::new();
|
|
||||||
// while !input.peek(Token![<]) {
|
|
||||||
// children.push(input.parse::<BodyNode<AS_HTML>>()?);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Ok(AmbiguousElement::Element(Element {
|
|
||||||
// name,
|
|
||||||
// key: todo!(),
|
|
||||||
// attributes: todo!(),
|
|
||||||
// listeners: todo!(),
|
|
||||||
// children,
|
|
||||||
// _is_static: todo!(),
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// // Try to parse as an absolute path and immediately defer to the componetn
|
|
||||||
// if input.peek(Token![::]) {
|
|
||||||
// return input
|
|
||||||
// .parse::<Component<AS_HTML>>()
|
|
||||||
// .map(AmbiguousElement::Component);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // If not an absolute path, then parse the ident and check if it's a valid tag
|
|
||||||
|
|
||||||
// if let Ok(pat) = input.fork().parse::<syn::Path>() {
|
|
||||||
// if pat.segments.len() > 1 {
|
|
||||||
// return input
|
|
||||||
// .parse::<Component<AS_HTML>>()
|
|
||||||
// .map(AmbiguousElement::Component);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// use syn::ext::IdentExt;
|
|
||||||
// if let Ok(name) = input.fork().call(Ident::parse_any) {
|
|
||||||
// let name_str = name.to_string();
|
|
||||||
|
|
||||||
// let first_char = name_str.chars().next().unwrap();
|
|
||||||
// if first_char.is_ascii_uppercase() {
|
|
||||||
// input
|
|
||||||
// .parse::<Component<AS_HTML>>()
|
|
||||||
// .map(AmbiguousElement::Component)
|
|
||||||
// } else {
|
|
||||||
// input
|
|
||||||
// .parse::<Element<AS_HTML>>()
|
|
||||||
// .map(AmbiguousElement::Element)
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Err(Error::new(input.span(), "Not a valid Html tag"))
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ impl Parse for Component<AS_HTML> {
|
|||||||
stream.parse::<Token![>]>()?;
|
stream.parse::<Token![>]>()?;
|
||||||
|
|
||||||
'parsing: loop {
|
'parsing: loop {
|
||||||
if stream.peek(Token![<]) {
|
if stream.peek(Token![<]) && stream.peek2(Token![/]) {
|
||||||
break 'parsing;
|
break 'parsing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,18 +115,6 @@ impl Parse for Component<AS_HTML> {
|
|||||||
}
|
}
|
||||||
stream.parse::<Token![>]>()?;
|
stream.parse::<Token![>]>()?;
|
||||||
|
|
||||||
// // parse the guts
|
|
||||||
// let content: ParseBuffer;
|
|
||||||
// syn::braced!(content in stream);
|
|
||||||
|
|
||||||
// let cfg: BodyConfig<AS_HTML> = BodyConfig {
|
|
||||||
// allow_children: true,
|
|
||||||
// allow_fields: true,
|
|
||||||
// allow_manual_props: true,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let (body, children, manual_props) = cfg.parse_component_body(&content)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
body,
|
body,
|
||||||
@@ -281,7 +269,7 @@ impl<const AS: HtmlOrRsx> ToTokens for Component<AS> {
|
|||||||
let mut __manual_props = #manual_props;
|
let mut __manual_props = #manual_props;
|
||||||
};
|
};
|
||||||
for field in &self.body {
|
for field in &self.body {
|
||||||
if field.name.to_string() == "key" {
|
if field.name == "key" {
|
||||||
has_key = Some(field);
|
has_key = Some(field);
|
||||||
} else {
|
} else {
|
||||||
let name = &field.name;
|
let name = &field.name;
|
||||||
@@ -301,7 +289,7 @@ impl<const AS: HtmlOrRsx> ToTokens for Component<AS> {
|
|||||||
None => {
|
None => {
|
||||||
let mut toks = quote! { fc_to_builder(#name) };
|
let mut toks = quote! { fc_to_builder(#name) };
|
||||||
for field in &self.body {
|
for field in &self.body {
|
||||||
if field.name.to_string() == "key" {
|
if field.name == "key" {
|
||||||
has_key = Some(field);
|
has_key = Some(field);
|
||||||
} else {
|
} else {
|
||||||
toks.append_all(quote! {#field})
|
toks.append_all(quote! {#field})
|
||||||
|
|||||||
@@ -137,10 +137,11 @@ impl Parse for Element<AS_HTML> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.parse::<Token![>]>()?;
|
stream.parse::<Token![>]>()?;
|
||||||
|
|
||||||
'parsing: loop {
|
'parsing: loop {
|
||||||
if stream.peek(Token![<]) {
|
if stream.peek(Token![<]) && stream.peek2(Token![/]) {
|
||||||
break 'parsing;
|
break 'parsing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +156,7 @@ impl Parse for Element<AS_HTML> {
|
|||||||
// closing element
|
// closing element
|
||||||
stream.parse::<Token![<]>()?;
|
stream.parse::<Token![<]>()?;
|
||||||
stream.parse::<Token![/]>()?;
|
stream.parse::<Token![/]>()?;
|
||||||
|
|
||||||
let close = Ident::parse_any(stream)?;
|
let close = Ident::parse_any(stream)?;
|
||||||
if close != el_name {
|
if close != el_name {
|
||||||
return Err(Error::new_spanned(
|
return Err(Error::new_spanned(
|
||||||
@@ -233,8 +235,6 @@ fn parse_rsx_element_field(
|
|||||||
// Return early if the field is a listener
|
// Return early if the field is a listener
|
||||||
if name_str.starts_with("on") {
|
if name_str.starts_with("on") {
|
||||||
// remove the "on" bit
|
// remove the "on" bit
|
||||||
// name = Ident::new(&name_str.trim_start_matches("on"), name.span());
|
|
||||||
|
|
||||||
let ty = if stream.peek(token::Brace) {
|
let ty = if stream.peek(token::Brace) {
|
||||||
let content;
|
let content;
|
||||||
syn::braced!(content in stream);
|
syn::braced!(content in stream);
|
||||||
@@ -293,7 +293,7 @@ fn parse_rsx_element_field(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
"classes" => {
|
"classes" => {
|
||||||
todo!("custom class lsit not supported")
|
todo!("custom class list not supported")
|
||||||
}
|
}
|
||||||
"namespace" => {
|
"namespace" => {
|
||||||
todo!("custom namespace not supported")
|
todo!("custom namespace not supported")
|
||||||
@@ -346,11 +346,11 @@ impl<const AS: HtmlOrRsx> ToTokens for ElementAttr<AS> {
|
|||||||
AttrType::BumpText(value) => tokens.append_all(quote! {
|
AttrType::BumpText(value) => tokens.append_all(quote! {
|
||||||
dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
||||||
}),
|
}),
|
||||||
|
|
||||||
AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
||||||
dioxus_elements::#el_name.#nameident(__cx, #exp)
|
dioxus_elements::#el_name.#nameident(__cx, #exp)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// todo: move event handlers on to the elements or onto the nodefactory
|
|
||||||
AttrType::Event(event) => tokens.append_all(quote! {
|
AttrType::Event(event) => tokens.append_all(quote! {
|
||||||
dioxus::events::on::#nameident(__cx, #event)
|
dioxus::events::on::#nameident(__cx, #event)
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ mod component;
|
|||||||
mod element;
|
mod element;
|
||||||
mod fragment;
|
mod fragment;
|
||||||
mod node;
|
mod node;
|
||||||
mod parse_rsx;
|
|
||||||
|
|
||||||
// Re-export the namespaces into each other
|
// Re-export the namespaces into each other
|
||||||
pub use ambiguous::*;
|
pub use ambiguous::*;
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
struct CallBody {}
|
|
||||||
pub fn parse_callbody() {}
|
|
||||||
@@ -11,20 +11,28 @@ fn html_usage() {
|
|||||||
let r = html! {
|
let r = html! {
|
||||||
<div>
|
<div>
|
||||||
"hello world"
|
"hello world"
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
<div />
|
||||||
"hello world"
|
"hello world"
|
||||||
"hello world"
|
<Fragment>
|
||||||
"hello world"
|
</Fragment>
|
||||||
</div>
|
</div>
|
||||||
};
|
};
|
||||||
|
let r = rsx! {
|
||||||
|
div {
|
||||||
|
"hello world"
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rsx_uage() {
|
fn rsx_uage() {
|
||||||
let r = html! {
|
// let r = html! {
|
||||||
<Fragment>
|
// <Fragment>
|
||||||
"hello world"
|
// "hello world"
|
||||||
"hello world"
|
// "hello world"
|
||||||
"hello world"
|
// "hello world"
|
||||||
"hello world"
|
// "hello world"
|
||||||
</Fragment>
|
// </Fragment>
|
||||||
};
|
// };
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user