Fix JS source maps for when expression

This commit is contained in:
Alexey Andreev
2017-06-23 12:19:48 +03:00
parent d613124cb1
commit be7f3a787c
6 changed files with 33 additions and 3 deletions
@@ -258,6 +258,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
doTest(fileName);
}
@TestMetadata("whenEntryWithMultipleConditions.kt")
public void testWhenEntryWithMultipleConditions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenEntryWithMultipleConditions.kt");
doTest(fileName);
}
@TestMetadata("whenIn.kt")
public void testWhenIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenIn.kt");
@@ -74,6 +74,7 @@ public final class WhenTranslator extends AbstractTranslator {
if (resultIf == null) {
currentIf = JsAstUtils.newJsIf(translateConditions(entry, context()), statement);
currentIf.setSource(entry);
resultIf = currentIf;
}
else {
@@ -83,6 +84,7 @@ public final class WhenTranslator extends AbstractTranslator {
}
JsBlock conditionsBlock = new JsBlock();
JsIf nextIf = JsAstUtils.newJsIf(translateConditions(entry, context().innerBlock(conditionsBlock)), statement);
nextIf.setSource(entry);
JsStatement statementToAdd = JsAstUtils.mergeStatementInBlockIfNeeded(nextIf, conditionsBlock);
currentIf.setElseStatement(statementToAdd);
currentIf = nextIf;
@@ -147,6 +149,7 @@ public final class WhenTranslator extends AbstractTranslator {
JsNameRef result = (JsNameRef) rightExpression;
JsIf ifStatement = JsAstUtils.newJsIf(leftExpression, JsAstUtils.assignment(result, new JsBooleanLiteral(true)).makeStmt(),
rightContext.getCurrentBlock());
ifStatement.setSource(condition);
context.addStatementToCurrentBlock(ifStatement);
return result;
}
@@ -11,4 +11,4 @@ fun baz() = 1
fun bar() = 2
// LINES: 8 3 3 2 2 3 4 4 4 5 5 2 8 8 10 10 10 12 12 12
// LINES: 8 3 3 2 2 4 3 4 4 4 5 5 2 8 8 10 10 10 12 12 12
@@ -0,0 +1,21 @@
fun box(x: Int) {
println(
when (
x
) {
1,
2,
3 ->
55
4,
5 ->
66
else ->
77
}
)
}
// LINES: 19 4 4 3 6 4 6 4 7 4 8 9 9 11 4 11 4 12 13 13 16 16 2
+1 -1
View File
@@ -13,4 +13,4 @@ fun foo(): Int = 23
fun bar(): IntRange = 1000..2000
// LINES: 10 2 2 2 2 3 4 4 5 6 6 7 8 8 12 12 12 14 14 14
// LINES: 10 2 2 2 2 3 3 4 4 5 5 6 6 7 7 8 8 12 12 12 14 14 14
+1 -1
View File
@@ -13,4 +13,4 @@ open class A
open class B : A()
// LINES: 10 2 2 2 2 3 4 4 5 6 6 8 8 12 * 14 14
// LINES: 10 2 2 2 2 3 3 4 4 5 5 6 6 8 8 12 * 14 14