Issues after compiling (IR compiler)

Hi all,
I’m trying to export 3 very simple classes.

@JsExport
open class MyFirstClass {
    open fun myFirstClassFunction() {
        println("################ MyFirstClass")
    }
}

@JsExport
open class MySecondClass {
    open fun mySecondClassFunction(){
        println("################ MySecondClass")
    }
}

@JsExport
open class MyThirdClass {
    open fun myThirdClassFunction() {
        println("################ MyThirdClass")
    }
}

Basically, these classes are the same.

After compile, a get d.ts. file and .js
d.ts. file looks like:

export class MyFirstClass {
    constructor();
    myFirstClassFunction(): void;
}
export class MySecondClass {
    constructor();
    mySecondClassFunction(): void;
}
export class MyThirdClass {
    constructor();
    myThirdClassFunction(): void;
}

but, the .js file added some numbers beside the methods name

MyFirstClass.prototype.myFirstClassFunction_0 = function () {
    println('################ MyFirstClass');
  };
  MyFirstClass.$metadata$ = {
    simpleName: 'MyFirstClass',
    kind: 'class',
    interfaces: []
  };
  function MySecondClass() {
  }
  MySecondClass.prototype.mySecondClassFunction = function () {
    println('################ MySecondClass');
  };
  MySecondClass.$metadata$ = {
    simpleName: 'MySecondClass',
    kind: 'class',
    interfaces: []
  };
  function MyThirdClass() {
  }
  MyThirdClass.prototype.myThirdClassFunction_3 = function () {
    println('################ MyThirdClass');
  };
  MyThirdClass.$metadata$ = {
    simpleName: 'MyThirdClass',
    kind: 'class',
    interfaces: []
  };

After inheritance like in example

class MyFirstClassTS extends MyFirstClass {
  constructor() {
    super();
  }
  myFirstClassFunction() {
    console.info("############ MyFirstClassTS")
  }
}

class MySecondClassTS extends MySecondClass {
  constructor() {
    super();
  }
  mySecondClassFunction() {
    console.info("############ MySecondClassTS")
  }
}

class MyThirdClassTS extends MyThirdClass {
  constructor() {
    super();
  }
  myThirdClassFunction() {
    console.info("############ MyThirdClassTS")
  }
}

in console I got very different result as in picture below.

Is there any other configuration of the compiler or something else to fix this issues ?

Thanks

1 Like

I believe you need to export the functions themselves too

@JsExport can only be used on class annotation, it can not be used inside class.

Something really weird is happening and I can’t understand what is the problem.
The second problem that I’ve found is the next example:

In d.ts file I have:

export namespace info {
    class EventListener {
        constructor();
        addType(type: number): void;
        isContainsType(type: number): boolean;
        hasTypes(): boolean;
        callback(event: Nullable<utils.information_bus.CoreEvent>): void;
    }
}

and in exported js I have:

  function EventListener_0() {
    this._eventTypes = new GSet();
  }
  EventListener_0.prototype.addType_8 = function (type) {
    this._eventTypes.add_20([type]);
  };
  EventListener_0.prototype.isContainsType_8 = function (type) {
    return this._eventTypes.contains_24(type);
  };
  EventListener_0.prototype.hasTypes_8 = function () {
    return this._eventTypes.size_2() > 0;
  };
  EventListener_0.prototype.callback_8 = function (event) {
  };

in my simple TS file when I try to use the method addType, an error says “this.addType is not a function”

class WebMainEvent extends info.EventListener {
  constructor() {
    super()
    this.addType(8)
  }
}
new WebMainEvent ()

Is there, maybe, any problem in kotlin compiler ?

Thanks

I think this is one of the cases where Kotlin/JS is unfortunately not quite 100% here.

I realize this is quite inelegant and cumbersome but I think you need to put JsName annotation on everything that should not be mangled:

I am afraid that this one is not working as expected, I tried but without any success.
Anyway, I found that functions without params works, generally ok, without name mangling. But, functions with variable number of params work very unpredictable, like my top comment.

Browser will not show any error, just overriding function will not be called, or will be called parent function.

I have no idea what is the right way to overcome this.

1 Like