feat(es/minifier): Drop cycles in nested functions (#5933)

This commit is contained in:
Donny/강동윤 2022-09-22 22:54:49 +09:00 committed by GitHub
parent 098a021a43
commit e16827cc9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 1 deletions

View File

@ -162,7 +162,6 @@ drop_unused/issue_t161_top_retain_9/input.js
drop_unused/issue_t183/input.js
drop_unused/keep_assign/input.js
drop_unused/reassign_const/input.js
drop_unused/unused_circular_references_1/input.js
drop_unused/unused_circular_references_2/input.js
drop_unused/unused_circular_references_3/input.js
drop_unused/var_catch_toplevel/input.js

View File

@ -438,6 +438,7 @@ drop_unused/issue_t161_top_retain_7/input.js
drop_unused/keep_fnames/input.js
drop_unused/unused_block_decls/input.js
drop_unused/unused_block_decls_in_catch/input.js
drop_unused/unused_circular_references_1/input.js
drop_unused/unused_class_which_extends_might_throw/input.js
drop_unused/unused_class_which_might_throw/input.js
drop_unused/unused_class_which_might_throw_2/input.js

View File

@ -216,6 +216,7 @@ struct Analyzer<'a> {
#[derive(Debug, Default)]
struct Scope<'a> {
parent: Option<&'a Scope<'a>>,
kind: ScopeKind,
bindings_affected_by_eval: AHashSet<Id>,
found_direct_eval: bool,
@ -235,6 +236,12 @@ enum ScopeKind {
ArrowFn,
}
impl Default for ScopeKind {
fn default() -> Self {
Self::Fn
}
}
impl Analyzer<'_> {
fn with_ast_path<F>(&mut self, ids: Vec<Id>, op: F)
where
@ -327,6 +334,10 @@ impl Analyzer<'_> {
.add_dep_edge(component.clone(), id.clone(), assign)
}
if s.kind == ScopeKind::Fn && !s.ast_path.is_empty() {
break;
}
scope = s.parent;
}
}

View File

@ -0,0 +1,10 @@
export function f(x, y) {
function g() {
return h();
}
function h() {
return g();
}
return x + y;
}

View File

@ -0,0 +1,3 @@
export function f(x, y) {
return x + y;
}

View File

@ -0,0 +1,3 @@
export function f(x, y) {
return x + y;
}