JS/Inlining: clarify why it's necessary to remove expression statements like a[b]

This commit is contained in:
Alexey Andreev
2016-06-01 13:46:25 +03:00
parent 57ac23a606
commit d829bf4914
@@ -126,6 +126,12 @@ class IneffectiveStatementElimination(private val root: JsFunction) {
}
}
// Although it can be suspicious case, sometimes it really helps.
// Consider the following case: `Kotlin.modules['foo'].bar()`, where `foo` is inlineable. Expression decomposer produces
// var $tmp = Kotlin.modules['foo'];
// $tmp.bar();
// Then, inlined body of `bar` never uses `$tmp`, therefore we can eliminate it, so `Kotlin.modules['foo']` remains.
// It's good to eliminate such useless expression.
is JsArrayAccess -> {
if (!expression.sideEffects) {
replace(expression.arrayExpression) + replace(expression.indexExpression)