mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Update wasm-bindgen, syn and wgpu (#1398)
This commit is contained in:
@@ -20,7 +20,7 @@ serde-discriminant = []
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1"
|
||||
syn = { version = "1.0.68", features = ["full"] }
|
||||
syn = { version = "2.0", features = ["full"] }
|
||||
quote = "1.0.9"
|
||||
|
||||
[dev-dependencies.editor]
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn derive_as_message_impl(input_item: TokenStream) -> syn::Result<TokenStrea
|
||||
.map(|var| {
|
||||
let var_name = &var.ident;
|
||||
let var_name_s = var.ident.to_string();
|
||||
if var.attrs.iter().any(|a| a.path.is_ident("child")) {
|
||||
if var.attrs.iter().any(|a| a.path().is_ident("child")) {
|
||||
(
|
||||
quote::quote! {
|
||||
#input_type::#var_name(child)
|
||||
|
||||
@@ -77,8 +77,13 @@ pub fn combined_message_attrs_impl(attr: TokenStream, input_item: TokenStream) -
|
||||
}
|
||||
|
||||
for var in &mut input.variants {
|
||||
if let Some(attr) = var.attrs.iter_mut().find(|a| a.path.is_ident("child")) {
|
||||
let last_segment = attr.path.segments.last_mut().unwrap();
|
||||
if let Some(attr) = var.attrs.iter_mut().find(|a| a.path().is_ident("child")) {
|
||||
let path = match &mut attr.meta {
|
||||
syn::Meta::Path(path) => path,
|
||||
syn::Meta::List(list) => &mut list.path,
|
||||
syn::Meta::NameValue(named_value) => &mut named_value.path,
|
||||
};
|
||||
let last_segment = path.segments.last_mut().unwrap();
|
||||
last_segment.ident = call_site_ident("sub_discriminant");
|
||||
var.attrs.push(syn::parse_quote! {
|
||||
#[discriminant_attr(child)]
|
||||
@@ -96,8 +101,13 @@ fn top_level_impl(input_item: TokenStream) -> syn::Result<TokenStream> {
|
||||
input.attrs.push(syn::parse_quote! { #[discriminant_attr(derive(Debug, Copy, Clone, PartialEq, Eq, Hash, AsMessage))] });
|
||||
|
||||
for var in &mut input.variants {
|
||||
if let Some(attr) = var.attrs.iter_mut().find(|a| a.path.is_ident("child")) {
|
||||
let last_segment = attr.path.segments.last_mut().unwrap();
|
||||
if let Some(attr) = var.attrs.iter_mut().find(|a| a.path().is_ident("child")) {
|
||||
let path = match &mut attr.meta {
|
||||
syn::Meta::Path(path) => path,
|
||||
syn::Meta::List(list) => &mut list.path,
|
||||
syn::Meta::NameValue(named_value) => &mut named_value.path,
|
||||
};
|
||||
let last_segment = path.segments.last_mut().unwrap();
|
||||
last_segment.ident = call_site_ident("sub_discriminant");
|
||||
var.attrs.push(syn::parse_quote! {
|
||||
#[discriminant_attr(child)]
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::helper_structs::ParenthesizedTokens;
|
||||
use crate::helpers::call_site_ident;
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use syn::spanned::Spanned;
|
||||
use syn::{Attribute, Data, DeriveInput, Field, Fields, ItemEnum};
|
||||
use syn::{Attribute, Data, DeriveInput, Field, Fields, ItemEnum, MetaList};
|
||||
|
||||
pub fn derive_discriminant_impl(input_item: TokenStream) -> syn::Result<TokenStream> {
|
||||
let input = syn::parse2::<DeriveInput>(input_item).unwrap();
|
||||
@@ -16,7 +15,7 @@ pub fn derive_discriminant_impl(input_item: TokenStream) -> syn::Result<TokenStr
|
||||
let mut attr_errs = vec![];
|
||||
|
||||
for var in &mut data.variants {
|
||||
if var.attrs.iter().any(|a| a.path.is_ident("sub_discriminant")) {
|
||||
if var.attrs.iter().any(|a| a.path().is_ident("sub_discriminant")) {
|
||||
match var.fields.len() {
|
||||
1 => {
|
||||
let Field { ty, .. } = var.fields.iter_mut().next().unwrap();
|
||||
@@ -33,9 +32,9 @@ pub fn derive_discriminant_impl(input_item: TokenStream) -> syn::Result<TokenStr
|
||||
}
|
||||
let mut retain = vec![];
|
||||
for (i, a) in var.attrs.iter_mut().enumerate() {
|
||||
if a.path.is_ident("discriminant_attr") {
|
||||
match syn::parse2::<ParenthesizedTokens>(a.tokens.clone()) {
|
||||
Ok(ParenthesizedTokens { tokens, .. }) => {
|
||||
if a.path().is_ident("discriminant_attr") {
|
||||
match a.meta.require_list() {
|
||||
Ok(MetaList { tokens, .. }) => {
|
||||
let attr: Attribute = syn::parse_quote! {
|
||||
#[#tokens]
|
||||
};
|
||||
@@ -48,7 +47,7 @@ pub fn derive_discriminant_impl(input_item: TokenStream) -> syn::Result<TokenStr
|
||||
}
|
||||
}
|
||||
}
|
||||
var.attrs = var.attrs.iter().enumerate().filter_map(|(i, x)| retain.contains(&i).then(|| x.clone())).collect();
|
||||
var.attrs = var.attrs.iter().enumerate().filter(|(i, _)| retain.contains(&i)).map(|(_, x)| x.clone()).collect();
|
||||
}
|
||||
|
||||
let attrs = input
|
||||
@@ -57,10 +56,10 @@ pub fn derive_discriminant_impl(input_item: TokenStream) -> syn::Result<TokenStr
|
||||
.cloned()
|
||||
.filter_map(|a| {
|
||||
let a_span = a.span();
|
||||
a.path
|
||||
a.path()
|
||||
.is_ident("discriminant_attr")
|
||||
.then(|| match syn::parse2::<ParenthesizedTokens>(a.tokens) {
|
||||
Ok(ParenthesizedTokens { tokens, .. }) => {
|
||||
.then(|| match a.meta.require_list() {
|
||||
Ok(MetaList { tokens, .. }) => {
|
||||
let attr: Attribute = syn::parse_quote! {
|
||||
#[#tokens]
|
||||
};
|
||||
|
||||
@@ -55,17 +55,13 @@ impl Parse for KeyEqString {
|
||||
|
||||
/// Parses `(key="value", key="value", …)`
|
||||
pub struct AttrInnerKeyStringMap {
|
||||
_paren_token: Paren,
|
||||
parts: Punctuated<KeyEqString, Token![,]>,
|
||||
}
|
||||
|
||||
impl Parse for AttrInnerKeyStringMap {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let content;
|
||||
let _paren_token = parenthesized!(content in input);
|
||||
Ok(Self {
|
||||
_paren_token,
|
||||
parts: Punctuated::parse_terminated(&content)?,
|
||||
parts: Punctuated::parse_terminated(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -96,7 +92,6 @@ impl AttrInnerKeyStringMap {
|
||||
|
||||
/// Parses `(left, right)`
|
||||
pub struct Pair<F, S> {
|
||||
pub paren_token: Paren,
|
||||
pub first: F,
|
||||
pub sep: Token![,],
|
||||
pub second: S,
|
||||
@@ -108,13 +103,10 @@ where
|
||||
S: Parse,
|
||||
{
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
let content;
|
||||
let paren_token = parenthesized!(content in input);
|
||||
Ok(Self {
|
||||
paren_token,
|
||||
first: content.parse()?,
|
||||
sep: content.parse()?,
|
||||
second: content.parse()?,
|
||||
first: input.parse()?,
|
||||
sep: input.parse()?,
|
||||
second: input.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -180,7 +172,7 @@ mod tests {
|
||||
#[test]
|
||||
fn attr_inner_key_string_map() {
|
||||
let res = syn::parse2::<AttrInnerKeyStringMap>(quote::quote! {
|
||||
(key="value", key2="value2")
|
||||
key="value", key2="value2"
|
||||
});
|
||||
assert!(res.is_ok());
|
||||
let res = res.ok().unwrap();
|
||||
@@ -190,7 +182,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let res = syn::parse2::<AttrInnerKeyStringMap>(quote::quote! {
|
||||
(key="value", key2="value2",)
|
||||
key="value", key2="value2",
|
||||
});
|
||||
assert!(res.is_ok());
|
||||
let res = res.ok().unwrap();
|
||||
|
||||
@@ -7,8 +7,8 @@ fn parse_hint_helper_attrs(attrs: &[Attribute]) -> syn::Result<(Vec<LitStr>, Vec
|
||||
fold_error_iter(
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|a| a.path.get_ident().map_or(false, |i| i == "hint"))
|
||||
.map(|attr| syn::parse2::<AttrInnerKeyStringMap>(attr.tokens.clone())),
|
||||
.filter(|a| a.path().get_ident().map_or(false, |i| i == "hint"))
|
||||
.map(|attr| attr.parse_args::<AttrInnerKeyStringMap>()),
|
||||
)
|
||||
.and_then(|v: Vec<AttrInnerKeyStringMap>| {
|
||||
fold_error_iter(AttrInnerKeyStringMap::multi_into_iter(v).map(|(k, mut v)| match v.len() {
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
use crate::helper_structs::Pair;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use syn::{Attribute, DeriveInput, Expr, Type};
|
||||
use syn::{DeriveInput, Expr, Type};
|
||||
|
||||
pub fn derive_transitive_child_impl(input_item: TokenStream) -> syn::Result<TokenStream> {
|
||||
let input = syn::parse2::<DeriveInput>(input_item).unwrap();
|
||||
|
||||
let Attribute { tokens, .. } = input
|
||||
let attribute = input
|
||||
.attrs
|
||||
.iter()
|
||||
.find(|a| a.path.is_ident("parent"))
|
||||
.find(|a| a.path().is_ident("parent"))
|
||||
.ok_or_else(|| syn::Error::new(Span::call_site(), format!("tried to derive TransitiveChild without a #[parent] attribute (on {})", input.ident)))?;
|
||||
|
||||
let parent_is_top = input.attrs.iter().any(|a| a.path.is_ident("parent_is_top"));
|
||||
let parent_is_top = input.attrs.iter().any(|a| a.path().is_ident("parent_is_top"));
|
||||
|
||||
let Pair {
|
||||
first: parent_type,
|
||||
second: to_parent,
|
||||
..
|
||||
} = syn::parse2::<Pair<Type, Expr>>(tokens.clone())?;
|
||||
} = attribute.parse_args::<Pair<Type, Expr>>()?;
|
||||
|
||||
let top_parent_type: Type = syn::parse_quote! { <#parent_type as TransitiveChild>::TopParent };
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ use syn::{Attribute, Data, DeriveInput, Field, PathArguments, Type};
|
||||
fn has_attribute(attrs: &[Attribute], target: &str) -> bool {
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.path.to_token_stream().to_string() == "widget_builder")
|
||||
.any(|attr| attr.tokens.to_token_stream().to_string() == target)
|
||||
.filter(|attr| attr.path().to_token_stream().to_string() == "widget_builder")
|
||||
.any(|attr| attr.meta.require_list().is_ok_and(|list| list.tokens.to_string() == target))
|
||||
}
|
||||
|
||||
/// Make setting strings easier by allowing all types that `impl Into<String>`
|
||||
@@ -67,7 +67,7 @@ fn find_type_and_assignment(field: &Field) -> syn::Result<(TokenStream2, TokenSt
|
||||
// Construct a builder function for a specific field in the struct
|
||||
fn construct_builder(field: &Field) -> syn::Result<TokenStream2> {
|
||||
// Check if this field should be skipped with `#[widget_builder(skip)]`
|
||||
if has_attribute(&field.attrs, "(skip)") {
|
||||
if has_attribute(&field.attrs, "skip") {
|
||||
return Ok(Default::default());
|
||||
}
|
||||
let field_ident = extract_ident(field)?;
|
||||
@@ -103,7 +103,7 @@ pub fn derive_widget_builder_impl(input_item: TokenStream2) -> syn::Result<Token
|
||||
let builder_functions = fields.iter().map(construct_builder).collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
// Check if this should not have the `widget_holder()` function due to a `#[widget_builder(not_widget_holder)]` attribute
|
||||
let widget_holder_fn = if !has_attribute(&input.attrs, "(not_widget_holder)") {
|
||||
let widget_holder_fn = if !has_attribute(&input.attrs, "not_widget_holder") {
|
||||
// A doc comment for the widget_holder function
|
||||
let widget_holder_doc_comment = Literal::string(&format!("Wrap {struct_name_ident} as a WidgetHolder."));
|
||||
|
||||
@@ -123,7 +123,7 @@ pub fn derive_widget_builder_impl(input_item: TokenStream2) -> syn::Result<Token
|
||||
// A doc comment for the new function
|
||||
let new_doc_comment = Literal::string(&format!("Create a new {struct_name_ident}, based on default values."));
|
||||
|
||||
let is_constructor = |field: &Field| has_attribute(&field.attrs, "(constructor)");
|
||||
let is_constructor = |field: &Field| has_attribute(&field.attrs, "constructor");
|
||||
|
||||
let idents = fields.iter().filter(|field| is_constructor(field)).map(extract_ident).collect::<Result<Vec<_>, _>>()?;
|
||||
let types_and_assignments = fields.iter().filter(|field| is_constructor(field)).map(find_type_and_assignment).collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Reference in New Issue
Block a user