This commit is contained in:
2026-01-11 16:43:02 +08:00
parent 75cb3bfaf1
commit 4c505edef5

View File

@@ -194,11 +194,18 @@ impl<Ctx: CodegenContext> Compile<Ctx> for Let {
for &expr in scc_exprs { for &expr in scc_exprs {
let ir = ctx.get_ir(expr); let ir = ctx.get_ir(expr);
let value = if let Ir::Thunk(inner) = ir { 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 { } else {
ir.compile(ctx) ir.compile(ctx)
}; };
js_statements.push(format!("let expr{}={}", expr.0, value)); js_statements.push(format!("const expr{}={}", expr.0, value));
} }
} }
} }