swc_ecma_compat_es2020/
optional_chaining.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
use serde::Deserialize;
use swc_common::Mark;
use swc_ecma_ast::Pass;
use swc_ecma_compat_es2022::optional_chaining_impl::optional_chaining_impl;
use swc_ecma_visit::visit_mut_pass;

pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Pass {
    visit_mut_pass(optional_chaining_impl(
        swc_ecma_compat_es2022::optional_chaining_impl::Config {
            no_document_all: c.no_document_all,
            pure_getter: c.pure_getter,
        },
        unresolved_mark,
    ))
}

#[derive(Debug, Clone, Copy, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Config {
    #[serde(default)]
    pub no_document_all: bool,
    #[serde(default)]
    pub pure_getter: bool,
}