fix(minifier): preserve iife with directives (#27060)

do not fold iife when body contains directives.

ref #24331
This commit is contained in:
Armano authored and GitHub committed 2026-09-28 10:17:13 +01:00
1 parent 9d80eeddbd
commit c380c85c08
2 files changed
+15 -1

No files matched your search

@@ -1919,7 +1919,7 @@ impl<'a> PeepholeOptimizations {
return;
}
let Some(body) = f.get_function_body_mut() else { return };
if body.statements.len() != 1 {
if body.statements.len() != 1 || !body.directives.is_empty() {
return;
}
match &mut body.statements[0] {
@@ -489,6 +489,20 @@ fn test_fold_iife() {
test("a((() => true)());", "a(!0)");
test("a((() => { return true })());", "a(!0)");
test("(() => { 'use strict'; return a() })()", "a()");
test_same_options_source_type(
"(() => { 'use strict'; return a() })()",
SourceType::cjs(),
&CompressOptions::smallest(),
);
test("(() => { 'use strict'; a() })()", "a()");
test_same_options_source_type(
"(() => { 'use strict'; a() })()",
SourceType::cjs(),
&CompressOptions::smallest(),
);
test_same("(() => { 'use cache'; return a() })()");
test_same("var a = (function () { b() })()");
test_same("var a = (function () { return b() })()");
test_same("var a = (function () { return this })()");