swc_ecma_quote_macros/ast/
id.rs

1use swc_ecma_ast::*;
2use syn::parse_quote;
3
4use super::ToCode;
5use crate::ctxt::Ctx;
6
7impl ToCode for swc_ecma_ast::Ident {
8    fn to_code(&self, cx: &Ctx) -> syn::Expr {
9        if let Some(var_name) = self.sym.strip_prefix('$') {
10            if let Some(var) = cx.var(crate::ctxt::VarPos::Ident, var_name) {
11                return var.get_expr();
12            }
13        }
14
15        let sym_value = self.sym.to_code(cx);
16        parse_quote!(swc_core::ecma::ast::Ident::new_no_ctxt(
17            #sym_value,
18            swc_core::common::DUMMY_SP,
19        ))
20    }
21}
22
23impl_struct!(IdentName, [span, sym]);
24impl_struct!(PrivateName, [span, name]);