Fix JS source maps for properties without initializer

This commit is contained in:
Alexey Andreev
2017-05-15 16:01:08 +03:00
parent fdf098d65c
commit c9545f291a
3 changed files with 20 additions and 2 deletions
@@ -192,6 +192,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest {
doTest(fileName);
}
@TestMetadata("propertyWithoutInitializer.kt")
public void testPropertyWithoutInitializer() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/propertyWithoutInitializer.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/simple.kt");
@@ -60,12 +60,12 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
else if (Boolean.TRUE.equals(context.bindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, descriptor))) {
JsNameRef backingFieldReference = TranslationUtils.backingFieldReference(context, descriptor);
JsExpression defaultValue = generateDefaultValue(descriptor, backingFieldReference);
statement = TranslationUtils.assignmentToBackingField(context, descriptor, defaultValue).makeStmt();
statement = TranslationUtils.assignmentToBackingField(context, descriptor, defaultValue).source(property).makeStmt();
}
else if (JsDescriptorUtils.isSimpleFinalProperty(descriptor)) {
JsNameRef propRef = new JsNameRef(context.getNameForDescriptor(descriptor), new JsThisRef());
JsExpression defaultValue = generateDefaultValue(descriptor, propRef);
statement = JsAstUtils.assignment(propRef, defaultValue).makeStmt();
statement = JsAstUtils.assignment(propRef, defaultValue).source(property).makeStmt();
}
if (statement != null && !JsAstUtils.isEmptyStatement(statement)) {
@@ -0,0 +1,12 @@
open class A {
val x: Int
open val y: Int
init {
x = 23
y = 42
}
}
// LINES: 2 4 7 8 4