Another technical question. Looking at the outputt...
# javascript
e
Another technical question. Looking at the outputted JS with ES modules I see:
Copy code
var MainTestClass;
function MainTest() {
  if (MainTestClass === VOID) {
    class $ {
      constructor() {
        return new.target.new_MainTest_jncw2x_k$();
      }
      static new_MainTest_jncw2x_k$($box) {
        return createThis(this, $box);
      }
      main() {
        init();
      }
    }
    initMetadataForClass($, 'MainTest', $.new_MainTest_jncw2x_k$);
    MainTestClass = $;
  }
  return MainTestClass;
}
Where, to generate the actual class, the function
MainTest()
is called. Why is it wrapped in a function? This doesn't seem to happen when targeting CommonJS.
t
AFAIK It's required for Kotlin initialization logic emulation
@Artem Kobzar ^^
e
I'm just surprised it's only for ES modules.
t
With file-to-file we receive 2 exports 1. Export in Kotlin 2. Export in JS
And they don't work same way
e
But this happens even for per-module. Did a bunch of tests to understand if it was connected to granularity, and it doesn't seem to be so
t
In common case it's ES modules specific
a
It's only for per-file to work with circular-dependencies between files + it should improve tree-shaking of the classes.
e
Thanks! I'll try again with per-module then, because IIRC it did happen with that too