提交 35ab41e9 编写于 作者: A Alexey Andreev

JS: when removing unused temporary variable, process its RHS value. Fix KT-15325

上级 49d57124
......@@ -507,7 +507,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
initializers.forEach { accept(it) }
if (isRemoved) {
for (initializer in initializers) {
ctx.addPrevious(JsExpressionStatement(initializer).apply { synthetic = x.synthetic })
ctx.addPrevious(JsExpressionStatement(accept(initializer)).apply { synthetic = x.synthetic })
}
}
else {
......@@ -530,10 +530,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
val (name, value) = assignment
if (shouldConsiderUnused(name)) {
hasChanges = true
ctx.replaceMe(JsExpressionStatement(value).run {
synthetic = true
accept(this)
})
ctx.replaceMe(accept(JsExpressionStatement(value)).apply { synthetic = true })
return false
}
}
......@@ -552,7 +549,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
val name = x.name
if (name != null && x.qualifier == null && name in namesToSubstitute) {
val replacement = accept(definedValues[name]!!)
ctx.replaceMe(replacement)
ctx.replaceMe(replacement.apply { synthetic = true })
return false
}
return super.visit(x, ctx)
......@@ -569,7 +566,7 @@ internal class TemporaryVariableElimination(private val function: JsFunction) {
if (assignment != null) {
val name = assignment.first
if (shouldConsiderUnused(name)) {
ctx.replaceMe(x.arg2)
ctx.replaceMe(accept(x.arg2).apply { synthetic = true })
}
}
super.endVisit(x, ctx)
......
......@@ -42,4 +42,6 @@ class TemporaryVariableEliminationTest : BasicOptimizerTest("temporary-variable"
@Test fun transitiveNotConsideredTrivial() = box()
@Test fun assignmentToNonLocal() = box()
@Test fun removeUnusedAndSubstitute() = box()
}
\ No newline at end of file
var log = "";
function test(a) {
var $tmp1;
log += $tmp1 = 1;
return a;
}
function box() {
if (test(3) != 3) return "fail1";
if (log != 1) return "fail2";
return "OK"
}
\ No newline at end of file
var log = "";
function test(a) {
var $tmp1;
log += $tmp1 = 1;
var $tmp2 = $tmp1;
var $tmp3;
var $tmp4 = $tmp2;
return a;
}
function box() {
if (test(3) != 3) return "fail1";
if (log != 1) return "fail2";
return "OK"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册