From 3149fe0aa4b93dca6cac05aa4e8ebff6515a93c8 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:22:49 +0000 Subject: [PATCH] test(minifier): add anonymous function test case for logical expression to logical assignment compression (#8347) Added a test case that tells having an anonymous function on the right hand side for "logical expression to logical assignment" compression is fine. --- .../src/ast_passes/peephole_substitute_alternate_syntax.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index 9e2b1f196..8d5ebf3ff 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -1520,6 +1520,10 @@ mod test { test("x && (x = g())", "x &&= g()"); test("x ?? (x = g())", "x ??= g()"); + // `||=`, `&&=`, `??=` sets the name property of the function + // Example case: `let f = false; f || (f = () => {}); console.log(f.name)` + test("x || (x = () => 'a')", "x ||= () => 'a'"); + test_same("x || (y = 3)"); // foo() might have a side effect