[JS IR] Optimize JS AST for closures

^KT-58891 Fixed
This commit is contained in:
Alexander Korepanov
2023-07-06 22:17:50 +02:00
committed by Space Team
parent 524c475834
commit a588e75c11
9 changed files with 136 additions and 2 deletions
@@ -0,0 +1,23 @@
// IGNORE_BACKEND_K2: JS_IR
// FIR works fine, however it generates another names for the temporary variables, therefore ignore it
fun demo(f: () -> String) = f()
// EXPECT_GENERATED_JS: function=test$lambda expect=deadCodeEliminationTestLambda.js
fun test(x: String?): String {
val r = demo {
val z = x ?: run {
return@demo "OK"
}
"Fail 1: $z"
}
return r
}
fun box(): String {
val r = test(null)
if (r != "OK") {
return "Fail test, got $r"
}
return "OK"
}