Fix JS source maps for "is" and "in" clauses in when expression

This commit is contained in:
Alexey Andreev
2017-05-10 20:44:45 +03:00
parent 9692c02f6e
commit 6ad991adfb
5 changed files with 47 additions and 3 deletions
@@ -155,4 +155,16 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/valParameter.kt");
doTest(fileName);
}
@TestMetadata("whenIn.kt")
public void testWhenIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenIn.kt");
doTest(fileName);
}
@TestMetadata("whenIs.kt")
public void testWhenIs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenIs.kt");
doTest(fileName);
}
}
@@ -190,7 +190,7 @@ public final class WhenTranslator extends AbstractTranslator {
assert expressionToMatchNonTranslated != null : "expressionToMatch != null => expressionToMatchNonTranslated != null: " +
PsiUtilsKt.getTextWithLocation(conditionIsPattern);
JsExpression result = Translation.patternTranslator(context).translateIsCheck(expressionToMatch, typeReference);
return result != null ? result : new JsBooleanLiteral(true);
return (result != null ? result : new JsBooleanLiteral(true)).source(conditionIsPattern);
}
@NotNull
@@ -226,7 +226,7 @@ public final class WhenTranslator extends AbstractTranslator {
TranslationContext callContext = context.innerContextWithAliasesForExpressions(subjectAliases);
boolean negated = condition.getOperationReference().getReferencedNameElementType() == KtTokens.NOT_IN;
return new InOperationTranslator(callContext, expressionToMatch, condition.getRangeExpression(), condition.getOperationReference(),
negated).translate();
negated).translate().source(condition);
}
@Nullable
@@ -64,7 +64,7 @@ private class TypeCheckRewritingVisitor : JsVisitorWithContextImpl() {
val replacement = getReplacement(callee, calleeArguments, argument)
if (replacement != null) {
ctx.replaceMe(accept(replacement))
ctx.replaceMe(accept(replacement).source(x.source))
return false
}
}
+16
View File
@@ -0,0 +1,16 @@
fun box() {
when (foo()) {
in 2..5 ->
println("A")
!in 100..200 ->
println("B")
in bar() ->
println("C")
}
}
fun foo(): Int = 23
fun bar(): IntRange = 1000..2000
// LINES: 2 2 3 4 5 6 7 8 12 14
+16
View File
@@ -0,0 +1,16 @@
fun box() {
when (A()) {
is A ->
println("A")
is B ->
println("B")
else ->
println("other")
}
}
open class A
open class B : A()
// LINES: 2 2 3 4 5 6 8 * 14