From d829bf49148130502c77fb3120957912b41d9f02 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 1 Jun 2016 13:46:25 +0300 Subject: [PATCH] JS/Inlining: clarify why it's necessary to remove expression statements like a[b] --- .../js/inline/clean/IneffectiveStatementElimination.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/clean/IneffectiveStatementElimination.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/clean/IneffectiveStatementElimination.kt index 742a73212e7..df9c33b6998 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/clean/IneffectiveStatementElimination.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/clean/IneffectiveStatementElimination.kt @@ -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)