[JS IR BE] Fix codegen for external companion objects
This commit is contained in:
+2
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.utils.getJsQualifier
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.util.isClass
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.util.transformFlat
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -66,7 +67,7 @@ fun moveBodilessDeclarationsToSeparatePlace(context: JsIrBackendContext, module:
|
||||
externalClasses.flatMap { collectExternalClasses(it, true) }
|
||||
|
||||
return if (includeCurrentLevel)
|
||||
externalClasses + nestedExternalClasses
|
||||
externalClasses.filter { it.isClass } + nestedExternalClasses
|
||||
else
|
||||
nestedExternalClasses
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class DynamicCallsTransformer(private val context: JsIrBackendContext) : CallsTr
|
||||
val symbol = call.symbol
|
||||
val function = call.symbol.owner
|
||||
|
||||
if (function.isDynamic() || function.isEffectivelyExternal()) {
|
||||
if (function.isDynamic()) {
|
||||
when (call.origin) {
|
||||
GET_PROPERTY -> {
|
||||
val fieldSymbol = context.symbolTable.lazyWrapper.referenceField(
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ class IrElementToJsExpressionTransformer : BaseIrElementToJsNodeTransformer<JsEx
|
||||
if (function is IrSimpleFunction) {
|
||||
val property = function.correspondingProperty
|
||||
if (property != null && property.isEffectivelyExternal()) {
|
||||
val nameRef = JsNameRef(property.name.identifier, jsDispatchReceiver)
|
||||
val nameRef = JsNameRef(context.getNameForDeclaration(property), jsDispatchReceiver)
|
||||
return when (function) {
|
||||
property.getter -> nameRef
|
||||
property.setter -> jsAssignment(nameRef, arguments.single())
|
||||
|
||||
+2
-1
@@ -45,7 +45,8 @@ class JsGenerationContext {
|
||||
|
||||
fun getNameForDeclaration(declaration: IrDeclaration): JsName = when (declaration) {
|
||||
is IrSymbolOwner -> getNameForSymbol(declaration.symbol)
|
||||
is IrProperty -> currentScope.declareName(declaration.name.identifier)
|
||||
// Properties don't have symbols. Handling them separately:
|
||||
is IrProperty -> currentScope.declareName(declaration.getJsName() ?: declaration.name.identifier)
|
||||
else -> error("Unsupported")
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -117,8 +117,12 @@ class SimpleNameGenerator : NameGenerator {
|
||||
if (declaration is IrConstructor) return@getOrPut getNameForDeclaration(declaration.parentAsClass, context)
|
||||
|
||||
if (declaration is IrClass && declaration.parent is IrClass) {
|
||||
val parentName = getNameForDeclaration(declaration.parentAsClass, context).ident
|
||||
return@getOrPut context.currentScope.declareFreshName(parentName + "$" + descriptorName.identifier)
|
||||
val parentName = getNameForDeclaration(declaration.parentAsClass, context)
|
||||
if (declaration.isCompanion) {
|
||||
// External companions are class references
|
||||
return@getOrPut parentName
|
||||
}
|
||||
return@getOrPut context.currentScope.declareFreshName(parentName.ident + "$" + descriptorName.identifier)
|
||||
}
|
||||
return@getOrPut context.staticContext.rootScope.declareName(descriptorName.identifier)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1281
|
||||
// FILE: main.kt
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
package foo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user