[JS IR] Style fixes

This commit is contained in:
Alexander Korepanov
2023-04-18 12:10:28 +02:00
committed by Space Team
parent 9fd05632f0
commit 84b5af3c89
4 changed files with 14 additions and 19 deletions
@@ -214,8 +214,10 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
override fun visitWhileLoop(loop: IrWhileLoop, context: JsGenerationContext): JsStatement { override fun visitWhileLoop(loop: IrWhileLoop, context: JsGenerationContext): JsStatement {
//TODO what if body null? //TODO what if body null?
val label = context.getNameForLoop(loop) val label = context.getNameForLoop(loop)
val loopStatement = JsWhile(loop.condition.accept(IrElementToJsExpressionTransformer(), context), val loopStatement = JsWhile(
loop.body?.accept(this, context) ?: JsEmpty) loop.condition.accept(IrElementToJsExpressionTransformer(), context),
loop.body?.accept(this, context) ?: JsEmpty
)
return label?.let { JsLabel(it, loopStatement) } ?: loopStatement return label?.let { JsLabel(it, loopStatement) } ?: loopStatement
} }
@@ -78,6 +78,7 @@ val IrFunctionAccessExpression.typeArguments: List<IrType?>
val IrFunctionAccessExpression.valueArguments: List<IrExpression?> val IrFunctionAccessExpression.valueArguments: List<IrExpression?>
get() = List(valueArgumentsCount) { getValueArgument(it) } get() = List(valueArgumentsCount) { getValueArgument(it) }
val IrClass.isInstantiableEnum: Boolean val IrClass.isInstantiableEnum: Boolean
get() = isEnumClass && !isExpect && !isEffectivelyExternal() get() = isEnumClass && !isExpect && !isEffectivelyExternal()
@@ -76,7 +76,7 @@ internal class DoWhileGuardElimination(private val root: JsStatement) {
if (guard != null) { if (guard != null) {
// When do..while loop has no label and we encounter break guard from nested loop, we can't // When do..while loop has no label and we encounter `break guard` from nested loop, we can't
// replace this break with continue. Example: // replace this break with continue. Example:
// //
// do { // do {
@@ -209,8 +209,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
try { try {
localVars = mutableSetOf() localVars = mutableSetOf()
return block() return block()
} } finally {
finally {
currentScope -= localVars currentScope -= localVars
localVars = localVarsBackup localVars = localVarsBackup
} }
@@ -233,8 +232,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
if (assignment != null) { if (assignment != null) {
val (name, value) = assignment val (name, value) = assignment
handleDefinition(name, value, x) handleDefinition(name, value, x)
} } else {
else {
if (handleExpression(expression)) { if (handleExpression(expression)) {
invalidateTemporaries() invalidateTemporaries()
} }
@@ -256,8 +254,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
if (isTrivial(value)) { if (isTrivial(value)) {
statementsToRemove += node statementsToRemove += node
namesToSubstitute += name namesToSubstitute += name
} } else {
else {
lastAssignedVars += Pair(name, node) lastAssignedVars += Pair(name, node)
if (sideEffects) { if (sideEffects) {
namesWithSideEffects += name namesWithSideEffects += name
@@ -460,8 +457,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
substitutableVariableReferences += name substitutableVariableReferences += name
} }
} }
} } else {
else {
super.visitNameRef(nameRef) super.visitNameRef(nameRef)
if (nameRef.sideEffects == SideEffectKind.AFFECTS_STATE) { if (nameRef.sideEffects == SideEffectKind.AFFECTS_STATE) {
sideEffectOccurred = true sideEffectOccurred = true
@@ -479,8 +475,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
if (qualifier != null) { if (qualifier != null) {
accept(qualifier) accept(qualifier)
} }
} } else if (left is JsArrayAccess) {
else if (left is JsArrayAccess) {
accept(left.arrayExpression) accept(left.arrayExpression)
accept(left.indexExpression) accept(left.indexExpression)
} }
@@ -488,13 +483,11 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
accept(right) accept(right)
sideEffectOccurred = true sideEffectOccurred = true
} } else if (x.operator == JsBinaryOperator.AND || x.operator == JsBinaryOperator.OR) {
else if (x.operator == JsBinaryOperator.AND || x.operator == JsBinaryOperator.OR) {
accept(x.arg1) accept(x.arg1)
sideEffectOccurred = true sideEffectOccurred = true
accept(x.arg2) accept(x.arg2)
} } else {
else {
super.visitBinaryExpression(x) super.visitBinaryExpression(x)
} }
} }
@@ -518,8 +511,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
for (initializer in initializers) { for (initializer in initializers) {
ctx.addPrevious(JsExpressionStatement(accept(initializer)).apply { synthetic = true }) ctx.addPrevious(JsExpressionStatement(accept(initializer)).apply { synthetic = true })
} }
} } else {
else {
ctx.addPrevious(JsVars(*subList.toTypedArray()).apply { synthetic = true }) ctx.addPrevious(JsVars(*subList.toTypedArray()).apply { synthetic = true })
} }
} }