Skip to content

Commit 2570efd

Browse files
committed
fix: consistency
1 parent 1c17d58 commit 2570efd

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

Diff for: crates/swc_ecma_minifier/src/option/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use swc_atoms::Atom;
99
use swc_common::Mark;
1010
use swc_config::{merge::Merge, CachedRegex};
1111
use swc_ecma_ast::{EsVersion, Expr, Id};
12+
use terser::TerserExperimentalOptions;
1213

1314
/// Implement default using serde.
1415
macro_rules! impl_default {
@@ -132,6 +133,20 @@ pub struct CompressExperimentalOptions {
132133
pub reduce_escaped_newline: bool,
133134
}
134135

136+
impl CompressExperimentalOptions {
137+
fn from_defaults(defaults: bool) -> Self {
138+
CompressExperimentalOptions {
139+
reduce_escaped_newline: defaults,
140+
}
141+
}
142+
143+
fn from_terser_with_defaults(terser: TerserExperimentalOptions, defaults: bool) -> Self {
144+
CompressExperimentalOptions {
145+
reduce_escaped_newline: terser.reduce_escaped_newline.unwrap_or(defaults),
146+
}
147+
}
148+
}
149+
135150
impl Default for CompressExperimentalOptions {
136151
fn default() -> Self {
137152
CompressExperimentalOptions {

Diff for: crates/swc_ecma_minifier/src/option/terser.rs

+11-23
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,8 @@ pub enum TerserTopRetainOption {
7575
#[serde(deny_unknown_fields)]
7676
#[non_exhaustive]
7777
pub struct TerserExperimentalOptions {
78-
#[serde(default = "true_by_default")]
79-
pub reduce_escaped_newline: bool,
80-
}
81-
82-
impl Default for TerserExperimentalOptions {
83-
fn default() -> Self {
84-
TerserExperimentalOptions {
85-
reduce_escaped_newline: true,
86-
}
87-
}
78+
#[serde(default)]
79+
pub reduce_escaped_newline: Option<bool>,
8880
}
8981

9082
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -421,11 +413,15 @@ impl TerserCompressorOptions {
421413
})
422414
})
423415
.collect(),
424-
experimental: self.experimental.map(From::from).unwrap_or(
425-
CompressExperimentalOptions {
426-
reduce_escaped_newline: self.defaults,
427-
},
428-
),
416+
experimental: self
417+
.experimental
418+
.map(|experimental| {
419+
CompressExperimentalOptions::from_terser_with_defaults(
420+
experimental,
421+
self.defaults,
422+
)
423+
})
424+
.unwrap_or(CompressExperimentalOptions::from_defaults(self.defaults)),
429425
}
430426
}
431427
}
@@ -481,14 +477,6 @@ impl From<TerserTopRetainOption> for Vec<Atom> {
481477
}
482478
}
483479

484-
impl From<TerserExperimentalOptions> for CompressExperimentalOptions {
485-
fn from(value: TerserExperimentalOptions) -> Self {
486-
CompressExperimentalOptions {
487-
reduce_escaped_newline: value.reduce_escaped_newline,
488-
}
489-
}
490-
}
491-
492480
fn value_to_expr(v: Value) -> Box<Expr> {
493481
match v {
494482
Value::Null => Lit::Null(Null { span: DUMMY_SP }).into(),

0 commit comments

Comments
 (0)