rra/ilgonmic/kt-51973

[JS IR] Add non overridden property and method insode exported class

[JS IR] Add method into exported interface in test

[JS IR] Add interface properties cases to all file export test

[JS IR] Fix usage of isExported inside IrJsUtils


Co-authored-by: Anton Bannykh <Anton.Bannykh@jetbrains.com>

Merge-request: KT-MR-6087
Merged-by: Ilya Goncharov <Ilya.Goncharov@jetbrains.com>

^KT-51973 fixed
This commit is contained in:
Anton Bannykh
2022-04-14 16:59:54 +00:00
committed by Space
parent a03999fe81
commit 90ee8662da
5 changed files with 152 additions and 15 deletions
@@ -668,7 +668,7 @@ private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, cont
}
fun IrOverridableDeclaration<*>.isAllowedFakeOverriddenDeclaration(context: JsIrBackendContext): Boolean {
if (this.resolveFakeOverride(allowAbstract = true)?.parentClassOrNull.isExportedInterface()) {
if (this.resolveFakeOverride(allowAbstract = true)?.parentClassOrNull.isExportedInterface(context)) {
return true
}
@@ -134,6 +134,8 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
val overriddenSymbols = property.getter?.overriddenSymbols.orEmpty()
val backendContext = context.staticContext.backendContext
// Don't generate `defineProperty` if the property overrides a property from an exported class,
// because we've already generated `defineProperty` for the base class property.
// In other words, we only want to generate `defineProperty` once for each property.
@@ -142,7 +144,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
// P.S. If the overridden property is owned by an interface - we should generate defineProperty
// for overridden property in the first class which override those properties
val hasOverriddenExportedInterfaceProperties = overriddenSymbols.any { it.owner.isDefinedInsideExportedInterface() }
&& !overriddenSymbols.any { it.owner.parentClassOrNull.isExportedClass() }
&& !overriddenSymbols.any { it.owner.parentClassOrNull.isExportedClass(backendContext) }
val getterOverridesExternal = property.getter?.overridesExternal() == true
val overriddenExportedGetter = !property.getter?.overriddenSymbols.isNullOrEmpty() &&
@@ -213,7 +215,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
}
private fun IrSimpleFunction.isDefinedInsideExportedInterface(): Boolean {
return (!isFakeOverride && parentClassOrNull.isExportedInterface()) ||
return (!isFakeOverride && parentClassOrNull.isExportedInterface(context.staticContext.backendContext)) ||
overriddenSymbols.any { it.owner.isDefinedInsideExportedInterface() }
}
@@ -124,7 +124,7 @@ fun translateCall(
val property = function.correspondingPropertySymbol?.owner
if (
property != null &&
(property.isEffectivelyExternal() || property.isExportedMember())
(property.isEffectivelyExternal() || property.isExportedMember(context.staticContext.backendContext))
) {
val propertyName = context.getNameForProperty(property)
val nameRef = when (jsDispatchReceiver) {
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.ir.backend.js.utils
import org.jetbrains.kotlin.descriptors.isClass
import org.jetbrains.kotlin.descriptors.isInterface
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.export.isExported
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithVisibility
@@ -14,18 +16,15 @@ import org.jetbrains.kotlin.ir.expressions.IrReturn
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
import org.jetbrains.kotlin.ir.util.parentClassOrNull
fun IrDeclaration.isExportedMember() =
fun IrDeclaration.isExportedMember(context: JsIrBackendContext) =
(this is IrDeclarationWithVisibility && visibility.isPublicAPI) &&
parentClassOrNull.let { it is IrClass && it.isJsExport() }
parentClassOrNull?.isExported(context) == true
fun IrDeclaration?.isExportedClass() =
this is IrClass && kind.isClass && isJsExport()
fun IrDeclaration?.isExportedClass(context: JsIrBackendContext) =
this is IrClass && kind.isClass && isExported(context)
fun IrDeclaration?.isExportedInterface() =
this is IrClass && kind.isInterface && isJsExport()
fun IrDeclaration.isExportedInterfaceMember() =
parentClassOrNull.isExportedInterface()
fun IrDeclaration?.isExportedInterface(context: JsIrBackendContext) =
this is IrClass && kind.isInterface && isExported(context)
fun IrReturn.isTheLastReturnStatementIn(target: IrReturnableBlockSymbol): Boolean {
return target.owner.statements.lastOrNull() === this