[JS IR] Generate stub for exported functions with default params
see https://youtrack.jetbrains.com/issue/KT-43407
This commit is contained in:
+6
-1
@@ -5,7 +5,12 @@ module.exports = function() {
|
||||
var p = new Point(3, 7);
|
||||
|
||||
return {
|
||||
"res": p.copy(13, 11).toString()
|
||||
"copy00": p.copy().toString(),
|
||||
"copy01": p.copy(undefined, 11).toString(),
|
||||
"copy10": p.copy(15).toString(),
|
||||
"copy11": p.copy(13, 11).toString(),
|
||||
"component1": p.component1(),
|
||||
"component2": p.component2()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+28
-4
@@ -1,4 +1,5 @@
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// SKIP_DCE_DRIVEN
|
||||
// SKIP_MINIFICATION
|
||||
|
||||
// FILE: api.kt
|
||||
@@ -14,17 +15,40 @@ data class AltPoint(val x: Int, val y: Int)
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val res: String
|
||||
val copy00: String
|
||||
val copy01: String
|
||||
val copy10: String
|
||||
val copy11: String
|
||||
val component1: Int
|
||||
val component2: Int
|
||||
}
|
||||
|
||||
@JsModule("lib")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
val res = jsBox().res
|
||||
if (res != "[13::11]") {
|
||||
return "Fail1: ${res}"
|
||||
val res = jsBox()
|
||||
if (res.copy00 != "[3::7]") {
|
||||
return "Fail1: ${res.copy00}"
|
||||
}
|
||||
if (res.copy01 != "[3::11]") {
|
||||
return "Fail2: ${res.copy01}"
|
||||
}
|
||||
if (res.copy10 != "[15::7]") {
|
||||
return "Fail3: ${res.copy10}"
|
||||
}
|
||||
if (res.copy11 != "[13::11]") {
|
||||
return "Fail4: ${res.copy11}"
|
||||
}
|
||||
if (res.component1 != 3) {
|
||||
return "Fail5: ${res.component1}"
|
||||
}
|
||||
if (res.component2 != 7) {
|
||||
return "Fail6: ${res.component2}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
$kotlin_test_internal$.beginModule();
|
||||
|
||||
module.exports = function() {
|
||||
var api = require("JS_TESTS").api;
|
||||
var ping = api.ping;
|
||||
var pong = api.pong;
|
||||
var transform = api.transform;
|
||||
var Ping = api.Ping;
|
||||
var Pong = api.Pong;
|
||||
|
||||
return {
|
||||
"ping00": ping(),
|
||||
"ping01": ping(undefined, 10),
|
||||
"ping10": ping("X"),
|
||||
"ping11": ping("Z", 5),
|
||||
|
||||
"pong00": pong(),
|
||||
"pong01": pong(undefined, 10),
|
||||
"pong10": pong("X"),
|
||||
"pong11": pong("Z", 5),
|
||||
|
||||
"transform00": transform(),
|
||||
"transform11": transform(-5, function(it) { return it * it * it }),
|
||||
|
||||
"Ping_ping00a": new Ping().ping(),
|
||||
"Ping_ping00b": new Ping(10).ping(),
|
||||
"Ping_ping11": new Ping().ping(-4, function(it) { return it * it * it }),
|
||||
|
||||
"Pong_ping00": new Pong().ping()
|
||||
};
|
||||
};
|
||||
|
||||
$kotlin_test_internal$.endModule("lib");
|
||||
@@ -0,0 +1,106 @@
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// SKIP_DCE_DRIVEN
|
||||
// SKIP_MINIFICATION
|
||||
package api
|
||||
|
||||
@JsExport
|
||||
fun ping(a: String = "A", b: Int = 1): String {
|
||||
return "$a::$b"
|
||||
}
|
||||
|
||||
@JsExport
|
||||
open class Ping(private val defaultSeed: Int = 3) {
|
||||
private fun calculate(n: Int) = n * n
|
||||
fun ping(s: Int = defaultSeed, c: (Int) -> Int = ::calculate): Int {
|
||||
return c(s)
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class Pong: Ping()
|
||||
|
||||
@JsExport
|
||||
@JsName("pong")
|
||||
fun bing(a: String = "A", b: Int = 1): String {
|
||||
return "$b::$a"
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun transform(i: Int = 10, t: (Int) -> Int = {it * it}): Int {
|
||||
return t(i)
|
||||
}
|
||||
|
||||
external interface JsResult {
|
||||
val ping00: String
|
||||
val ping01: String
|
||||
val ping10: String
|
||||
val ping11: String
|
||||
|
||||
val pong00: String
|
||||
val pong01: String
|
||||
val pong10: String
|
||||
val pong11: String
|
||||
|
||||
val transform00: Int
|
||||
val transform11: Int
|
||||
|
||||
val Ping_ping00a: Int
|
||||
val Ping_ping00b: Int
|
||||
val Ping_ping11: Int
|
||||
|
||||
val Pong_ping00: Int
|
||||
}
|
||||
|
||||
@JsModule("lib")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
val res = jsBox()
|
||||
if (res.ping00 != "A::1") {
|
||||
return "fail0: ${res.ping00}"
|
||||
}
|
||||
if (res.ping01 != "A::10") {
|
||||
return "fail1: ${res.ping01}"
|
||||
}
|
||||
if (res.ping10 != "X::1") {
|
||||
return "fail2: ${res.ping10}"
|
||||
}
|
||||
if (res.ping11 != "Z::5") {
|
||||
return "fail3: ${res.ping11}"
|
||||
}
|
||||
|
||||
if (res.pong00 != "1::A") {
|
||||
return "fail4: ${res.pong00}"
|
||||
}
|
||||
if (res.pong01 != "10::A") {
|
||||
return "fail5: ${res.pong01}"
|
||||
}
|
||||
if (res.pong10 != "1::X") {
|
||||
return "fail6: ${res.pong10}"
|
||||
}
|
||||
if (res.pong11 != "5::Z") {
|
||||
return "fail7: ${res.pong11}"
|
||||
}
|
||||
|
||||
if (res.transform00 != 100) {
|
||||
return "fail8: ${res.transform00}"
|
||||
}
|
||||
if (res.transform11 != -125) {
|
||||
return "fail9: ${res.transform11}"
|
||||
}
|
||||
|
||||
if (res.Ping_ping00a != 9) {
|
||||
return "fail10: ${res.Ping_ping00a}"
|
||||
}
|
||||
if (res.Ping_ping00b != 100) {
|
||||
return "fail11: ${res.Ping_ping00b}"
|
||||
}
|
||||
if (res.Ping_ping11 != -64) {
|
||||
return "fail12: ${res.Ping_ping11}"
|
||||
}
|
||||
if (res.Pong_ping00 != 9) {
|
||||
return "fail13: ${res.Pong_ping00}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user