Skip to content

Commit

Permalink
refactor(es/minifier): Remove mangle.safari10 (#8857)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8837
  • Loading branch information
Auspicus committed Apr 16, 2024
1 parent 0af2010 commit df2e056
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 43 deletions.
1 change: 0 additions & 1 deletion crates/swc_ecma_minifier/benches/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn run(src: &str) {
keep_fn_names: false,
keep_private_props: false,
ie8: false,
safari10: false,
..Default::default()
}),
wrap: false,
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/option/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct MangleOptions {
#[serde(default, alias = "ie8")]
pub ie8: bool,

#[deprecated = "This field is no longer required to work around bugs in Safari 10."]
#[serde(default, alias = "safari10")]
pub safari10: bool,

Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub(crate) fn name_mangler(
renamer(
swc_ecma_transforms_base::hygiene::Config {
keep_class_names: options.keep_class_names,
safari_10: options.safari10,
top_level_mark,
ignore_eval: options.eval,
..Default::default()
},
ManglingRenamer { chars, preserved }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ new class {
throw {
m: "PASS"
};
} catch ({ m: B }) {
console.log(B);
} catch ({ m: A }) {
console.log(A);
}
}
}().f();
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ new class {
throw {
m: "PASS"
};
} catch ({ m: B }) {
console.log(B);
} catch ({ m: A }) {
console.log(A);
}
}
}().f();
1 change: 1 addition & 0 deletions crates/swc_ecma_transforms_base/src/hygiene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Config {
pub keep_class_names: bool,

/// If true, the bug of safari 10 is avoided.
#[deprecated = "This field is no longer required to work around bugs in Safari 10."]
pub safari_10: bool,

/// The marks derived from this marks will treated as `specified by user`
Expand Down
47 changes: 11 additions & 36 deletions crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub(super) mod scope;

#[derive(Debug, Default)]
pub(super) struct Analyzer {
pub safari_10: bool,
/// If `eval` exists for the current scope, we only rename synthesized
/// identifiers.
pub has_eval: bool,
Expand Down Expand Up @@ -50,7 +49,6 @@ impl Analyzer {
{
{
let mut v = Analyzer {
safari_10: self.safari_10,
has_eval: self.has_eval,
top_level_mark: self.top_level_mark,

Expand Down Expand Up @@ -153,43 +151,20 @@ impl Visit for Analyzer {
}

fn visit_catch_clause(&mut self, n: &CatchClause) {
if self.safari_10 {
let old_is_pat_decl = self.is_pat_decl;
let old_in_catch_params = self.in_catch_params;

self.is_pat_decl = true;
self.in_catch_params = true;
n.param.visit_with(self);

self.in_catch_params = old_in_catch_params;
self.is_pat_decl = old_is_pat_decl;

self.with_scope(ScopeKind::Block, |v| {
let old = v.is_pat_decl;
let old_in_catch_params = v.in_catch_params;

v.is_pat_decl = false;
n.body.visit_children_with(v);

v.is_pat_decl = old;
v.in_catch_params = old_in_catch_params;
})
} else {
self.with_scope(ScopeKind::Block, |v| {
let old = v.is_pat_decl;
let old_in_catch_params = v.in_catch_params;
self.with_scope(ScopeKind::Block, |v| {
let old = v.is_pat_decl;
let old_in_catch_params = v.in_catch_params;

v.is_pat_decl = false;
n.body.visit_children_with(v);
v.is_pat_decl = false;
n.body.visit_children_with(v);

v.is_pat_decl = true;
v.in_catch_params = true;
n.param.visit_with(v);
v.is_pat_decl = true;
v.in_catch_params = true;
n.param.visit_with(v);

v.is_pat_decl = old;
v.in_catch_params = old_in_catch_params;
})
}
v.is_pat_decl = old;
v.in_catch_params = old_in_catch_params;
})
}

fn visit_class_decl(&mut self, c: &ClassDecl) {
Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_transforms_base/src/rename/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ where
{
let mut scope = {
let mut v = Analyzer {
safari_10: self.config.safari_10,
has_eval,
top_level_mark: self.config.top_level_mark,

Expand Down

0 comments on commit df2e056

Please sign in to comment.