[JS IR] Export nested objects
Companion objects are exported as ParentClass.Companion. Companion object's members are not exposed to its parent class — one must reference the companion object explicitly if they want to access its members. #KT-43783 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
862f8cdad8
commit
be999564b1
@@ -0,0 +1,58 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1265
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
// INFER_MAIN_MODULE
|
||||
// SKIP_MINIFICATION
|
||||
// SKIP_DCE_DRIVEN
|
||||
// SKIP_NODE_JS
|
||||
|
||||
// See KT-43783
|
||||
|
||||
// MODULE: nestedObjectExport
|
||||
// FILE: lib.kt
|
||||
|
||||
@JsExport
|
||||
class Abc {
|
||||
companion object AbcCompanion {
|
||||
fun xyz(): String = "Companion object method OK"
|
||||
|
||||
val prop: String
|
||||
get() = "Companion object property OK"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class Foo {
|
||||
companion object {
|
||||
fun xyz(): String = "Companion object method OK"
|
||||
|
||||
val prop: String
|
||||
get() = "Companion object property OK"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
sealed class MyEnum(val name: String) {
|
||||
object A: MyEnum("A")
|
||||
object B: MyEnum("B")
|
||||
object C: MyEnum("C")
|
||||
}
|
||||
|
||||
// FILE: test.js
|
||||
|
||||
function box() {
|
||||
const abcCompanion = nestedObjectExport.Abc.AbcCompanion;
|
||||
|
||||
if (abcCompanion.xyz() != 'Companion object method OK') return 'companion object function failure';
|
||||
if (abcCompanion.prop != 'Companion object property OK') return 'companion object property failure';
|
||||
|
||||
const justCompanion = nestedObjectExport.Foo.Companion;
|
||||
|
||||
if (justCompanion.xyz() != 'Companion object method OK') return 'companion object function failure';
|
||||
if (justCompanion.prop != 'Companion object property OK') return 'companion object property failure';
|
||||
|
||||
if (nestedObjectExport.MyEnum.A.name != 'A') return 'MyEnum.A failure';
|
||||
if (nestedObjectExport.MyEnum.B.name != 'B') return 'MyEnum.B failure';
|
||||
if (nestedObjectExport.MyEnum.C.name != 'C') return 'MyEnum.C failure';
|
||||
|
||||
return 'OK';
|
||||
}
|
||||
Reference in New Issue
Block a user