From cd4548fd8c32f67d0e8373f7a2c3cb625f43e6c4 Mon Sep 17 00:00:00 2001 From: Austaras Date: Tue, 23 Apr 2024 20:34:14 +0800 Subject: [PATCH] fix(es/minifier): Abort seq inline on recursive usage (#8887) **Related issue:** - Closes #8841 --- crates/swc_ecma_minifier/src/compress/optimize/sequences.rs | 2 +- crates/swc_ecma_minifier/tests/fixture/issues/8841/input.js | 4 ++++ crates/swc_ecma_minifier/tests/fixture/issues/8841/output.js | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/8841/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/8841/output.js diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs index 2a90e3c432a5..b1422fcc87eb 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs @@ -2308,7 +2308,7 @@ impl Optimizer<'_> { can_take_init = true; } - if usage.inline_prevented { + if usage.inline_prevented || usage.used_recursively { return Ok(false); } diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8841/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/8841/input.js new file mode 100644 index 000000000000..c34cb561beb0 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8841/input.js @@ -0,0 +1,4 @@ +export const k = (() => { + var x = x; + return x; +})(); diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8841/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8841/output.js new file mode 100644 index 000000000000..45a235405a64 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8841/output.js @@ -0,0 +1,2 @@ +var x; +export const k = x;