[K/JS] Optimize logical operators generating
This commit is contained in:
+14
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user