[JS IR BE] Add JsExport annotations

This commit is contained in:
Svyatoslav Kuzmich
2019-06-27 15:12:14 +03:00
parent 685597d20a
commit 69962cbf8c
22 changed files with 91 additions and 31 deletions
@@ -1,11 +1,15 @@
// SKIP_MINIFICATION
@JsName("foo")
@JsExport
fun foo(): Char = '1'
@JsExport
val p1: Char = '2'
@JsExport
var p2: Char = '3'
@JsExport
var p3: Char = '4'
get() = field + 1
set(value) {
@@ -7,6 +7,7 @@
// MODULE: non-identifier-module-name
// FILE: lib.kt
@JsName("foo")
@JsExport
public fun foo(k: String): String = "O$k"
// FILE: test.js
@@ -7,6 +7,7 @@
// MODULE: if
// FILE: lib.kt
@JsName("foo")
@JsExport
public fun foo(k: String): String = "O$k"
// FILE: test.js
@@ -2,6 +2,9 @@
// SKIP_MINIFICATION
// This test assumes that external JS code calls Kotlin code directly
// Legacy export, wrong types
// DONT_TARGET_EXACT_BACKEND: JS_IR
open class A
class B : A()
@@ -11,6 +11,7 @@ inline fun ok(): I {
}
@JsName("convolutedOk")
@JsExport
inline fun convolutedOk(): I {
val fail = object : I {
override fun ok() = "fail"
+1
View File
@@ -1,5 +1,6 @@
// EXPECTED_REACHABLE_NODES: 1290
@JsExport
data class A(val value: Int)
fun box(): String {
+4 -4
View File
@@ -6,10 +6,10 @@ object A {
@JsName("js_property") val f: String get() = "property"
}
fun test() = js("""
var a = JS_TESTS.A;
return a.js_method() + ";" + a.js_property;
""")
fun test(): dynamic {
val a = A.asDynamic()
return a.js_method() + ";" + a.js_property
}
fun box(): String {
val result = test()
+3 -4
View File
@@ -8,10 +8,9 @@ class B : A() {
override fun f(x: Int) = "B.f($x)"
}
fun test() = js("""
var module = JS_TESTS;
return new (module.A)().js_f(23) + ";" + new (module.B)().js_f(42);
""")
fun test(): dynamic {
return A().asDynamic().js_f(23) + ";" + B().asDynamic().js_f(42)
}
fun box(): String {
val result = test()
@@ -8,10 +8,9 @@ class B : A {
override fun f(x: Int) = "B.f($x)"
}
fun test() = js("""
var module = JS_TESTS;
return new (module.B)().js_f(23);
""")
fun test(): dynamic {
return B().asDynamic().js_f(23)
}
fun box(): String {
val result = test()
+4 -4
View File
@@ -10,10 +10,10 @@ object A {
@JsName("js_q") val q: String get() = "q"
}
fun test() = js("""
var a = JS_TESTS.A;
return a.js_f(23) + ";" + a.js_g(42) + ";" + a.js_p + ";" + a.js_q;
""")
fun test(): dynamic {
var a = A.asDynamic()
return a.js_f(23) + ";" + a.js_g(42) + ";" + a.js_p + ";" + a.js_q
}
fun box(): String {
val result = test()
+1
View File
@@ -1,5 +1,6 @@
// SKIP_MINIFICATION
@JsExport
val top = "TOP LEVEL"
fun box(): String {
@@ -1,6 +1,7 @@
// SKIP_MINIFICATION
// Contains calls from external JS code
@JsExport
open class A {
@JsName("foo")
open protected fun foo(n: Int) = 23
@@ -9,6 +10,7 @@ open class A {
fun bar(n: Int) = foo(n) + 100
}
@JsExport
open class B {
@JsName("foo")
protected fun foo(n: Int) = 42
@@ -11,6 +11,7 @@ class A {
}
}
@JsExport
val A.z: Int
@JsName("getZ_") get() = 42
@@ -1,8 +1,10 @@
// EXPECTED_REACHABLE_NODES: 1288
@JsExport
val x: Int
@JsName("getX_") get() = 23
@JsExport
var y: Int = 0
@JsName("getY_") get() = field + 10
@JsName("setY_") set(value) {
@@ -27,10 +27,13 @@ fun box(): String {
if (!hasProp(b, "foo")) return "B hasn't foo"
if (!hasProp(b, "boo")) return "B hasn't boo"
val PREFIX = "_"
if (eval("$PREFIX.A") == null) return "$PREFIX.A not found"
if (eval("$PREFIX.B") == null) return "$PREFIX.B not found"
if (eval("$PREFIX.A === $PREFIX.B") as Boolean) return "A and B refer to the same object"
// Legacy scheme exports interfaces
if (testUtils.isLegacyBackend()) {
val PREFIX = "_"
if (eval("$PREFIX.A") == null) return "$PREFIX.A not found"
if (eval("$PREFIX.B") == null) return "$PREFIX.B not found"
if (eval("$PREFIX.A === $PREFIX.B") as Boolean) return "A and B refer to the same object"
}
return "OK"
}