swc_estree_ast/
ser.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
use serde::Serializer;

use crate::flavor::Flavor;

pub(crate) fn serialize_optional<S>(o: &Option<bool>, s: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    s.serialize_some(&o.unwrap_or(false))
}

/// Always serializes as a boolean value.
pub(crate) fn serialize_as_bool<S>(o: &Option<bool>, s: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    s.serialize_bool(o.unwrap_or(false))
}

pub(crate) fn skip_expression_for_fn<T>(_: T) -> bool {
    match Flavor::current() {
        Flavor::Acorn { .. } => false,
        Flavor::Babel => true,
    }
}

pub(crate) fn skip_interpreter<T>(_: T) -> bool {
    match Flavor::current() {
        Flavor::Acorn { .. } => true,
        Flavor::Babel => false,
    }
}

pub(crate) fn skip_typescript<T>(_: T) -> bool {
    match Flavor::current() {
        Flavor::Acorn { .. } => true,
        Flavor::Babel => false,
    }
}

pub(crate) fn skip_comments_on_program<T>(_: T) -> bool {
    match Flavor::current() {
        Flavor::Acorn { extra_comments } => !extra_comments,
        _ => true,
    }
}