Keep JS AST source information after refreshing local names

This commit is contained in:
Alexey Andreev
2017-05-05 23:16:22 +03:00
parent ad89e5906f
commit 89e3fb7592
4 changed files with 22 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +22,14 @@ class NameReplacingVisitor(private val replaceMap: Map<JsName, JsExpression>) :
override fun endVisit(x: JsNameRef, ctx: JsContext<JsNode>) {
val replacement = replaceMap[x.name] ?: return
ctx.replaceMe(replacement.deepCopy())
ctx.replaceMe(replacement.deepCopy().source(x.source))
}
override fun endVisit(x: JsVars.JsVar, ctx: JsContext<JsNode>) {
val replacement = replaceMap[x.name]
if (replacement is HasName) {
val replacementVar = JsVars.JsVar(replacement.name, x.initExpression)
ctx.replaceMe(replacementVar)
ctx.replaceMe(replacementVar.source(x.source))
}
}
@@ -60,6 +60,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
doTest(fileName);
}
@TestMetadata("inlineLocalVarsRef.kt")
public void testInlineLocalVarsRef() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlineLocalVarsRef.kt");
doTest(fileName);
}
@TestMetadata("inlineReturn.kt")
public void testInlineReturn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlineReturn.kt");
@@ -0,0 +1,12 @@
inline fun foo(x: Int) {
val y = x > 23
if (y) {
println("foo")
}
}
fun bar() {
foo(42)
}
// LINES: 2 3 4 * 2 9 2 3 4
+1 -1
View File
@@ -21,4 +21,4 @@ fun bar(x: Int) {
println("%")
}
// LINES: 2 3 4 7 9 10 11 14 16 * 20 * 2 3 3 7 9 10 10 14 16 20 21
// LINES: 2 3 4 7 9 10 11 14 16 * 20 * 2 3 4 3 7 9 10 11 10 14 16 20 21