feat: add implicit export support for Kotlin/JS

This commit is contained in:
Artem Kobzar
2021-11-16 16:59:18 +00:00
committed by Space
parent f05436b939
commit af924fd3d1
10 changed files with 161 additions and 7 deletions
@@ -89,6 +89,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/implicitExport")
@TestDataPath("$PROJECT_ROOT")
public class ImplicitExport {
@Test
public void testAllFilesPresentInImplicitExport() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/implicitExport"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("declarations.kt")
public void testDeclarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/implicitExport/declarations.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/inheritance")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,18 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
function producer(value: number): any/* foo.NonExportedType */;
function consumer(value: any/* foo.NonExportedType */): number;
class A {
constructor(value: any/* foo.NonExportedType */);
value: any/* foo.NonExportedType */;
increment<T>(t: T): any/* foo.NonExportedType */;
}
class B /* extends foo.NonExportedType */ {
constructor(v: number);
}
class C /* implements foo.NonExportedInterface */ {
constructor();
}
}
}
@@ -0,0 +1,35 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// RUN_PLAIN_BOX_FUNCTION
// SKIP_MINIFICATION
// SKIP_NODE_JS
// INFER_MAIN_MODULE
// MODULE: JS_TESTS
// FILE: declarations.kt
package foo
interface NonExportedInterface
open class NonExportedType(val value: Int)
@JsExport
fun producer(value: Int): NonExportedType {
return NonExportedType(value)
}
@JsExport
fun consumer(value: NonExportedType): Int {
return value.value
}
@JsExport
class A(var value: NonExportedType) {
fun <T: NonExportedType> increment(t: T): NonExportedType {
return NonExportedType(value = t.value + 1)
}
}
@JsExport
class B(v: Int) : NonExportedType(v)
@JsExport
class C : NonExportedInterface
@@ -0,0 +1,21 @@
"use strict";
var producer = JS_TESTS.foo.producer;
var consumer = JS_TESTS.foo.consumer;
var A = JS_TESTS.foo.A;
var B = JS_TESTS.foo.B;
function assert(condition) {
if (!condition) {
throw "Assertion failed";
}
}
function box() {
var nonExportedType = producer(42);
var a = new A(nonExportedType);
var b = new B(43);
assert(consumer(nonExportedType) == 42);
a.value = producer(24);
assert(consumer(b) == 43);
assert(consumer(a.value) == 24);
assert(consumer(a.increment(nonExportedType)) == 43);
return "OK";
}
@@ -0,0 +1,25 @@
import producer = JS_TESTS.foo.producer;
import consumer = JS_TESTS.foo.consumer;
import A = JS_TESTS.foo.A;
import B = JS_TESTS.foo.B;
function assert(condition: boolean) {
if (!condition) {
throw "Assertion failed";
}
}
function box(): string {
const nonExportedType = producer(42)
const a = new A(nonExportedType)
const b = new B(43)
assert(consumer(nonExportedType) == 42)
a.value = producer(24)
assert(consumer(b) == 43)
assert(consumer(a.value) == 24)
assert(consumer(a.increment(nonExportedType)) == 43)
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}