swc_ecma_compat_es2022/class_properties/
used_name.rs1use swc_atoms::Atom;
2use swc_ecma_ast::*;
3use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
4use swc_trace_macro::swc_trace;
5
6pub(super) struct UsedNameCollector<'a> {
7 pub used_names: &'a mut Vec<Atom>,
8}
9
10macro_rules! noop {
11 ($name:ident, $T:path) => {
12 fn $name(&mut self, _: &$T) {}
14 };
15}
16
17#[swc_trace]
18impl Visit for UsedNameCollector<'_> {
19 noop_visit_type!(fail);
20
21 noop!(visit_arrow_expr, ArrowExpr);
22
23 noop!(visit_function, Function);
24
25 noop!(visit_setter_prop, SetterProp);
26
27 noop!(visit_getter_prop, GetterProp);
28
29 noop!(visit_method_prop, MethodProp);
30
31 noop!(visit_constructor, Constructor);
32
33 fn visit_expr(&mut self, expr: &Expr) {
34 match *expr {
35 Expr::Ident(ref i) => self.used_names.push(i.sym.clone()),
36 _ => expr.visit_children_with(self),
37 }
38 }
39}