Hi. In JS, it looks like order of class initializa...
# announcements
v
Hi. In JS, it looks like order of class initialization is sometimes wrong. Am I missing something? Example code:
Copy code
fun test1() {
    class B {
        val value = "qweqwe"
    }

    class A(val b: B) {
        val value = when {
            true -> b.value
            else -> "lalala"
        }
    }

    val a = A(B())
    println(a.value)
}
Execution result:
Copy code
E:\work\kotlin-js-playground>node run.js test1
Running test1
E:\work\kotlin-js-playground\out\production\kotlin-js-playground\kotlin-js-playground.js:10
        tmp$0 = this.b.value;
                      ^

TypeError: Cannot read property 'value' of undefined
    at new <anonymous> (E:\work\kotlin-js-playground\out\production\kotlin-js-playground\kotlin-js-playground.js:10:23)
Piece of generated JS:
Copy code
test1$A: Kotlin.createClass(null, function (b) {
      var tmp$0;
      if (true)
        tmp$0 = this.b.value;   // <-- Error here
      else
        tmp$0 = 'lalala';
      this.b = b;               // <-- This should be above [if]
      this.value = tmp$0;
    }),