[JS IR] .d.ts generation for module systems

Support .d.ts generation for UMD, AMD, CommonJS module kinds in
addition to existing "plain" module kind.
This commit is contained in:
Svyatoslav Kuzmich
2020-07-14 14:16:41 +03:00
parent ee23e39b3c
commit 609f0ca9bc
11 changed files with 189 additions and 9 deletions
@@ -83,6 +83,34 @@ public class IrJsTypeScriptExportES6TestGenerated extends AbstractIrJsTypeScript
}
}
@TestMetadata("js/js.translator/testData/typescript-export/moduleSystems")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ModuleSystems extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInModuleSystems() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/moduleSystems"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("commonjs.kt")
public void testCommonjs() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/commonjs.kt");
}
@TestMetadata("plain.kt")
public void testPlain() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/plain.kt");
}
@TestMetadata("umd.kt")
public void testUmd() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/umd.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/namespaces")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -83,6 +83,34 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp
}
}
@TestMetadata("js/js.translator/testData/typescript-export/moduleSystems")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ModuleSystems extends AbstractIrJsTypeScriptExportTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInModuleSystems() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/moduleSystems"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("commonjs.kt")
public void testCommonjs() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/commonjs.kt");
}
@TestMetadata("plain.kt")
public void testPlain() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/plain.kt");
}
@TestMetadata("umd.kt")
public void testUmd() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/umd.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/namespaces")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -78,6 +78,34 @@ public class LegacyJsTypeScriptExportTestGenerated extends AbstractLegacyJsTypeS
}
}
@TestMetadata("js/js.translator/testData/typescript-export/moduleSystems")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ModuleSystems extends AbstractLegacyJsTypeScriptExportTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInModuleSystems() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/moduleSystems"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("commonjs.kt")
public void testCommonjs() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/commonjs.kt");
}
@TestMetadata("plain.kt")
public void testPlain() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/plain.kt");
}
@TestMetadata("umd.kt")
public void testUmd() throws Exception {
runTest("js/js.translator/testData/typescript-export/moduleSystems/umd.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/namespaces")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -0,0 +1,10 @@
type Nullable<T> = T | null | undefined
export namespace foo {
const prop: number;
class C {
constructor(x: number);
readonly x: number;
doubleX(): number;
}
function box(): string;
}
@@ -0,0 +1,16 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// SKIP_MINIFICATION
// SKIP_NODE_JS
// MODULE_KIND: COMMON_JS
@file:JsExport
package foo
val prop = 10
class C(val x: Int) {
fun doubleX() = x * 2
}
fun box(): String = "OK"
@@ -0,0 +1,12 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
const prop: number;
class C {
constructor(x: number);
readonly x: number;
doubleX(): number;
}
function box(): string;
}
}
@@ -0,0 +1,15 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// SKIP_MINIFICATION
// SKIP_NODE_JS
@file:JsExport
package foo
val prop = 10
class C(val x: Int) {
fun doubleX() = x * 2
}
fun box(): String = "OK"
@@ -0,0 +1,11 @@
type Nullable<T> = T | null | undefined
export namespace foo {
const prop: number;
class C {
constructor(x: number);
readonly x: number;
doubleX(): number;
}
function box(): string;
}
export as namespace JS_TESTS;
@@ -0,0 +1,16 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// SKIP_MINIFICATION
// SKIP_NODE_JS
// MODULE_KIND: UMD
@file:JsExport
package foo
val prop = 10
class C(val x: Int) {
fun doubleX() = x * 2
}
fun box(): String = "OK"