JS: when both clauses of if become empty during optimization, remove if entirely. Make condition and then clause of JsIf non-nullable. Fix #KT-13912

This commit is contained in:
Alexey Andreev
2016-09-27 16:34:50 +03:00
committed by Alexey Andreev
parent b5358122e2
commit d2fdc7ffc0
11 changed files with 134 additions and 24 deletions
@@ -108,6 +108,11 @@ abstract class BasicOptimizerTest(private var basePath: String) {
}
super.visitIf(x)
}
override fun visitLabel(x: JsLabel) {
x.synthetic = isSyntheticId(x.name.ident)
super.visitLabel(x)
}
}.accept(stmt)
}
}
@@ -119,7 +124,6 @@ abstract class BasicOptimizerTest(private var basePath: String) {
private fun isSyntheticId(id: String) = id.startsWith("$")
private fun astToString(ast: List<JsStatement>): String {
val output = TextOutputImpl()
val visitor = JsSourceGenerationVisitor(output, null)
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.js.test.optimizer
import org.junit.Test
class RedundantLabelRemovalTest : BasicOptimizerTest("redundant-label-removal") {
@Test fun emptyIfConditionPreserved() = box()
@Test fun ifWithEmptyThenAndNoElse() = box()
}