Some cleanup in JS optimizer
This commit is contained in:
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.js.inline.context.InliningContext
|
|||||||
import org.jetbrains.kotlin.js.inline.context.NamingContext
|
import org.jetbrains.kotlin.js.inline.context.NamingContext
|
||||||
import org.jetbrains.kotlin.js.inline.util.*
|
import org.jetbrains.kotlin.js.inline.util.*
|
||||||
import org.jetbrains.kotlin.js.inline.util.rewriters.ReturnReplacingVisitor
|
import org.jetbrains.kotlin.js.inline.util.rewriters.ReturnReplacingVisitor
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.newVar
|
|
||||||
|
|
||||||
class FunctionInlineMutator
|
class FunctionInlineMutator
|
||||||
private constructor(
|
private constructor(
|
||||||
|
|||||||
+1
-2
@@ -157,8 +157,7 @@ internal class TemporaryAssignmentElimination(private val root: JsBlock) {
|
|||||||
|
|
||||||
val assignment = JsAstUtils.decomposeAssignmentToVariable(x.expression)
|
val assignment = JsAstUtils.decomposeAssignmentToVariable(x.expression)
|
||||||
if (assignment != null) {
|
if (assignment != null) {
|
||||||
val (name, value) = assignment
|
val usage = getUsage(assignment.first)
|
||||||
val usage = getUsage(name)
|
|
||||||
if (usage is Usage.Declaration) {
|
if (usage is Usage.Declaration) {
|
||||||
usage.count++
|
usage.count++
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -190,7 +190,7 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
val name = x.name
|
val name = x.name
|
||||||
if (x.qualifier == null && name != null && shouldConsiderTemporary(name)) {
|
if (x.qualifier == null && name != null && shouldConsiderTemporary(name)) {
|
||||||
hasChanges = true
|
hasChanges = true
|
||||||
val newExpr = definedValues[name]!!
|
val newExpr = definedValues[name] ?: JsLiteral.UNDEFINED
|
||||||
ctx.replaceMe(accept(newExpr))
|
ctx.replaceMe(accept(newExpr))
|
||||||
usages[name] = usages[name]!! - 1
|
usages[name] = usages[name]!! - 1
|
||||||
return false
|
return false
|
||||||
@@ -201,6 +201,17 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
override fun visit(x: JsBreak, ctx: JsContext<*>) = false
|
override fun visit(x: JsBreak, ctx: JsContext<*>) = false
|
||||||
|
|
||||||
override fun visit(x: JsContinue, ctx: JsContext<*>) = false
|
override fun visit(x: JsContinue, ctx: JsContext<*>) = false
|
||||||
|
|
||||||
|
override fun visit(x: JsReturn, ctx: JsContext<*>): Boolean {
|
||||||
|
val returnValue = x.expression
|
||||||
|
if (returnValue is JsNameRef) {
|
||||||
|
val name = returnValue.name
|
||||||
|
if (returnValue.qualifier == null && name != null && name in temporary && definitions[name] ?: 0 == 0) {
|
||||||
|
x.expression = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.visit(x, ctx)
|
||||||
|
}
|
||||||
}.accept(root)
|
}.accept(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user