swc_ecma_transforms_base/
assumptions.rs

1use serde::{Deserialize, Serialize};
2
3/// Alternative for https://babeljs.io/docs/en/assumptions
4///
5/// All fields default to `false`.
6#[derive(
7    Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
8)]
9#[non_exhaustive]
10#[serde(rename_all = "camelCase", deny_unknown_fields)]
11pub struct Assumptions {
12    /// https://babeljs.io/docs/en/assumptions#arraylikeisiterable
13    #[serde(default)]
14    pub array_like_is_iterable: bool,
15
16    /// https://babeljs.io/docs/en/assumptions#constantreexports
17    #[serde(default)]
18    pub constant_reexports: bool,
19
20    /// https://babeljs.io/docs/en/assumptions#constantsuper
21    #[serde(default)]
22    pub constant_super: bool,
23
24    /// https://babeljs.io/docs/en/assumptions#enumerablemodulemeta
25    #[serde(default)]
26    pub enumerable_module_meta: bool,
27
28    /// https://babeljs.io/docs/en/assumptions#ignorefunctionlength
29    #[serde(default)]
30    pub ignore_function_length: bool,
31
32    #[serde(default)]
33    pub ignore_function_name: bool,
34
35    /// https://babeljs.io/docs/en/assumptions#ignoretoprimitivehint
36    #[serde(default)]
37    pub ignore_to_primitive_hint: bool,
38
39    /// https://babeljs.io/docs/en/assumptions#iterableisarray
40    #[serde(default)]
41    pub iterable_is_array: bool,
42
43    /// https://babeljs.io/docs/en/assumptions#mutabletemplateobject
44    #[serde(default)]
45    pub mutable_template_object: bool,
46
47    /// https://babeljs.io/docs/en/assumptions#noclasscalls
48    #[serde(default)]
49    pub no_class_calls: bool,
50
51    /// https://babeljs.io/docs/en/assumptions#nodocumentall
52    #[serde(default)]
53    pub no_document_all: bool,
54
55    /// https://babeljs.io/docs/en/assumptions#noincompletensimportdetection
56    #[serde(default)]
57    pub no_incomplete_ns_import_detection: bool,
58
59    /// https://babeljs.io/docs/en/assumptions#nonewarrows
60    #[serde(default)]
61    pub no_new_arrows: bool,
62
63    /// https://babeljs.io/docs/en/assumptions#objectrestnosymbols
64    #[serde(default)]
65    pub object_rest_no_symbols: bool,
66
67    /// https://babeljs.io/docs/en/assumptions#privatefieldsasproperties
68    #[serde(default)]
69    pub private_fields_as_properties: bool,
70
71    /// https://babeljs.io/docs/en/assumptions#puregetters
72    #[serde(default)]
73    pub pure_getters: bool,
74
75    /// https://babeljs.io/docs/en/assumptions#setclassmethods
76    #[serde(default)]
77    pub set_class_methods: bool,
78
79    /// https://babeljs.io/docs/en/assumptions#setcomputedproperties
80    #[serde(default)]
81    pub set_computed_properties: bool,
82
83    /// https://babeljs.io/docs/en/assumptions#setpublicclassfields
84    #[serde(default)]
85    pub set_public_class_fields: bool,
86
87    /// https://babeljs.io/docs/en/assumptions#setspreadproperties
88    #[serde(default)]
89    pub set_spread_properties: bool,
90
91    /// https://babeljs.io/docs/en/assumptions#skipforofiteratorclosing
92    #[serde(default)]
93    pub skip_for_of_iterator_closing: bool,
94
95    /// https://babeljs.io/docs/en/assumptions#superiscallableconstructor
96    #[serde(default)]
97    pub super_is_callable_constructor: bool,
98}
99
100#[allow(deprecated)]
101impl Assumptions {
102    pub fn all() -> Self {
103        Self {
104            array_like_is_iterable: true,
105            constant_reexports: true,
106            constant_super: true,
107            enumerable_module_meta: true,
108            ignore_function_length: true,
109            ignore_function_name: true,
110            ignore_to_primitive_hint: true,
111            iterable_is_array: true,
112            mutable_template_object: true,
113            no_class_calls: true,
114            no_document_all: true,
115            no_incomplete_ns_import_detection: true,
116            no_new_arrows: true,
117            object_rest_no_symbols: true,
118            private_fields_as_properties: true,
119            pure_getters: true,
120            set_class_methods: true,
121            set_computed_properties: true,
122            set_public_class_fields: true,
123            set_spread_properties: true,
124            skip_for_of_iterator_closing: true,
125            super_is_callable_constructor: true,
126        }
127    }
128}