swc_ecma_transforms_macros/
lib.rs

1#![deny(clippy::all)]
2#![recursion_limit = "2048"]
3
4use proc_macro::TokenStream;
5use quote::ToTokens;
6use swc_macros_common::print;
7
8mod common;
9mod fast;
10mod parallel;
11
12/// This macro adds fast-path to the `swc_ecma_visit::Fold` and
13/// `swc_ecma_visit::Visit`.
14///
15/// Currently this macro modifies handler of `Expr`, `Stmt`, `ModuleItem`,
16/// `Decl`, `Pat` and some vector types.
17///
18///
19///
20///
21/// # Usage
22///
23/// `#[fast_path(ArrowVisitor)]`
24///
25/// where `ShouldWork` implements `swc_ecma_transforms::perf::Check`
26#[proc_macro_attribute]
27pub fn fast_path(attr: TokenStream, item: TokenStream) -> TokenStream {
28    let item = syn::parse(item).expect("failed to parse input as an item");
29    let expanded = fast::expand(attr.into(), item);
30    print("fast_path", expanded.into_token_stream())
31}
32
33///
34/// # Input
35///
36/// Basically, input for each types are wrapped in the suffix of the visitor
37/// method for the type.
38///
39/// ## `#[threashold]`
40///
41/// ```ignore,
42/// #[parallel(module_items(threshold = "4"))]
43/// impl VisitMut for Pass {}
44/// ```
45#[proc_macro_attribute]
46pub fn parallel(attr: TokenStream, item: TokenStream) -> TokenStream {
47    let item = syn::parse(item).expect("failed to parse input as an item");
48    let expanded = parallel::expand(attr.into(), item);
49    print("parallel", expanded.into_token_stream())
50}