JS: fix translation of extension properties
This commit is contained in:
-9
@@ -95,12 +95,3 @@ val FunctionCallInfo.functionName: JsName
|
||||
get() = context.getNameForDescriptor(callableDescriptor)
|
||||
|
||||
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 {
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
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())
|
||||
}
|
||||
else {
|
||||
@@ -77,7 +77,7 @@ object DefaultVariableAccessCase : VariableAccessCase() {
|
||||
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
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())
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ object DefaultVariableAccessCase : VariableAccessCase() {
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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