Skip to content

Failure to process Kotlin JS/exports correctly #106

@nanodeath

Description

@nanodeath

Hi there,

Context: I'm writing Kotlin JS, which generates a AMD-style JS module, which then gets plumbed through Rollup using rollup-plugin-amd, which in turn depends on...this.

The JS Kotlin generates initially looks like this:

define(['exports', 'kotlin'], function (_, Kotlin) {
  'use strict';
  var defineInlineFunction = Kotlin.defineInlineFunction;
  function main(args) {
  }
  _.main_kand9s$ = main;
  main([]);
  Kotlin.defineModule('my-module', _);
  return _;
});

After trickling through the build process, the final output JS is this:

var app = (function (Kotlin) {
  'use strict';

  Kotlin = Kotlin && Kotlin.hasOwnProperty('default') ? Kotlin['default'] : Kotlin;

  var defineInlineFunction = Kotlin.defineInlineFunction;
  function main(args) {
  }
  _.main_kand9s$ = main;

  return _;

}(kotlin));

Which looks fine-ish, except for one problem -- it's assuming there's a _ global when there is none. This causes JS errors when loading the page. As an immediate workaround, I'll create a "_" object on the page to absorb exports, but that seems odd to me. Thoughts?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions