Fix JS source maps for while/do..while statements
This commit is contained in:
@@ -66,6 +66,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("doWhileWithComplexCondition.kt")
|
||||||
|
public void testDoWhileWithComplexCondition() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/doWhileWithComplexCondition.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("for.kt")
|
@TestMetadata("for.kt")
|
||||||
public void testFor() throws Exception {
|
public void testFor() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/for.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/for.kt");
|
||||||
@@ -185,4 +191,10 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenIs.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whenIs.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whileWithComplexCondition.kt")
|
||||||
|
public void testWhileWithComplexCondition() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/whileWithComplexCondition.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class LineCollector : RecursiveJsVisitor() {
|
|||||||
|
|
||||||
override fun visitIf(x: JsIf) {
|
override fun visitIf(x: JsIf) {
|
||||||
withStatement(x) {
|
withStatement(x) {
|
||||||
|
handleNodeLocation(x)
|
||||||
x.ifExpression.accept(this)
|
x.ifExpression.accept(this)
|
||||||
}
|
}
|
||||||
x.thenStatement.accept(this)
|
x.thenStatement.accept(this)
|
||||||
@@ -68,6 +69,7 @@ class LineCollector : RecursiveJsVisitor() {
|
|||||||
|
|
||||||
override fun visitWhile(x: JsWhile) {
|
override fun visitWhile(x: JsWhile) {
|
||||||
withStatement(x) {
|
withStatement(x) {
|
||||||
|
handleNodeLocation(x)
|
||||||
x.condition.accept(this)
|
x.condition.accept(this)
|
||||||
}
|
}
|
||||||
x.body.accept(this)
|
x.body.accept(this)
|
||||||
@@ -75,6 +77,7 @@ class LineCollector : RecursiveJsVisitor() {
|
|||||||
|
|
||||||
override fun visitDoWhile(x: JsDoWhile) {
|
override fun visitDoWhile(x: JsDoWhile) {
|
||||||
withStatement(x) {
|
withStatement(x) {
|
||||||
|
handleNodeLocation(x)
|
||||||
x.condition.accept(this)
|
x.condition.accept(this)
|
||||||
}
|
}
|
||||||
x.body.accept(this)
|
x.body.accept(this)
|
||||||
|
|||||||
@@ -51,17 +51,18 @@ fun createWhile(doWhile: Boolean, expression: KtWhileExpressionBase, context: Tr
|
|||||||
JsEmpty
|
JsEmpty
|
||||||
|
|
||||||
if (!conditionBlock.isEmpty) {
|
if (!conditionBlock.isEmpty) {
|
||||||
val breakIfConditionIsFalseStatement = JsIf(not(jsCondition), JsBreak())
|
val breakIfConditionIsFalseStatement = JsIf(not(jsCondition), JsBreak().apply { source = expression })
|
||||||
|
.apply { source = expression }
|
||||||
val bodyBlock = convertToBlock(bodyStatement)
|
val bodyBlock = convertToBlock(bodyStatement)
|
||||||
jsCondition = JsBooleanLiteral(true)
|
jsCondition = JsBooleanLiteral(true)
|
||||||
|
|
||||||
if (doWhile) {
|
if (doWhile) {
|
||||||
// translate to: tmpSecondRun = false;
|
// translate to: tmpSecondRun = false;
|
||||||
// do { if(tmpSecondRun) { <expr> if(!tmpExprVar) break; } else tmpSecondRun=true; <body> } while(true)
|
// do { if(tmpSecondRun) { <expr> if(!tmpExprVar) break; } else tmpSecondRun=true; <body> } while(true)
|
||||||
val secondRun = context.defineTemporary(JsBooleanLiteral(false))
|
val secondRun = context.defineTemporary(JsBooleanLiteral(false).source(expression))
|
||||||
conditionBlock.statements.add(breakIfConditionIsFalseStatement)
|
conditionBlock.statements.add(breakIfConditionIsFalseStatement)
|
||||||
val ifStatement = JsIf(secondRun, conditionBlock, assignment(secondRun, JsBooleanLiteral(true)).makeStmt())
|
val ifStatement = JsIf(secondRun, conditionBlock, assignment(secondRun, JsBooleanLiteral(true)).source(expression).makeStmt())
|
||||||
bodyBlock.statements.add(0, ifStatement)
|
bodyBlock.statements.add(0, ifStatement.apply { source = expression })
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
conditionBlock.statements.add(breakIfConditionIsFalseStatement)
|
conditionBlock.statements.add(breakIfConditionIsFalseStatement)
|
||||||
@@ -74,7 +75,7 @@ fun createWhile(doWhile: Boolean, expression: KtWhileExpressionBase, context: Tr
|
|||||||
val result = if (doWhile) JsDoWhile() else JsWhile()
|
val result = if (doWhile) JsDoWhile() else JsWhile()
|
||||||
result.condition = jsCondition
|
result.condition = jsCondition
|
||||||
result.body = bodyStatement
|
result.body = bodyStatement
|
||||||
return result.source(expression)!!
|
return result.source(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun translateForExpression(expression: KtForExpression, context: TranslationContext): JsStatement {
|
fun translateForExpression(expression: KtForExpression, context: TranslationContext): JsStatement {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
fun box() {
|
||||||
|
var i = 0
|
||||||
|
do {
|
||||||
|
println("body: $i")
|
||||||
|
}
|
||||||
|
while(
|
||||||
|
try {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
println("finally: $i")
|
||||||
|
} < i
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LINES: 8 3 2 3 3 3 8 11 3 7 12 3 3 4
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
fun box() {
|
||||||
|
var i = 0
|
||||||
|
while(
|
||||||
|
try {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
println("finally: $i")
|
||||||
|
} < i
|
||||||
|
) {
|
||||||
|
println("body: $i")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LINES: 5 2 3 5 8 3 4 9 3 11
|
||||||
Reference in New Issue
Block a user