Fix JS source maps for complex enum entry

This commit is contained in:
Alexey Andreev
2017-05-15 18:57:51 +03:00
parent b70c52e41f
commit 27a44f3282
4 changed files with 22 additions and 2 deletions
@@ -120,6 +120,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
doTest(fileName);
}
@TestMetadata("enumObject.kt")
public void testEnumObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/enumObject.kt");
doTest(fileName);
}
@TestMetadata("expressionAsFunctionBody.kt")
public void testExpressionAsFunctionBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/expressionAsFunctionBody.kt");
@@ -197,6 +197,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
if (classDeclaration instanceof KtEnumEntry) {
JsExpression expression = CallTranslator.translate(context(), superCall, null);
expression.setSource(classDeclaration);
JsExpression fixedInvocation = AstUtilsKt.toInvocationWith(
expression, getAdditionalArgumentsForEnumConstructor(), 0, new JsThisRef());
@@ -69,12 +69,12 @@ fun JsExpression.toInvocationWith(
is JsNew -> {
qualifier = Namer.getFunctionCallRef(constructorExpression)
// `new A(a, b, c)` -> `A.call($this, a, b, c)`
return JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments)
return JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments).source(source)
}
is JsInvocation -> {
qualifier = getQualifier()
// `A(a, b, c)` -> `A(a, b, c, $this)`
return JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr)
return JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr).source(source)
}
else -> throw IllegalStateException("Unexpected node type: " + this::class.java)
}
+13
View File
@@ -0,0 +1,13 @@
enum class E {
X,
Y {
fun foo() = 23
},
Z() {
fun bar() = 42
}
}
// LINES: 1 1 1 1 2 4 8 * 2 2 4 4 5 * 4 4 8 8 9 * 8 8 * 1 * 1 1 1 1 1 1