Fix JS source maps for companion objects of enum

This commit is contained in:
Alexey Andreev
2017-05-15 16:09:58 +03:00
parent c9545f291a
commit 5bc6c07f9e
3 changed files with 17 additions and 1 deletions
@@ -102,6 +102,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
doTest(fileName);
}
@TestMetadata("enumCompanionObject.kt")
public void testEnumCompanionObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/enumCompanionObject.kt");
doTest(fileName);
}
@TestMetadata("expressionAsFunctionBody.kt")
public void testExpressionAsFunctionBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/expressionAsFunctionBody.kt");
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType
import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.CommonSupertypes.topologicallySortSuperclassesAndRecordAllInstances
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeConstructor
@@ -89,7 +90,7 @@ class ClassTranslator private constructor(
val companionDescriptor = descriptor.companionObjectDescriptor
if (enumInitFunction != null && companionDescriptor != null) {
val initInvocation = JsInvocation(JsAstUtils.pureFqn(context().getNameForObjectInstance(companionDescriptor), null))
enumInitFunction.body.statements += JsAstUtils.asSyntheticStatement(initInvocation)
enumInitFunction.body.statements += JsAstUtils.asSyntheticStatement(initInvocation.source(companionDescriptor.source.getPsi()))
}
translatePrimaryConstructor(constructorFunction, context, delegationTranslator)
@@ -0,0 +1,9 @@
enum class Foo {
A;
companion object {
val a = A
}
}
// LINES: 1 1 1 1 2 4 * 2 2 4 5 * 4 4 4 4 * 1 * 1 1 1 1