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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
mod arrow_functions;
mod options;

pub use arrow_functions::{ArrowFunctions, ArrowFunctionsOptions};
pub use options::ES2015Options;

use oxc_allocator::Vec;
use oxc_ast::ast::*;
use std::rc::Rc;

use crate::context::Ctx;

#[allow(dead_code)]
pub struct ES2015<'a> {
    ctx: Ctx<'a>,
    options: ES2015Options,

    // Plugins
    arrow_functions: ArrowFunctions<'a>,
}

impl<'a> ES2015<'a> {
    pub fn new(options: ES2015Options, ctx: &Ctx<'a>) -> Self {
        Self {
            arrow_functions: ArrowFunctions::new(
                options.arrow_function.clone().unwrap_or_default(),
                ctx,
            ),
            ctx: Rc::clone(ctx),
            options,
        }
    }

    pub fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_statements(stmts);
        }
    }

    pub fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_statements_on_exit(stmts);
        }
    }

    pub fn transform_jsx_opening_element(&mut self, elem: &mut JSXOpeningElement<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_jsx_opening_element(elem);
        }
    }

    pub fn transform_declaration(&mut self, decl: &mut Declaration<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_declaration(decl);
        }
    }

    pub fn transform_expression(&mut self, expr: &mut Expression<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_expression(expr);
        }
    }

    pub fn transform_expression_on_exit(&mut self, expr: &mut Expression<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_expression_on_exit(expr);
        }
    }

    pub fn transform_declaration_on_exit(&mut self, decl: &mut Declaration<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_declaration_on_exit(decl);
        }
    }

    pub fn transform_class(&mut self, class: &mut Class<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_class(class);
        }
    }

    pub fn transform_class_on_exit(&mut self, class: &mut Class<'a>) {
        if self.options.arrow_function.is_some() {
            self.arrow_functions.transform_class_on_exit(class);
        }
    }
}