mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
fix(es/minifier): Abort seq inliner using visitor (#7699)
**Related issue:** - Closes #7697.
This commit is contained in:
parent
cd98859482
commit
a26dbce981
@ -2031,9 +2031,11 @@ impl Optimizer<'_> {
|
|||||||
pat_usage: Default::default(),
|
pat_usage: Default::default(),
|
||||||
target: a_id,
|
target: a_id,
|
||||||
in_lhs: false,
|
in_lhs: false,
|
||||||
|
abort: false,
|
||||||
|
in_abort: false,
|
||||||
};
|
};
|
||||||
b.visit_with(&mut v);
|
b.visit_with(&mut v);
|
||||||
if v.expr_usage != 1 || v.pat_usage != 0 {
|
if v.expr_usage != 1 || v.pat_usage != 0 || v.abort {
|
||||||
log_abort!(
|
log_abort!(
|
||||||
"sequences: Aborting merging of an update expression because of \
|
"sequences: Aborting merging of an update expression because of \
|
||||||
usage counts ({}, ref = {}, pat = {})",
|
usage counts ({}, ref = {}, pat = {})",
|
||||||
@ -2103,9 +2105,11 @@ impl Optimizer<'_> {
|
|||||||
pat_usage: Default::default(),
|
pat_usage: Default::default(),
|
||||||
target: a_id,
|
target: a_id,
|
||||||
in_lhs: false,
|
in_lhs: false,
|
||||||
|
abort: false,
|
||||||
|
in_abort: false,
|
||||||
};
|
};
|
||||||
b.visit_with(&mut v);
|
b.visit_with(&mut v);
|
||||||
if v.expr_usage != 1 || v.pat_usage != 0 {
|
if v.expr_usage != 1 || v.pat_usage != 0 || v.abort {
|
||||||
log_abort!(
|
log_abort!(
|
||||||
"sequences: Aborting merging of an update expression because of \
|
"sequences: Aborting merging of an update expression because of \
|
||||||
usage counts ({}, ref = {}, pat = {})",
|
usage counts ({}, ref = {}, pat = {})",
|
||||||
@ -2426,9 +2430,11 @@ impl Optimizer<'_> {
|
|||||||
pat_usage: Default::default(),
|
pat_usage: Default::default(),
|
||||||
target: &left_id,
|
target: &left_id,
|
||||||
in_lhs: false,
|
in_lhs: false,
|
||||||
|
abort: false,
|
||||||
|
in_abort: false,
|
||||||
};
|
};
|
||||||
b.visit_with(&mut v);
|
b.visit_with(&mut v);
|
||||||
if v.expr_usage != 1 || v.pat_usage != 0 {
|
if v.expr_usage != 1 || v.pat_usage != 0 || v.abort {
|
||||||
log_abort!(
|
log_abort!(
|
||||||
"sequences: Aborting because of usage counts ({}{:?}, ref = {}, pat = {})",
|
"sequences: Aborting because of usage counts ({}{:?}, ref = {}, pat = {})",
|
||||||
left_id.sym,
|
left_id.sym,
|
||||||
@ -2493,8 +2499,11 @@ struct UsageCounter<'a> {
|
|||||||
expr_usage: usize,
|
expr_usage: usize,
|
||||||
pat_usage: usize,
|
pat_usage: usize,
|
||||||
|
|
||||||
|
abort: bool,
|
||||||
|
|
||||||
target: &'a Ident,
|
target: &'a Ident,
|
||||||
in_lhs: bool,
|
in_lhs: bool,
|
||||||
|
in_abort: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visit for UsageCounter<'_> {
|
impl Visit for UsageCounter<'_> {
|
||||||
@ -2502,6 +2511,11 @@ impl Visit for UsageCounter<'_> {
|
|||||||
|
|
||||||
fn visit_ident(&mut self, i: &Ident) {
|
fn visit_ident(&mut self, i: &Ident) {
|
||||||
if self.target.sym == i.sym && self.target.span.ctxt == i.span.ctxt {
|
if self.target.sym == i.sym && self.target.span.ctxt == i.span.ctxt {
|
||||||
|
if self.in_abort {
|
||||||
|
self.abort = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if self.in_lhs {
|
if self.in_lhs {
|
||||||
self.pat_usage += 1;
|
self.pat_usage += 1;
|
||||||
} else {
|
} else {
|
||||||
@ -2521,6 +2535,27 @@ impl Visit for UsageCounter<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_update_expr(&mut self, e: &UpdateExpr) {
|
||||||
|
let old_in_abort = self.in_abort;
|
||||||
|
self.in_abort = true;
|
||||||
|
e.visit_children_with(self);
|
||||||
|
self.in_abort = old_in_abort;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_await_expr(&mut self, e: &AwaitExpr) {
|
||||||
|
let old_in_abort = self.in_abort;
|
||||||
|
self.in_abort = true;
|
||||||
|
e.visit_children_with(self);
|
||||||
|
self.in_abort = old_in_abort;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_yield_expr(&mut self, e: &YieldExpr) {
|
||||||
|
let old_in_abort = self.in_abort;
|
||||||
|
self.in_abort = true;
|
||||||
|
e.visit_children_with(self);
|
||||||
|
self.in_abort = old_in_abort;
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &Pat) {
|
fn visit_pat(&mut self, p: &Pat) {
|
||||||
let old = self.in_lhs;
|
let old = self.in_lhs;
|
||||||
self.in_lhs = true;
|
self.in_lhs = true;
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"arguments": false,
|
||||||
|
"arrows": true,
|
||||||
|
"booleans": true,
|
||||||
|
"booleans_as_integers": false,
|
||||||
|
"collapse_vars": true,
|
||||||
|
"comparisons": true,
|
||||||
|
"computed_props": true,
|
||||||
|
"conditionals": true,
|
||||||
|
"dead_code": true,
|
||||||
|
"directives": true,
|
||||||
|
"drop_console": false,
|
||||||
|
"drop_debugger": true,
|
||||||
|
"evaluate": true,
|
||||||
|
"expression": true,
|
||||||
|
"hoist_funs": false,
|
||||||
|
"hoist_props": true,
|
||||||
|
"hoist_vars": false,
|
||||||
|
"if_return": true,
|
||||||
|
"join_vars": true,
|
||||||
|
"keep_classnames": false,
|
||||||
|
"keep_fargs": true,
|
||||||
|
"keep_fnames": false,
|
||||||
|
"keep_infinity": false,
|
||||||
|
"loops": true,
|
||||||
|
"negate_iife": true,
|
||||||
|
"properties": true,
|
||||||
|
"reduce_funcs": false,
|
||||||
|
"reduce_vars": false,
|
||||||
|
"side_effects": true,
|
||||||
|
"switches": true,
|
||||||
|
"typeofs": true,
|
||||||
|
"unsafe": false,
|
||||||
|
"unsafe_arrows": false,
|
||||||
|
"unsafe_comps": false,
|
||||||
|
"unsafe_Function": false,
|
||||||
|
"unsafe_math": false,
|
||||||
|
"unsafe_symbols": false,
|
||||||
|
"unsafe_methods": false,
|
||||||
|
"unsafe_proto": false,
|
||||||
|
"unsafe_regexp": false,
|
||||||
|
"unsafe_undefined": false,
|
||||||
|
"unused": true,
|
||||||
|
"const_to_let": true,
|
||||||
|
"pristine_globals": true,
|
||||||
|
"passes": 2
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
let id = 0;
|
||||||
|
|
||||||
|
export function getId() {
|
||||||
|
id = id % 9999;
|
||||||
|
return `${id++}`
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
let id = 0;
|
||||||
|
export function getId() {
|
||||||
|
return id %= 9999, `${id++}`;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user