swc_ecma_codegen/
config.rs1#[cfg(feature = "serde-impl")]
2use serde::{Deserialize, Serialize};
3use swc_ecma_ast::EsVersion;
4
5#[cfg(feature = "serde-impl")]
6const fn true_by_default() -> bool {
7 true
8}
9
10#[derive(Debug, Clone, Copy)]
11#[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))]
12#[cfg_attr(feature = "serde-impl", serde(rename_all = "camelCase"))]
13#[non_exhaustive]
14pub struct Config {
15 #[cfg_attr(feature = "serde-impl", serde(default = "EsVersion::latest"))]
25 pub target: EsVersion,
26
27 #[cfg_attr(feature = "serde-impl", serde(default))]
31 pub ascii_only: bool,
32
33 #[cfg_attr(feature = "serde-impl", serde(default))]
34 pub minify: bool,
35
36 #[cfg_attr(feature = "serde-impl", serde(default))]
40 pub omit_last_semi: bool,
41
42 #[cfg_attr(feature = "serde-impl", serde(default))]
43 pub emit_assert_for_import_attributes: bool,
44
45 #[cfg_attr(feature = "serde-impl", serde(default))]
46 pub inline_script: bool,
47
48 #[cfg_attr(feature = "serde-impl", serde(default = "true_by_default"))]
53 pub reduce_escaped_newline: bool,
54}
55
56impl Default for Config {
57 fn default() -> Self {
58 Self {
59 target: EsVersion::latest(),
60 minify: false,
61 ascii_only: false,
62 omit_last_semi: false,
63 emit_assert_for_import_attributes: false,
64 inline_script: false,
65 reduce_escaped_newline: true,
66 }
67 }
68}
69
70impl Config {
71 pub fn with_target(mut self, target: EsVersion) -> Self {
72 self.target = target;
73 self
74 }
75
76 pub fn with_minify(mut self, minify: bool) -> Self {
77 self.minify = minify;
78 self
79 }
80
81 pub fn with_ascii_only(mut self, ascii_only: bool) -> Self {
82 self.ascii_only = ascii_only;
83 self
84 }
85
86 pub fn with_omit_last_semi(mut self, omit_last_semi: bool) -> Self {
87 self.omit_last_semi = omit_last_semi;
88 self
89 }
90
91 pub fn with_emit_assert_for_import_attributes(
92 mut self,
93 emit_assert_for_import_attributes: bool,
94 ) -> Self {
95 self.emit_assert_for_import_attributes = emit_assert_for_import_attributes;
96 self
97 }
98
99 pub fn with_inline_script(mut self, inline_script: bool) -> Self {
100 self.inline_script = inline_script;
101 self
102 }
103
104 pub fn with_reduce_escaped_newline(mut self, reduce_escaped_newline: bool) -> Self {
109 self.reduce_escaped_newline = reduce_escaped_newline;
110 self
111 }
112}