pass clippy
This commit is contained in:
1 parent
0f2ff34a30
commit
ffc9bf763a
6 files changed
+53
-55
No files matched your search
+23
-19
@@ -1,3 +1,5 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
|
|
||||||
use quote::{quote, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
@@ -12,7 +14,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
|||||||
let mut expr_counter = 0;
|
let mut expr_counter = 0;
|
||||||
for segment in input.segments.iter() {
|
for segment in input.segments.iter() {
|
||||||
match segment {
|
match segment {
|
||||||
Segment::Literal(s) => format_literal += &s,
|
Segment::Literal(s) => format_literal += s,
|
||||||
Segment::Formatted {
|
Segment::Formatted {
|
||||||
format_args,
|
format_args,
|
||||||
segment,
|
segment,
|
||||||
@@ -35,24 +37,24 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let positional_args = input.segments.iter().filter_map(|seg| {
|
let positional_args = input.segments.iter().filter_map(|seg| {
|
||||||
if let Segment::Formatted { segment, .. } = seg {
|
if let Segment::Formatted {
|
||||||
if let FormattedSegment::Expr(expr) = segment {
|
segment: FormattedSegment::Expr(expr),
|
||||||
Some(expr)
|
..
|
||||||
} else {
|
} = seg
|
||||||
None
|
{
|
||||||
}
|
Some(expr)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let named_args = input.segments.iter().filter_map(|seg| {
|
let named_args = input.segments.iter().filter_map(|seg| {
|
||||||
if let Segment::Formatted { segment, .. } = seg {
|
if let Segment::Formatted {
|
||||||
if let FormattedSegment::Ident(ident) = segment {
|
segment: FormattedSegment::Ident(ident),
|
||||||
Some(quote! {#ident = #ident})
|
..
|
||||||
} else {
|
} = seg
|
||||||
None
|
{
|
||||||
}
|
Some(quote! {#ident = #ident})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -73,8 +75,10 @@ pub struct IfmtInput {
|
|||||||
pub segments: Vec<Segment>,
|
pub segments: Vec<Segment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IfmtInput {
|
impl FromStr for IfmtInput {
|
||||||
pub fn from_str(input: &str) -> Result<Self> {
|
type Err = syn::Error;
|
||||||
|
|
||||||
|
fn from_str(input: &str) -> Result<Self> {
|
||||||
let mut chars = input.chars().peekable();
|
let mut chars = input.chars().peekable();
|
||||||
let mut segments = Vec::new();
|
let mut segments = Vec::new();
|
||||||
let mut current_literal = String::new();
|
let mut current_literal = String::new();
|
||||||
@@ -90,7 +94,7 @@ impl IfmtInput {
|
|||||||
while let Some(c) = chars.next() {
|
while let Some(c) = chars.next() {
|
||||||
if c == ':' {
|
if c == ':' {
|
||||||
let mut current_format_args = String::new();
|
let mut current_format_args = String::new();
|
||||||
while let Some(c) = chars.next() {
|
for c in chars.by_ref() {
|
||||||
if c == '}' {
|
if c == '}' {
|
||||||
segments.push(Segment::Formatted {
|
segments.push(Segment::Formatted {
|
||||||
format_args: current_format_args,
|
format_args: current_format_args,
|
||||||
@@ -131,20 +135,20 @@ pub enum Segment {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FormattedSegment {
|
pub enum FormattedSegment {
|
||||||
Expr(Expr),
|
Expr(Box<Expr>),
|
||||||
Ident(Ident),
|
Ident(Ident),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormattedSegment {
|
impl FormattedSegment {
|
||||||
fn parse(input: &str) -> Result<Self> {
|
fn parse(input: &str) -> Result<Self> {
|
||||||
if let Ok(ident) = parse_str::<Ident>(input) {
|
if let Ok(ident) = parse_str::<Ident>(input) {
|
||||||
if &ident.to_string() == input {
|
if ident == input {
|
||||||
return Ok(Self::Ident(ident));
|
return Ok(Self::Ident(ident));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if let Ok(expr) = parse_str(&("{".to_string() + input + "}")) {
|
// if let Ok(expr) = parse_str(&("{".to_string() + input + "}")) {
|
||||||
if let Ok(expr) = parse_str(input) {
|
if let Ok(expr) = parse_str(input) {
|
||||||
Ok(Self::Expr(expr))
|
Ok(Self::Expr(Box::new(expr)))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(
|
Err(Error::new(
|
||||||
Span::call_site(),
|
Span::call_site(),
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ pub enum BodyNode {
|
|||||||
|
|
||||||
impl BodyNode {
|
impl BodyNode {
|
||||||
pub fn is_litstr(&self) -> bool {
|
pub fn is_litstr(&self) -> bool {
|
||||||
match self {
|
matches!(self, BodyNode::Text(_))
|
||||||
BodyNode::Text(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ impl CapturedContextBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_call_body(body: CallBody) -> Result<Self> {
|
pub fn from_call_body(body: CallBody) -> Result<Self> {
|
||||||
let mut new = Self::default();
|
let mut new = Self {
|
||||||
new.custom_context = body.custom_context;
|
custom_context: body.custom_context,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
for node in body.roots {
|
for node in body.roots {
|
||||||
new.extend(Self::find_captured(node)?);
|
new.extend(Self::find_captured(node)?);
|
||||||
}
|
}
|
||||||
@@ -102,8 +104,7 @@ impl ToTokens for CapturedContextBuilder {
|
|||||||
});
|
});
|
||||||
let captured: Vec<_> = ifmted
|
let captured: Vec<_> = ifmted
|
||||||
.iter()
|
.iter()
|
||||||
.map(|input| input.segments.iter())
|
.flat_map(|input| input.segments.iter())
|
||||||
.flatten()
|
|
||||||
.filter_map(|seg| match seg {
|
.filter_map(|seg| match seg {
|
||||||
Segment::Formatted {
|
Segment::Formatted {
|
||||||
format_args,
|
format_args,
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ macro_rules! builder_constructors {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub const ELEMENTS_WITH_MAPPED_ATTRIBUTES: &'static [(
|
pub const ELEMENTS_WITH_MAPPED_ATTRIBUTES: &[(
|
||||||
&'static str,
|
&str,
|
||||||
&'static [(&'static str, &'static str)],
|
&[(&str, &str)],
|
||||||
)] = &[
|
)] = &[
|
||||||
("script", &[("r#type", "type"), ("r#script", "script")]),
|
("script", &[("r#type", "type"), ("r#script", "script")]),
|
||||||
("button", &[("r#type", "type")]),
|
("button", &[("r#type", "type")]),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use dioxus_core::{Attribute, AttributeValue, NodeFactory, VNode};
|
|||||||
use dioxus_rsx::{BodyNode, CallBody, ElementAttr, IfmtInput, Segment};
|
use dioxus_rsx::{BodyNode, CallBody, ElementAttr, IfmtInput, Segment};
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use quote::__private::Span;
|
use quote::__private::Span;
|
||||||
|
use std::str::FromStr;
|
||||||
use syn::{parse2, parse_str, Expr};
|
use syn::{parse2, parse_str, Expr};
|
||||||
|
|
||||||
use crate::attributes::attrbute_to_static_str;
|
use crate::attributes::attrbute_to_static_str;
|
||||||
@@ -55,7 +56,7 @@ pub fn build<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if children_built.len() == 1 {
|
if children_built.len() == 1 {
|
||||||
return Ok(children_built.pop().unwrap());
|
Ok(children_built.pop().unwrap())
|
||||||
} else {
|
} else {
|
||||||
Ok(factory.fragment_from_iter(children_built.iter()))
|
Ok(factory.fragment_from_iter(children_built.iter()))
|
||||||
}
|
}
|
||||||
@@ -158,29 +159,24 @@ fn build_node<'a>(
|
|||||||
}
|
}
|
||||||
let listeners = bump.alloc(Vec::new());
|
let listeners = bump.alloc(Vec::new());
|
||||||
for attr in el.attributes {
|
for attr in el.attributes {
|
||||||
match attr.attr {
|
if let ElementAttr::EventTokens { .. } = attr.attr {
|
||||||
ElementAttr::EventTokens { .. } => {
|
let expr: Expr = parse2(attr.to_token_stream()).map_err(|err| {
|
||||||
let expr: Expr = parse2(attr.to_token_stream()).map_err(|err| {
|
Error::ParseError(ParseError::new(err, ctx.location.clone()))
|
||||||
Error::ParseError(ParseError::new(err, ctx.location.clone()))
|
})?;
|
||||||
})?;
|
if let Some(idx) = ctx.listeners.iter().position(|(code, _)| {
|
||||||
if let Some(idx) = ctx.listeners.iter().position(|(code, _)| {
|
if let Ok(parsed) = parse_str::<Expr>(*code) {
|
||||||
if let Ok(parsed) = parse_str::<Expr>(*code) {
|
parsed == expr
|
||||||
parsed == expr
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
let (_, listener) = ctx.listeners.remove(idx);
|
|
||||||
listeners.push(listener)
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::RecompileRequiredError(
|
false
|
||||||
RecompileReason::CapturedListener(
|
|
||||||
expr.to_token_stream().to_string(),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
}) {
|
||||||
|
let (_, listener) = ctx.listeners.remove(idx);
|
||||||
|
listeners.push(listener)
|
||||||
|
} else {
|
||||||
|
return Err(Error::RecompileRequiredError(
|
||||||
|
RecompileReason::CapturedListener(expr.to_token_stream().to_string()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let tag = bump.alloc(el.name.to_string());
|
let tag = bump.alloc(el.name.to_string());
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::cell::{Cell, RefCell};
|
|
||||||
|
|
||||||
use bumpalo::boxed::Box;
|
|
||||||
use dioxus_core::{prelude::*, AnyEvent};
|
|
||||||
|
use dioxus_core::{prelude::*};
|
||||||
use dioxus_core_macro::*;
|
use dioxus_core_macro::*;
|
||||||
use dioxus_html as dioxus_elements;
|
use dioxus_html as dioxus_elements;
|
||||||
use dioxus_rsx_interpreter::{
|
use dioxus_rsx_interpreter::{
|
||||||
captuered_context::{CapturedContext, FormattedArg, IfmtArgs},
|
captuered_context::{CapturedContext, FormattedArg, IfmtArgs},
|
||||||
CodeLocation, ErrorHandler,
|
CodeLocation,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user