swc_ecma_transforms_base/
quote.rs

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
/// Not a public api.
#[doc(hidden)]
#[macro_export]
macro_rules! helper_expr {
    (ts, $field_name:ident) => {{
        $crate::helper_expr!(ts, ::swc_common::DUMMY_SP, $field_name)
    }};

    (ts, $span:expr, $field_name:ident) => {{
        use swc_ecma_utils::{quote_ident, ExprFactory};

        let mark = $crate::enable_helper!($field_name);
        let ctxt = swc_common::SyntaxContext::empty().apply_mark(mark);

        Expr::from(swc_ecma_utils::quote_ident!(
            ctxt,
            $span,
            concat!("_", stringify!($field_name))
        ))
    }};

    ($field_name:ident) => {{
        $crate::helper_expr!(::swc_common::DUMMY_SP, $field_name)
    }};

    ($span:expr, $field_name:ident) => {{
        use swc_ecma_utils::{quote_ident, ExprFactory};

        let mark = $crate::enable_helper!($field_name);
        let ctxt = swc_common::SyntaxContext::empty().apply_mark(mark);

        Expr::from(swc_ecma_utils::quote_ident!(
            ctxt,
            $span,
            concat!("_", stringify!($field_name))
        ))
    }};
}

/// Not a public api.
#[doc(hidden)]
#[macro_export]
macro_rules! helper {
    ($($t:tt)*) => {{
        use swc_ecma_utils::ExprFactory;
        $crate::helper_expr!($($t)*).as_callee()
    }};
}