Fix generation of JS source maps for class properties
This commit is contained in:
@@ -48,6 +48,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("delegateMemberVal.kt")
|
||||||
|
public void testDelegateMemberVal() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/delegateMemberVal.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlining.kt")
|
@TestMetadata("inlining.kt")
|
||||||
public void testInlining() throws Exception {
|
public void testInlining() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlining.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlining.kt");
|
||||||
@@ -95,4 +101,10 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/syntheticCodeInEnums.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/syntheticCodeInEnums.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("valParameter.kt")
|
||||||
|
public void testValParameter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/valParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -380,7 +380,8 @@ class ClassTranslator private constructor(
|
|||||||
|
|
||||||
function.parameters.add(i, JsParameter(name))
|
function.parameters.add(i, JsParameter(name))
|
||||||
if (fieldName != null && constructor == primaryConstructor) {
|
if (fieldName != null && constructor == primaryConstructor) {
|
||||||
additionalStatements += JsAstUtils.defineSimpleProperty(fieldName.ident, name.makeRef())
|
val source = (capturedVar as? DeclarationDescriptorWithSource)?.source
|
||||||
|
additionalStatements += JsAstUtils.defineSimpleProperty(fieldName.ident, name.makeRef(), source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
|||||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||||
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.js.translate.utils.TranslationUtils.assignmentToBackingField;
|
import static org.jetbrains.kotlin.js.translate.utils.TranslationUtils.assignmentToBackingField;
|
||||||
|
|
||||||
@@ -37,7 +38,9 @@ public final class InitializerUtils {
|
|||||||
@NotNull PropertyDescriptor descriptor,
|
@NotNull PropertyDescriptor descriptor,
|
||||||
@NotNull JsExpression value
|
@NotNull JsExpression value
|
||||||
) {
|
) {
|
||||||
return assignmentToBackingField(context, descriptor, value).makeStmt();
|
JsExpression assignment = assignmentToBackingField(context, descriptor, value);
|
||||||
|
assignment.setSource(KotlinSourceElementKt.getPsi(descriptor.getSource()));
|
||||||
|
return assignment.makeStmt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -46,6 +49,6 @@ public final class InitializerUtils {
|
|||||||
@NotNull JsExpression value
|
@NotNull JsExpression value
|
||||||
) {
|
) {
|
||||||
String name = descriptor.getName().asString();
|
String name = descriptor.getName().asString();
|
||||||
return JsAstUtils.defineSimpleProperty(Namer.getDelegateName(name), value);
|
return JsAstUtils.defineSimpleProperty(Namer.getDelegateName(name), value, descriptor.getSource());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ import com.intellij.util.SmartList;
|
|||||||
import kotlin.Pair;
|
import kotlin.Pair;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||||
import org.jetbrains.kotlin.js.backend.ast.*;
|
import org.jetbrains.kotlin.js.backend.ast.*;
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.MetadataProperties;
|
import org.jetbrains.kotlin.js.backend.ast.metadata.MetadataProperties;
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.SideEffectKind;
|
import org.jetbrains.kotlin.js.backend.ast.metadata.SideEffectKind;
|
||||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||||
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||||
|
|
||||||
@@ -466,8 +468,12 @@ public final class JsAstUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsStatement defineSimpleProperty(@NotNull String name, @NotNull JsExpression value) {
|
public static JsStatement defineSimpleProperty(@NotNull String name, @NotNull JsExpression value, @Nullable SourceElement source) {
|
||||||
return assignment(new JsNameRef(name, new JsThisRef()), value).makeStmt();
|
JsExpression assignment = assignment(new JsNameRef(name, new JsThisRef()), value);
|
||||||
|
if (source != null) {
|
||||||
|
assignment.setSource(KotlinSourceElementKt.getPsi(source));
|
||||||
|
}
|
||||||
|
return assignment.makeStmt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class A {
|
||||||
|
val z by
|
||||||
|
lazy { 23 }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
println(A().z)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LINES: 2 3 * 3 * 7
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class A(
|
||||||
|
val x: Int,
|
||||||
|
val y: String
|
||||||
|
)
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
A(23, "foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
// LINES: 2 3 * 7
|
||||||
Reference in New Issue
Block a user