JS: fix translation of extension properties
This commit is contained in:
@@ -3269,12 +3269,24 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/extensionProperty"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/extensionProperty"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("externalExtensionProperty.kt")
|
||||||
|
public void testExternalExtensionProperty() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/externalExtensionProperty.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inClass.kt")
|
@TestMetadata("inClass.kt")
|
||||||
public void testInClass() throws Exception {
|
public void testInClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/inClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/inClass.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateExtensionProperty.kt")
|
||||||
|
public void testPrivateExtensionProperty() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/privateExtensionProperty.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("propertyWithGetterAndSetter.kt")
|
@TestMetadata("propertyWithGetterAndSetter.kt")
|
||||||
public void testPropertyWithGetterAndSetter() throws Exception {
|
public void testPropertyWithGetterAndSetter() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/propertyWithGetterAndSetter.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/extensionProperty/propertyWithGetterAndSetter.kt");
|
||||||
|
|||||||
-9
@@ -95,12 +95,3 @@ val FunctionCallInfo.functionName: JsName
|
|||||||
get() = context.getNameForDescriptor(callableDescriptor)
|
get() = context.getNameForDescriptor(callableDescriptor)
|
||||||
|
|
||||||
fun FunctionCallInfo.hasSpreadOperator(): Boolean = argumentsInfo.hasSpreadOperator
|
fun FunctionCallInfo.hasSpreadOperator(): Boolean = argumentsInfo.hasSpreadOperator
|
||||||
|
|
||||||
fun TranslationContext.aliasOrValue(callableDescriptor: CallableDescriptor, value: (CallableDescriptor) -> JsExpression): JsExpression {
|
|
||||||
val alias = getAliasForDescriptor(callableDescriptor)
|
|
||||||
if (alias != null) {
|
|
||||||
return alias
|
|
||||||
} else {
|
|
||||||
return value(callableDescriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+3
-3
@@ -54,7 +54,7 @@ object NativeVariableAccessCase : VariableAccessCase() {
|
|||||||
override fun VariableAccessInfo.noReceivers(): JsExpression {
|
override fun VariableAccessInfo.noReceivers(): JsExpression {
|
||||||
val descriptor = resolvedCall.resultingDescriptor
|
val descriptor = resolvedCall.resultingDescriptor
|
||||||
return if (descriptor is PropertyDescriptor && TranslationUtils.shouldAccessViaFunctions(descriptor)) {
|
return if (descriptor is PropertyDescriptor && TranslationUtils.shouldAccessViaFunctions(descriptor)) {
|
||||||
val methodRef = context.aliasOrValue(callableDescriptor) { context.getQualifiedReference(getAccessDescriptorIfNeeded()) }
|
val methodRef = ReferenceTranslator.translateAsValueReference(getAccessDescriptorIfNeeded(), context)
|
||||||
JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -77,7 +77,7 @@ object DefaultVariableAccessCase : VariableAccessCase() {
|
|||||||
|
|
||||||
val descriptor = resolvedCall.resultingDescriptor
|
val descriptor = resolvedCall.resultingDescriptor
|
||||||
if (descriptor is PropertyDescriptor && TranslationUtils.shouldAccessViaFunctions(descriptor)) {
|
if (descriptor is PropertyDescriptor && TranslationUtils.shouldAccessViaFunctions(descriptor)) {
|
||||||
val methodRef = context.aliasOrValue(callableDescriptor) { context.getQualifiedReference(getAccessDescriptorIfNeeded()) }
|
val methodRef = ReferenceTranslator.translateAsValueReference(getAccessDescriptorIfNeeded(), context)
|
||||||
return JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
return JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ object DefaultVariableAccessCase : VariableAccessCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun VariableAccessInfo.extensionReceiver(): JsExpression {
|
override fun VariableAccessInfo.extensionReceiver(): JsExpression {
|
||||||
val functionRef = context.aliasOrValue(callableDescriptor) { context.getQualifiedReference(getAccessDescriptorIfNeeded()) }
|
val functionRef = ReferenceTranslator.translateAsValueReference(getAccessDescriptorIfNeeded(), context)
|
||||||
return JsInvocation(functionRef, extensionReceiver!!, *additionalArguments.toTypedArray())
|
return JsInvocation(functionRef, extensionReceiver!!, *additionalArguments.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// MODULE: lib
|
||||||
|
// FILE: lib.kt
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun ok() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
val A.foo: String
|
||||||
|
get() = ok()
|
||||||
|
|
||||||
|
// MODULE: main(lib)
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun box() = A().foo
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class A {
|
||||||
|
fun result() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
private val A.foo: String
|
||||||
|
get() = result()
|
||||||
|
|
||||||
|
fun box() = A().foo
|
||||||
Reference in New Issue
Block a user