Fix JS source maps for initialization of variables captured by class
This commit is contained in:
@@ -54,6 +54,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("classCapturingLocals.kt")
|
||||
public void testClassCapturingLocals() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/classCapturingLocals.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closure.kt")
|
||||
public void testClosure() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/closure.kt");
|
||||
@@ -114,6 +120,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/innerClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithClosure.kt")
|
||||
public void testLambdaWithClosure() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/lambdaWithClosure.kt");
|
||||
|
||||
+1
-1
@@ -380,7 +380,7 @@ class ClassTranslator private constructor(
|
||||
|
||||
function.parameters.add(i, JsParameter(name))
|
||||
if (fieldName != null && constructor == primaryConstructor) {
|
||||
val source = (capturedVar as? DeclarationDescriptorWithSource)?.source
|
||||
val source = (constructor.descriptor as? DeclarationDescriptorWithSource)?.source
|
||||
additionalStatements += JsAstUtils.defineSimpleProperty(fieldName.ident, name.makeRef(), source)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
initFunction.getParameters().add(0, new JsParameter(outerName));
|
||||
|
||||
JsExpression paramRef = pureFqn(outerName, null);
|
||||
JsExpression assignment = JsAstUtils.assignment(pureFqn(outerName, new JsThisRef()), paramRef);
|
||||
JsExpression assignment = JsAstUtils.assignment(pureFqn(outerName, new JsThisRef()), paramRef).source(classDeclaration);
|
||||
initFunction.getBody().getStatements().add(new JsExpressionStatement(assignment));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class A
|
||||
|
||||
fun A.foo() {
|
||||
val x = baz()
|
||||
class B {
|
||||
fun bar() {
|
||||
println(this@foo)
|
||||
println("A.B.bar: $x")
|
||||
}
|
||||
}
|
||||
println("A.foo: $x")
|
||||
B().bar()
|
||||
}
|
||||
|
||||
fun baz() = 23
|
||||
|
||||
// LINES: 5 5 7 8 * 4 11 12 15
|
||||
@@ -0,0 +1,9 @@
|
||||
class A(val x: Int) {
|
||||
inner class B {
|
||||
fun foo() {
|
||||
println(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LINES: 1 2 4
|
||||
Reference in New Issue
Block a user