[K/JS] Optimize logical operators generating

This commit is contained in:
Artem Kobzar
2024-02-23 15:16:31 +00:00
committed by Space Team
parent 425381ddf9
commit be47632609
10 changed files with 63 additions and 2 deletions
@@ -239,6 +239,20 @@ class IrElementToJsExpressionTransformer : BaseIrElementToJsNodeTransformer<JsEx
}
override fun visitWhen(expression: IrWhen, context: JsGenerationContext): JsExpression {
if (expression.origin == IrStatementOrigin.ANDAND) {
return JsBinaryOperation(
JsBinaryOperator.AND,
expression.branches[0].condition.accept(this, context),
expression.branches[0].result.accept(this, context)
)
}
if (expression.origin == IrStatementOrigin.OROR) {
return JsBinaryOperation(
JsBinaryOperator.OR,
expression.branches[0].condition.accept(this, context),
expression.branches[1].result.accept(this, context)
)
}
val lastBranch = expression.branches.lastOrNull()
val implicitElse =
if (lastBranch == null || !isElseBranch(lastBranch))
@@ -25,6 +25,7 @@ fun test(): Long {
// EXPECTATIONS JS_IR
// test.kt:6 box
// test.kt:10 test
// test.kt:12 test
// test.kt:7 box