feat: add ability to create nested entities inside object.

This commit is contained in:
Artem Kobzar
2022-06-22 11:59:13 +00:00
committed by Space
parent 3766698081
commit ba738cbbff
10 changed files with 559 additions and 337 deletions
@@ -198,5 +198,39 @@ declare namespace JS_TESTS {
hashCode(): number;
equals(other: Nullable<any>): boolean;
}
abstract class Parent {
private constructor();
}
namespace Parent {
abstract class Nested1 extends _objects_.foo$Parent$Nested1 {
private constructor();
}
namespace Nested1 {
class Nested2 {
constructor();
}
namespace Nested2 {
abstract class Companion {
private constructor();
}
namespace Companion {
class Nested3 {
constructor();
}
}
}
}
}
function getParent(): typeof foo.Parent;
function createNested1(): typeof foo.Parent.Nested1;
function createNested2(): foo.Parent.Nested1.Nested2;
function createNested3(): foo.Parent.Nested1.Nested2.Companion.Nested3;
}
}
namespace _objects_ {
const foo$Parent$Nested1: {
get value(): string;
} & {
new(): any;
};
}
}
@@ -256,4 +256,36 @@ class __JsNameTest private constructor() {
data class KT39423(
val a: String,
val b: Int? = null
)
)
@JsExport
object Parent {
object Nested1 {
val value: String = "Nested1"
class Nested2 {
companion object {
class Nested3
}
}
}
}
@JsExport
fun getParent(): Parent {
return Parent
}
@JsExport
fun createNested1(): Parent.Nested1 {
return Parent.Nested1
}
@JsExport
fun createNested2(): Parent.Nested1.Nested2 {
return Parent.Nested1.Nested2()
}
@JsExport
fun createNested3(): Parent.Nested1.Nested2.Companion.Nested3 {
return Parent.Nested1.Nested2.Companion.Nested3()
}
@@ -32,6 +32,11 @@ var processInterface = JS_TESTS.foo.processInterface;
var OuterClass = JS_TESTS.foo.OuterClass;
var KT38262 = JS_TESTS.foo.KT38262;
var JsNameTest = JS_TESTS.foo.JsNameTest;
var Parent = JS_TESTS.foo.Parent;
var getParent = JS_TESTS.foo.getParent;
var createNested1 = JS_TESTS.foo.createNested1;
var createNested2 = JS_TESTS.foo.createNested2;
var createNested3 = JS_TESTS.foo.createNested3;
function assert(condition) {
if (!condition) {
throw "Assertion failed";
@@ -135,5 +140,15 @@ function box() {
assert(jsNameTest.runTest() === "JsNameTest");
var jsNameNestedTest = JsNameTest.Companion.createChild(42);
assert(jsNameNestedTest.value === 42);
// Do not strip types from those test cases (it is a check of nested objects types usability)
var parent = Parent;
var nested1 = Parent.Nested1;
var nested2 = new Parent.Nested1.Nested2();
var nested3 = new Parent.Nested1.Nested2.Companion.Nested3();
assert(nested1.value === "Nested1");
assert(getParent() === parent);
assert(createNested1() === nested1);
assert(createNested2() !== nested2);
assert(createNested3() !== nested3);
return "OK";
}
@@ -32,6 +32,11 @@ import processInterface = JS_TESTS.foo.processInterface;
import OuterClass = JS_TESTS.foo.OuterClass;
import KT38262 = JS_TESTS.foo.KT38262;
import JsNameTest = JS_TESTS.foo.JsNameTest;
import Parent = JS_TESTS.foo.Parent;
import getParent = JS_TESTS.foo.getParent;
import createNested1 = JS_TESTS.foo.createNested1;
import createNested2 = JS_TESTS.foo.createNested2;
import createNested3 = JS_TESTS.foo.createNested3;
function assert(condition: boolean) {
if (!condition) {
@@ -166,5 +171,16 @@ function box(): string {
assert(jsNameNestedTest.value === 42)
// Do not strip types from those test cases (it is a check of nested objects types usability)
const parent: typeof Parent = Parent
const nested1: typeof Parent.Nested1 = Parent.Nested1
const nested2: Parent.Nested1.Nested2 = new Parent.Nested1.Nested2()
const nested3: Parent.Nested1.Nested2.Companion.Nested3 = new Parent.Nested1.Nested2.Companion.Nested3()
assert(nested1.value === "Nested1")
assert(getParent() === parent)
assert(createNested1() === nested1)
assert(createNested2() !== nested2)
assert(createNested3() !== nested3)
return "OK";
}
@@ -13,13 +13,13 @@ declare namespace JS_TESTS {
constructor();
protected get protectedVal(): number;
protected protectedFun(): number;
get publicVal(): number;
publicFun(): number;
protected static get protectedNestedObject(): {
};
protected static get Companion(): {
get companionObjectProp(): number;
};
get publicVal(): number;
publicFun(): number;
}
namespace Class {
class protectedClass {