Fix: clippy, dont throw error on commas (#2869)

* Fix: clippy, hotreload css blocks, raw blocks

* fix test

* okay nevermind
This commit is contained in:
Jonathan Kelley 2024-08-20 16:57:56 -07:00 committed by GitHub
parent 5c002686d0
commit 005d52468d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 29 deletions

View file

@ -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
@ -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);
})
}

View file

@ -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},
*,
@ -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 {
@ -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)
}
}
@ -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![

View file

@ -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(),

View file

@ -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)
}