Skip to content

Commit

Permalink
Fix: clippy, dont throw error on commas (#2869)
Browse files Browse the repository at this point in the history
* Fix: clippy, hotreload css blocks, raw blocks

* fix test

* okay nevermind
  • Loading branch information
jkelleyrtp authored Aug 20, 2024
1 parent 5c00268 commit 005d524
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/suspense/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl SuspenseBoundaryProps {
// Store the (now mounted) children back into the scope state
let scope_state = &mut dom.scopes[scope_id.0];
let props = Self::downcast_from_props(&mut *scope_state.props).unwrap();
props.children = children.clone();
props.children.clone_from(&children);

let scope_state = &mut dom.scopes[scope_id.0];
let suspense_context = scope_state
Expand Down Expand Up @@ -435,7 +435,7 @@ impl SuspenseBoundaryProps {
// Store the (now mounted) children back into the scope state
let scope_state = &mut dom.scopes[scope_id.0];
let props = Self::downcast_from_props(&mut *scope_state.props).unwrap();
props.children = children.clone();
props.children.clone_from(&children);
scope_state.last_rendered_node = Some(children);
})
}
Expand Down
25 changes: 6 additions & 19 deletions packages/rsx/src/ifmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens, TokenStreamExt};
use std::{collections::HashMap, str::FromStr};
use std::collections::HashMap;
use syn::{
parse::{Parse, ParseStream},
*,
Expand All @@ -25,9 +25,9 @@ impl IfmtInput {
}
}

pub fn new_litstr(source: LitStr) -> Self {
let segments = Self::from_raw(&source.value()).unwrap();
Self { segments, source }
pub fn new_litstr(source: LitStr) -> Result<Self> {
let segments = IfmtInput::from_raw(&source.value())?;
Ok(Self { segments, source })
}

pub fn span(&self) -> Span {
Expand Down Expand Up @@ -335,23 +335,10 @@ impl ToTokens for FormattedSegmentType {
}
}

impl FromStr for IfmtInput {
type Err = syn::Error;

fn from_str(input: &str) -> Result<Self> {
let segments = IfmtInput::from_raw(input)?;
Ok(Self {
source: LitStr::new(input, Span::call_site()),
segments,
})
}
}

impl Parse for IfmtInput {
fn parse(input: ParseStream) -> Result<Self> {
let source: LitStr = input.parse()?;
let segments = IfmtInput::from_raw(&source.value())?;
Ok(Self { source, segments })
Self::new_litstr(source)
}
}

Expand All @@ -370,7 +357,7 @@ mod tests {

#[test]
fn segments_parse() {
let input = "blah {abc} {def}".parse::<IfmtInput>().unwrap();
let input: IfmtInput = parse_quote! { "blah {abc} {def}" };
assert_eq!(
input.segments,
vec![
Expand Down
2 changes: 1 addition & 1 deletion packages/rsx/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Parse for HotLiteral {
Lit::Int(a) => HotLiteral::Int(a),
Lit::Bool(a) => HotLiteral::Bool(a),
Lit::Float(a) => HotLiteral::Float(a),
Lit::Str(a) => HotLiteral::Fmted(IfmtInput::new_litstr(a).into()),
Lit::Str(a) => HotLiteral::Fmted(IfmtInput::new_litstr(a)?.into()),
_ => {
return Err(syn::Error::new(
raw.span(),
Expand Down
28 changes: 21 additions & 7 deletions packages/rsx/src/rsx_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,30 @@ impl RsxBlock {
// Parse a body node with diagnostics for unnecessary trailing commas
fn parse_body_node_with_comma_diagnostics(
content: &ParseBuffer,
diagnostics: &mut Diagnostics,
_diagnostics: &mut Diagnostics,
) -> syn::Result<BodyNode> {
let body_node = content.parse::<BodyNode>()?;
if !content.is_empty() && content.peek(Token![,]) {
let comma = content.parse::<Token![,]>()?;
diagnostics.push(
comma
.span()
.warning("Elements and text nodes do not need to be separated by commas."),
);
let _comma = content.parse::<Token![,]>()?;

// todo: we would've pushed a warning here but proc-macro-2 emits them as errors, which we
// dont' want. There's no built-in cfg way for checking if we're on nightly, and adding
// that would require a build script, so for the interest of compile times, we won't throw
// any warning at all.
//
// Whenever the user formats their code with `dx fmt`, the comma will be removed, so active
// projects will implicitly be fixed.
//
// Whenever the issue is resolved or diagnostics are added, we can re-add this warning.
//
// - https://github.com/SergioBenitez/proc-macro2-diagnostics/issues/9
// - https://github.com/DioxusLabs/dioxus/issues/2807
//
// diagnostics.push(
// comma
// .span()
// .warning("Elements and text nodes do not need to be separated by commas."),
// );
}
Ok(body_node)
}
Expand Down

0 comments on commit 005d524

Please sign in to comment.