Skip to content

Commit 27a44f3

Browse files
Alexey AndreevAlexey Andreev
Alexey Andreev
authored and
Alexey Andreev
committed
Fix JS source maps for complex enum entry
1 parent b70c52e commit 27a44f3

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

js/js.tests/test/org/jetbrains/kotlin/js/test/JsLineNumberTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ public void testEnumCompanionObject() throws Exception {
120120
doTest(fileName);
121121
}
122122

123+
@TestMetadata("enumObject.kt")
124+
public void testEnumObject() throws Exception {
125+
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/enumObject.kt");
126+
doTest(fileName);
127+
}
128+
123129
@TestMetadata("expressionAsFunctionBody.kt")
124130
public void testExpressionAsFunctionBody() throws Exception {
125131
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/expressionAsFunctionBody.kt");

js/js.translator/src/org/jetbrains/kotlin/js/translate/initializer/ClassInitializerTranslator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ else if (hasAncestorClass(bindingContext(), classDeclaration)) {
197197

198198
if (classDeclaration instanceof KtEnumEntry) {
199199
JsExpression expression = CallTranslator.translate(context(), superCall, null);
200+
expression.setSource(classDeclaration);
200201

201202
JsExpression fixedInvocation = AstUtilsKt.toInvocationWith(
202203
expression, getAdditionalArgumentsForEnumConstructor(), 0, new JsThisRef());

js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/astUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ fun JsExpression.toInvocationWith(
6969
is JsNew -> {
7070
qualifier = Namer.getFunctionCallRef(constructorExpression)
7171
// `new A(a, b, c)` -> `A.call($this, a, b, c)`
72-
return JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments)
72+
return JsInvocation(qualifier, listOf(thisExpr) + leadingExtraArgs + arguments).source(source)
7373
}
7474
is JsInvocation -> {
7575
qualifier = getQualifier()
7676
// `A(a, b, c)` -> `A(a, b, c, $this)`
77-
return JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr)
77+
return JsInvocation(qualifier, leadingExtraArgs + padArguments(arguments) + thisExpr).source(source)
7878
}
7979
else -> throw IllegalStateException("Unexpected node type: " + this::class.java)
8080
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
enum class E {
2+
X,
3+
4+
Y {
5+
fun foo() = 23
6+
},
7+
8+
Z() {
9+
fun bar() = 42
10+
}
11+
}
12+
13+
// 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

0 commit comments

Comments
 (0)