mirror of
https://github.com/typst/typst
synced 2025-07-27 22:37:54 +08:00
Add support for until
to the deprecated macro
This allows easily annotating the `until` version in impl blocks using the `#[scope]` macro.
This commit is contained in:
parent
3cb06baa98
commit
37b169ab5e
@ -1,7 +1,8 @@
|
||||
use heck::ToKebabCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_quote, Result};
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::{parse_quote, MetaNameValue, Result, Token};
|
||||
|
||||
use crate::util::{foundations, BareType};
|
||||
|
||||
@ -53,15 +54,33 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
|
||||
_ => bail!(child, "unexpected item in scope"),
|
||||
};
|
||||
|
||||
if let Some(message) = attrs.iter().find_map(|attr| match &attr.meta {
|
||||
if let Some(attr) = attrs.iter().find(|attr| attr.path().is_ident("deprecated")) {
|
||||
match &attr.meta {
|
||||
syn::Meta::NameValue(pair) if pair.path.is_ident("deprecated") => {
|
||||
Some(&pair.value)
|
||||
let message = &pair.value;
|
||||
def = quote! { #def.deprecated(#message) }
|
||||
}
|
||||
_ => None,
|
||||
syn::Meta::List(list) if list.path.is_ident("deprecated") => {
|
||||
let args = list.parse_args_with(
|
||||
Punctuated::<MetaNameValue, Token![,]>::parse_separated_nonempty,
|
||||
)?;
|
||||
|
||||
if let Some(message) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("message").then_some(&pair.value)
|
||||
}) {
|
||||
def = quote! { #def.deprecated(#message) }
|
||||
}
|
||||
|
||||
if let Some(version) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("until").then_some(&pair.value)
|
||||
}) {
|
||||
def = quote! { #def.until(#version) }
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
definitions.push(def);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user