From 4c505edef52359f432c04f3f4802cbcc5c7f8ea7 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sun, 11 Jan 2026 16:43:02 +0800 Subject: [PATCH] fix: let --- nix-js/src/codegen.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nix-js/src/codegen.rs b/nix-js/src/codegen.rs index f69712d..7eaab53 100644 --- a/nix-js/src/codegen.rs +++ b/nix-js/src/codegen.rs @@ -194,11 +194,18 @@ impl Compile for Let { for &expr in scc_exprs { let ir = ctx.get_ir(expr); let value = if let Ir::Thunk(inner) = ir { - ctx.get_ir(*inner).compile(ctx) + let inner_ir = ctx.get_ir(*inner); + // Don't unwrap Thunk if inner is a Let expression + // to avoid generating IIFE that executes immediately + if matches!(inner_ir, Ir::Let(_)) { + ir.compile(ctx) + } else { + inner_ir.compile(ctx) + } } else { ir.compile(ctx) }; - js_statements.push(format!("let expr{}={}", expr.0, value)); + js_statements.push(format!("const expr{}={}", expr.0, value)); } } }