[K/Wasm] Add tests for nested external declarations + fix them

This commit is contained in:
Artem Kobzar
2024-01-22 11:55:09 +00:00
committed by Space Team
parent f15ca6a20f
commit 57a4d09ad2
3 changed files with 57 additions and 8 deletions
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.name.parentOrNull
import org.jetbrains.kotlin.serialization.js.ModuleKind import org.jetbrains.kotlin.serialization.js.ModuleKind
import org.jetbrains.kotlin.utils.addToStdlib.runIf import org.jetbrains.kotlin.utils.addToStdlib.runIf
import org.jetbrains.kotlin.utils.memoryOptimizedFilter import org.jetbrains.kotlin.utils.memoryOptimizedFilter
@@ -62,7 +62,13 @@ class ExportModelGenerator(val context: WasmBackendContext) {
override fun visitClass(declaration: IrClass) { override fun visitClass(declaration: IrClass) {
declaration.superTypes.forEach(::visitType) declaration.superTypes.forEach(::visitType)
declaration.acceptChildrenVoid(this) declaration.typeParameters.forEach(::visitTypeParameter)
declaration.declarations.forEach { it.acceptVoid(this) }
}
override fun visitProperty(declaration: IrProperty) {
declaration.backingField?.let(::visitField)
declaration.getter?.let(::visitFunction)
} }
override fun visitField(declaration: IrField) { override fun visitField(declaration: IrField) {
@@ -306,8 +312,10 @@ class ExportModelGenerator(val context: WasmBackendContext) {
) )
} }
val parentFqName = declaration.getFqNameWithJsNameWhenAvailable(shouldIncludePackage = true).parentOrNull()
return ExportedNamespace( return ExportedNamespace(
name = "$NOT_EXPORTED_NAMESPACE${declaration.packageFqName?.asString()?.takeIf { it.isNotEmpty() }?.let { ".$it" }.orEmpty()}", name = "$NOT_EXPORTED_NAMESPACE${parentFqName?.asString()?.takeIf { it.isNotEmpty() }?.let { ".$it" }.orEmpty()}",
declarations = listOf(exportedDeclaration), declarations = listOf(exportedDeclaration),
isPrivate = true isPrivate = true
) )
@@ -12,18 +12,37 @@ declare namespace not.exported.org.second {
} }
declare namespace not.exported.org.second { declare namespace not.exported.org.second {
const Foo: { const Foo: {
get bar(): number; get bar(): not.exported.Parent.OneMoreLayer.MentionedNested;
get baz(): string; get baz(): string;
get oneMore(): not.exported.Parent.Companion.AnotherMentionedNested;
} & not.exported.Baz<string>; } & not.exported.Baz<string>;
} }
declare namespace not.exported { declare namespace not.exported {
interface Baz<T> extends not.exported.Bar { interface Baz<T> extends not.exported.Bar {
readonly baz?: T; readonly baz?: T;
readonly bar: number; readonly bar: not.exported.Parent.OneMoreLayer.MentionedNested;
readonly oneMore: not.exported.Parent.Companion.AnotherMentionedNested;
}
}
declare namespace not.exported.Parent.OneMoreLayer {
interface MentionedNested {
readonly value: typeof not.exported.MentionedParent;
}
}
declare namespace not.exported.Parent.Companion {
class AnotherMentionedNested {
constructor();
get value(): string;
} }
} }
declare namespace not.exported { declare namespace not.exported {
interface Bar { interface Bar {
readonly bar: number; readonly bar: not.exported.Parent.OneMoreLayer.MentionedNested;
readonly oneMore: not.exported.Parent.Companion.AnotherMentionedNested;
} }
}
declare namespace not.exported {
const MentionedParent: {
get value(): string;
};
} }
@@ -3,8 +3,29 @@
// MODULE: main // MODULE: main
// FILE: first.kt // FILE: first.kt
external object MentionedParent {
val value: String
interface Nested {
val value: Int
}
}
external class Parent {
object OneMoreLayer {
interface MentionedNested {
val value: MentionedParent
}
}
companion object {
class AnotherMentionedNested {
val value: String
}
}
}
external interface Bar { external interface Bar {
val bar: Int val bar: Parent.OneMoreLayer.MentionedNested
val oneMore: Parent.Companion.AnotherMentionedNested
} }
external interface Baz<T: JsAny?> : Bar { external interface Baz<T: JsAny?> : Bar {
@@ -18,8 +39,9 @@ import Bar
import Baz import Baz
external object Foo : Baz<JsString> { external object Foo : Baz<JsString> {
override val bar: Int override val bar: Parent.OneMoreLayer.MentionedNested
override val baz: JsString override val baz: JsString
override val oneMore: Parent.Companion.AnotherMentionedNested
} }
external abstract class BaseResult<T: JsAny>(foo: Foo) external abstract class BaseResult<T: JsAny>(foo: Foo)