JS/Inlining: fix broken evaluation order after applying temporary variable elimination
This commit is contained in:
+5
-4
@@ -264,6 +264,7 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
namesToSubstitute += name
|
namesToSubstitute += name
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
lastAssignedVars.clear()
|
||||||
lastAssignedVars += Pair(name, x)
|
lastAssignedVars += Pair(name, x)
|
||||||
sideEffectOccurred = false
|
sideEffectOccurred = false
|
||||||
}
|
}
|
||||||
@@ -385,6 +386,7 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
namesToSubstitute += name
|
namesToSubstitute += name
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
lastAssignedVars.clear()
|
||||||
lastAssignedVars += Pair(name, v)
|
lastAssignedVars += Pair(name, v)
|
||||||
sideEffectOccurred = false
|
sideEffectOccurred = false
|
||||||
}
|
}
|
||||||
@@ -453,7 +455,7 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
}
|
}
|
||||||
val initExpression = v.initExpression
|
val initExpression = v.initExpression
|
||||||
if (initExpression != null) {
|
if (initExpression != null) {
|
||||||
ctx.addPrevious(JsExpressionStatement(initExpression).apply {
|
ctx.addPrevious(JsExpressionStatement(initExpression).run {
|
||||||
synthetic = true
|
synthetic = true
|
||||||
accept(this)
|
accept(this)
|
||||||
})
|
})
|
||||||
@@ -485,11 +487,10 @@ internal class TemporaryVariableElimination(private val root: JsStatement) {
|
|||||||
val (name, value) = assignment
|
val (name, value) = assignment
|
||||||
if (name in variablesToRemove) {
|
if (name in variablesToRemove) {
|
||||||
hasChanges = true
|
hasChanges = true
|
||||||
JsExpressionStatement(value).apply {
|
ctx.replaceMe(JsExpressionStatement(value).run {
|
||||||
synthetic = true
|
synthetic = true
|
||||||
accept(this)
|
accept(this)
|
||||||
ctx.replaceMe(this)
|
})
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -20,9 +20,8 @@ function test2() {
|
|||||||
init();
|
init();
|
||||||
|
|
||||||
var $tmp2 = foo(2);
|
var $tmp2 = foo(2);
|
||||||
var $tmp1 = foo(1);
|
|
||||||
|
|
||||||
return foo($tmp1 + $tmp2);
|
return foo(foo(1) + $tmp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test3() {
|
function test3() {
|
||||||
|
|||||||
Reference in New Issue
Block a user