1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![deny(clippy::all)]
#![recursion_limit = "2048"]

use proc_macro::TokenStream;
use quote::ToTokens;
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.into_token_stream())
}

///
/// # 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.into_token_stream())
}