Skip to content

Commit

Permalink
Update syn to v2 (#593)
Browse files Browse the repository at this point in the history
* Update syn to v2

* cargo fmt

* Update UI tests

* Update UI tests again, this time with correct rustc version
  • Loading branch information
lukechu10 authored Mar 26, 2023
1 parent fedc881 commit c8666c7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/sycamore-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ once_cell = "1.16.0"
proc-macro2 = "1.0.47"
quote = "1.0.21"
rand = "0.8.5"
syn = { version = "1.0.103", features = ["extra-traits", "full"] }
syn = { version = "2.0.10", features = ["extra-traits", "full"] }

[dev-dependencies]
sycamore = { path = "../sycamore", features = ["hydrate", "suspense"] }
Expand Down
6 changes: 3 additions & 3 deletions packages/sycamore-macro/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Parse for ComponentFn {

if let ReturnType::Default = sig.output {
return Err(syn::Error::new(
sig.paren_token.span,
sig.paren_token.span.close(),
"component must return `sycamore::view::View`",
));
};
Expand All @@ -48,7 +48,7 @@ impl Parse for ComponentFn {

if inputs.is_empty() {
return Err(syn::Error::new(
sig.paren_token.span,
sig.paren_token.span.span(),
"component must take at least one argument of type `sycamore::reactive::Scope`",
));
}
Expand Down Expand Up @@ -293,7 +293,7 @@ fn inline_props_impl(item: &mut ItemFn) -> Result<TokenStream> {
let inputs = item.sig.inputs.clone();
if inputs.is_empty() {
return Err(syn::Error::new(
item.sig.paren_token.span,
item.sig.paren_token.span.join(),
"component must take at least one argument of type `sycamore::reactive::Scope`",
));
}
Expand Down
52 changes: 14 additions & 38 deletions packages/sycamore-macro/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ mod struct_info {
use proc_macro2::TokenStream;
use quote::quote;
use syn::parse::Error;
use syn::punctuated::Punctuated;
use syn::Token;

use super::field_info::{FieldBuilderAttr, FieldInfo};
use super::util::{
Expand Down Expand Up @@ -669,27 +671,13 @@ mod struct_info {
pub fn new(attrs: &[syn::Attribute]) -> Result<TypeBuilderAttr, Error> {
let mut result = TypeBuilderAttr::default();
for attr in attrs {
if path_to_single_string(&attr.path).as_deref() != Some("prop") {
if !attr.path().is_ident("prop") {
continue;
}

if attr.tokens.is_empty() {
continue;
}
let as_expr: syn::Expr = syn::parse2(attr.tokens.clone())?;

match as_expr {
syn::Expr::Paren(body) => {
result.apply_meta(*body.expr)?;
}
syn::Expr::Tuple(body) => {
for expr in body.elems.into_iter() {
result.apply_meta(expr)?;
}
}
_ => {
return Err(Error::new_spanned(attr.tokens.clone(), "Expected (<...>)"));
}
let as_expr: Punctuated<syn::Expr, Token![,]> =
attr.parse_args_with(Punctuated::parse_terminated)?;
for expr in as_expr {
result.apply_meta(expr)?;
}
}

Expand Down Expand Up @@ -773,7 +761,9 @@ mod field_info {
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::parse::Error;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::Token;

use super::util::{
expr_to_single_string, ident_to_type, path_to_single_string, strip_raw_ident_prefix,
Expand Down Expand Up @@ -869,27 +859,13 @@ mod field_info {
impl FieldBuilderAttr {
pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
for attr in attrs {
if path_to_single_string(&attr.path).as_deref() != Some("prop") {
if !attr.path().is_ident("prop") {
continue;
}

if attr.tokens.is_empty() {
continue;
}

let as_expr: syn::Expr = syn::parse2(attr.tokens.clone())?;
match as_expr {
syn::Expr::Paren(body) => {
self.apply_meta(*body.expr)?;
}
syn::Expr::Tuple(body) => {
for expr in body.elems.into_iter() {
self.apply_meta(expr)?;
}
}
_ => {
return Err(Error::new_spanned(attr.tokens.clone(), "Expected (<...>)"));
}
let as_expr: Punctuated<syn::Expr, Token![,]> =
attr.parse_args_with(Punctuated::parse_terminated)?;
for expr in as_expr {
self.apply_meta(expr)?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sycamore-macro/src/view/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Parse for Element {
let content;
parenthesized!(content in input);
content
.parse_terminated::<Attribute, Token![,]>(Attribute::parse)?
.parse_terminated(Attribute::parse, Token![,])?
.into_iter()
.collect()
} else {
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Parse for Component {
// Parse props.
let content;
parenthesized!(content in input);
props = content.parse_terminated(ComponentProp::parse)?;
props = content.parse_terminated(ComponentProp::parse, Token![,])?;
}
if input.peek(Brace) {
// Parse children.
Expand Down
4 changes: 2 additions & 2 deletions packages/sycamore-macro/tests/component/component-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: component must return `sycamore::view::View`
--> tests/component/component-fail.rs:5:18
--> tests/component/component-fail.rs:5:29
|
5 | fn Comp1<G: Html>(_cx: Scope) {
| ^^^^^^^^^^^^
| ^

error: component must take at least one argument of type `sycamore::reactive::Scope`
--> tests/component/component-fail.rs:11:18
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore-router-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc-macro = true
nom = "7.1.1"
proc-macro2 = "1.0.47"
quote = "1.0.21"
syn = "1.0.103"
syn = "2.0.10"
unicode-xid = "0.2.4"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore-router-macro/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn route_impl(input: DeriveInput) -> syn::Result<TokenStream> {
let mut is_to_route = false;

for attr in &variant.attrs {
let attr_name = match attr.path.get_ident() {
let attr_name = match attr.path().get_ident() {
Some(ident) => ident.to_string(),
None => continue,
};
Expand Down

0 comments on commit c8666c7

Please sign in to comment.