Don't discard other attributes in time
macro
This commit is contained in:
parent
c2dfbd39a0
commit
55a50ace1e
@ -381,7 +381,7 @@ pub fn symbols(stream: BoundaryStream) -> BoundaryStream {
|
||||
#[proc_macro_attribute]
|
||||
pub fn time(stream: BoundaryStream, item: BoundaryStream) -> BoundaryStream {
|
||||
let item = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
time::time(stream.into(), &item)
|
||||
time::time(stream.into(), item)
|
||||
.unwrap_or_else(|err| err.to_compile_error())
|
||||
.into()
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
use syn::Result;
|
||||
use syn::{parse_quote, Result};
|
||||
|
||||
use crate::util::{kw, parse_key_value, parse_string};
|
||||
|
||||
/// Expand the `#[time(..)]` macro.
|
||||
pub fn time(stream: TokenStream, item: &syn::ItemFn) -> Result<TokenStream> {
|
||||
pub fn time(stream: TokenStream, item: syn::ItemFn) -> Result<TokenStream> {
|
||||
let meta: Meta = syn::parse2(stream)?;
|
||||
Ok(create(meta, item))
|
||||
}
|
||||
@ -26,7 +26,7 @@ impl Parse for Meta {
|
||||
}
|
||||
}
|
||||
|
||||
fn create(meta: Meta, item: &syn::ItemFn) -> TokenStream {
|
||||
fn create(meta: Meta, mut item: syn::ItemFn) -> TokenStream {
|
||||
let name = meta.name.unwrap_or_else(|| item.sig.ident.to_string());
|
||||
let span = meta
|
||||
.span
|
||||
@ -34,18 +34,13 @@ fn create(meta: Meta, item: &syn::ItemFn) -> TokenStream {
|
||||
.map(|span| quote! { Some(#span) })
|
||||
.unwrap_or_else(|| quote! { None });
|
||||
|
||||
let sig = &item.sig;
|
||||
let vis = &item.vis;
|
||||
let block = &item.block;
|
||||
quote! {
|
||||
#vis #sig {
|
||||
item.block.stmts.insert(
|
||||
0,
|
||||
parse_quote! {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let __scope = ::typst_timing::TimingScope::new(#name, {
|
||||
use ::typst::foundations::NativeElement;
|
||||
#span
|
||||
});
|
||||
let __scope = ::typst_timing::TimingScope::new(#name, #span);
|
||||
},
|
||||
);
|
||||
|
||||
#block
|
||||
}
|
||||
}
|
||||
item.into_token_stream()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user