[JS IR] Support per-file mode and ES modules
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
// SKIP_DCE_DRIVEN
|
||||
// SKIP_MINIFICATION
|
||||
// ES_MODULES
|
||||
|
||||
// FILE: api.kt
|
||||
|
||||
@JsExport
|
||||
data class Point(val x: Int, val y: Int) {
|
||||
override fun toString(): String = "[${x}::${y}]"
|
||||
}
|
||||
|
||||
// we need his class to make sure that there's more than one ping method in existence - due to peculiarities of current namer otherwise test can pass but JsExport won't be actually respected
|
||||
data class AltPoint(val x: Int, val y: Int)
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val copy00: String
|
||||
val copy01: String
|
||||
val copy10: String
|
||||
val copy11: String
|
||||
val component1: Int
|
||||
val component2: Int
|
||||
}
|
||||
|
||||
@JsModule("./dataClass.mjs")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
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,14 @@
|
||||
import { Point } from "./JS_TESTS/index.js";
|
||||
|
||||
export default function() {
|
||||
var p = new Point(3, 7);
|
||||
|
||||
return {
|
||||
"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()
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// SKIP_DCE_DRIVEN
|
||||
// SKIP_MINIFICATION
|
||||
// ES_MODULES
|
||||
|
||||
@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
|
||||
class Foo {
|
||||
@JsName("foo")
|
||||
fun value(value: Long = 5L) = if (value == 5L) "C" else "fail"
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
val Foo: String
|
||||
}
|
||||
|
||||
@JsModule("./exportedDefaultStub.mjs")
|
||||
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}"
|
||||
}
|
||||
|
||||
if (res.Foo != "C") {
|
||||
return "fail14: ${res.Foo}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as api from "./JS_TESTS/index.js";
|
||||
|
||||
export default function() {
|
||||
var ping = api.ping;
|
||||
var pong = api.pong;
|
||||
var transform = api.transform;
|
||||
var Ping = api.Ping;
|
||||
var Pong = api.Pong;
|
||||
var Foo = api.Foo;
|
||||
|
||||
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(),
|
||||
"Foo": new Foo().foo()
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// SKIP_MINIFICATION
|
||||
// ES_MODULES
|
||||
// FILE: api.kt
|
||||
|
||||
@JsExport
|
||||
class A() {
|
||||
fun ping() = "ping"
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class B() {
|
||||
@JsName("pong")
|
||||
fun ping() = "pong"
|
||||
}
|
||||
|
||||
// we need his class to make sure that there's more than one ping method in existence - due to peculiarities of current namer otherwise test can pass but JsExport won't be actually respected
|
||||
class C() {
|
||||
fun ping() = "pong"
|
||||
}
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val res: String
|
||||
}
|
||||
|
||||
@JsModule("./jsExportInClass.mjs")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
val res = jsBox().res
|
||||
if (res != "pingpong") {
|
||||
return "Fail: ${res}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { A, B } from "./JS_TESTS/index.js";
|
||||
|
||||
export default function() {
|
||||
return {
|
||||
"res": (new A().ping()) + (new B().pong())
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// SKIP_MINIFICATION
|
||||
// ES_MODULES
|
||||
|
||||
// FILE: api.kt
|
||||
@JsExport
|
||||
class Something<T: Something<T>> {
|
||||
fun ping(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun ping(s: Something<*>): String {
|
||||
return s.ping()
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val pingCall: () -> String
|
||||
}
|
||||
|
||||
@JsModule("./recursiveExport.mjs")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
return jsBox().pingCall()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ping, Something } from "./JS_TESTS/index.js"
|
||||
|
||||
export default function() {
|
||||
return {
|
||||
"pingCall": function() {
|
||||
return ping(new Something())
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user