Copy location info when copying JS AST subtrees
This is necessary to preserve source information of a function's body after inlining.
This commit is contained in:
@@ -28,8 +28,12 @@ abstract class AbstractNode extends HasMetadata implements JsNode {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
protected <T extends HasMetadata> T withMetadataFrom(T other) {
|
||||
protected <T extends HasMetadata & JsNode> T withMetadataFrom(T other) {
|
||||
this.copyMetadataFrom(other);
|
||||
Object otherSource = other.getSource();
|
||||
if (otherSource != null) {
|
||||
source(otherSource);
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,18 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/lineNumbers"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlining.kt")
|
||||
public void testInlining() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlining.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inliningWithLambda.kt")
|
||||
public void testInliningWithLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inliningWithLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/simple.kt");
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
fun box() {
|
||||
println("1")
|
||||
bar()
|
||||
println("2")
|
||||
bar()
|
||||
println("3")
|
||||
}
|
||||
|
||||
inline fun bar() {
|
||||
println("bar1")
|
||||
println("bar2")
|
||||
}
|
||||
|
||||
// LINES: 2 10 11 4 10 11 6 10 11
|
||||
@@ -0,0 +1,19 @@
|
||||
fun box() {
|
||||
println("1")
|
||||
foo {
|
||||
println("x")
|
||||
}
|
||||
println("2")
|
||||
foo {
|
||||
println("y")
|
||||
}
|
||||
println("3")
|
||||
}
|
||||
|
||||
inline fun foo(f: () -> Unit) {
|
||||
println("before")
|
||||
f()
|
||||
println("after")
|
||||
}
|
||||
|
||||
// LINES: 2 14 4 16 6 14 8 16 10 14 15 16
|
||||
Reference in New Issue
Block a user