Kotlin接口导出到Javascript缺失的属性

时间:2017-10-24 11:46:18

标签: javascript gradle kotlin

我在Kotlin有一个简单的界面,如下所示:

interface IMyInterface {

var name: String

var description: String }

使用如下的build.gradle文件:

 apply plugin: 'java' 
 apply plugin: 'kotlin2js'

 sourceCompatibility = 1.8

 repositories {
     mavenCentral() }

 dependencies {
     compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
     compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }

 compileKotlin2Js {
     kotlinOptions.moduleKind = "umd"
     kotlinOptions.sourceMap = true }

我在构建导出时导出的javascript:

  (function (root, factory) {
  if (typeof define === 'function' && define.amd)
    define(['exports', 'kotlin'], factory);
  else if (typeof exports === 'object')
    factory(module.exports, require('kotlin'));
  else {
    if (typeof kotlin === 'undefined') {
      throw new Error("Error loading module 'myModule'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'myModule'.");
    }
    root['myModule'] = factory(typeof this['myModule'] === 'undefined' ? {} : this['myModule'], kotlin);
  }
}(this, function (_, Kotlin) {
  'use strict';
  function IMyInterface() {
  }
  IMyInterface.$metadata$ = {
    kind: Kotlin.Kind.INTERFACE,
    simpleName: 'IMyInterface',
    interfaces: []
  };
  _.IMyInterface = IMyInterface;
  Kotlin.defineModule('myModule', _);
  return _;
}));

如果您注意到导出的javascript不包含我的界面定义的任何属性(缺少名称,描述)。

我希望看到的是像这样的出口:

  IMyInterface = function ( args ) {

  "use strict";

  var _name =  "";
  Object.defineProperty(this,"name",{

    enumerable: true,
    get: function() { return _name; },

    set: function(value) { _name = value; }

  });

  var _description =  "";
  Object.defineProperty(this,"description",{

    enumerable: true,
    get: function() { return _description; },

    set: function(value) { _description = value; }

  });

我也在使用kotlin版本1.1.51

谢谢!

0 个答案:

没有答案