swc/crates/swc_ecma_transforms_macros/src/lib.rs
2022-01-15 16:43:34 +09:00

51 lines
1.3 KiB
Rust

#![deny(clippy::all)]
#![recursion_limit = "2048"]
use pmutil::ToTokensExt;
use proc_macro::TokenStream;
use swc_macros_common::print;
mod common;
mod fast;
mod parallel;
/// This macro adds fast-path to the `swc_ecma_visit::Fold` and
/// `swc_ecma_visit::Visit`.
///
/// Currently this macro modifies handler of `Expr`, `Stmt`, `ModuleItem`,
/// `Decl`, `Pat` and some vector types.
///
///
///
///
/// # Usage
///
/// `#[fast_path(ArrowVisitor)]`
///
/// where `ShouldWork` implements `swc_ecma_transforms::perf::Check`
#[proc_macro_attribute]
pub fn fast_path(attr: TokenStream, item: TokenStream) -> TokenStream {
let item = syn::parse(item).expect("failed to parse input as an item");
let expanded = fast::expand(attr.into(), item);
print("fast_path", expanded.dump())
}
///
/// # Input
///
/// Basically, input for each types are wrapped in the suffix of the visitor
/// method for the type.
///
/// ## `#[threashold]`
///
/// ```ignore,
/// #[parallel(module_items(threshold = "4"))]
/// impl VisitMut for Pass {}
/// ```
#[proc_macro_attribute]
pub fn parallel(attr: TokenStream, item: TokenStream) -> TokenStream {
let item = syn::parse(item).expect("failed to parse input as an item");
let expanded = parallel::expand(attr.into(), item);
print("parallel", expanded.dump())
}