[K/JS] test: add @file:JsExport tests for each @JsExport test + auto-generate TypeScript export tests.

This commit is contained in:
Artem Kobzar
2022-08-26 09:51:59 +00:00
committed by Space
parent d65775ca1a
commit dbda8dcad1
139 changed files with 4242 additions and 31 deletions
@@ -719,6 +719,12 @@ private fun shouldDeclarationBeExportedImplicitlyOrExplicitly(declaration: IrDec
}
private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, context: JsIrBackendContext): Boolean {
// Formally, user have no ability to annotate EnumEntry as exported, without Enum Class
// But, when we add @file:JsExport, the annotation appears on the all of enum entries
// what make a wrong behaviour on non-exported members inside Enum Entry (check exportEnumClass and exportFileWithEnumClass tests)
if (declaration is IrClass && declaration.kind == ClassKind.ENUM_ENTRY)
return false
if (context.additionalExportedDeclarationNames.contains(declaration.fqNameWhenAvailable))
return true
@@ -0,0 +1,34 @@
// !OPT_IN: kotlin.js.ExperimentalJsExport
// !RENDER_DIAGNOSTICS_MESSAGES
@file:JsExport
package foo
fun <!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>delete<!>() {}
val <!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>instanceof<!> = 4
class <!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>eval<!>
@JsName(<!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>"await"<!>)
fun foo() {}
@JsName(<!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>"this"<!>)
val bar = 4
@JsName(<!NON_CONSUMABLE_EXPORTED_IDENTIFIER!>"super"<!>)
class Baz
class Test {
fun instanceof() {}
@JsName("eval")
fun test() {}
}
object NaN
enum class Nums {
Infinity,
undefined
}
@@ -0,0 +1,58 @@
package
package foo {
@kotlin.js.JsName(name = "this") public val bar: kotlin.Int = 4
public val instanceof: kotlin.Int = 4
public fun delete(): kotlin.Unit
@kotlin.js.JsName(name = "await") public fun foo(): kotlin.Unit
@kotlin.js.JsName(name = "super") public final class Baz {
public constructor Baz()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object NaN {
private constructor NaN()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final enum class Nums : kotlin.Enum<foo.Nums> {
enum entry Infinity
enum entry undefined
private constructor Nums()
@kotlin.internal.IntrinsicConstEvaluation public final override /*1*/ /*fake_override*/ val name: kotlin.String
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: foo.Nums): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public final /*synthesized*/ val entries: kotlin.enums.EnumEntries<foo.Nums>
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): foo.Nums
public final /*synthesized*/ fun values(): kotlin.Array<foo.Nums>
}
public final class Test {
public constructor Test()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun instanceof(): kotlin.Unit
@kotlin.js.JsName(name = "eval") public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class eval {
public constructor eval()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -0,0 +1,14 @@
// !OPT_IN: kotlin.js.ExperimentalJsExport
// !RENDER_DIAGNOSTICS_MESSAGES
@file:JsExport
package foo
class C(val x: String) {
<!WRONG_EXPORTED_DECLARATION("secondary constructor without @JsName")!>constructor(x: Int)<!>: this(x.toString())
}
class C2(val x: String) {
@JsName("JsNameProvided")
constructor(x: Int): this(x.toString())
}
@@ -0,0 +1,22 @@
package
package foo {
public final class C {
public constructor C(/*0*/ x: kotlin.Int)
public constructor C(/*0*/ x: kotlin.String)
public final val x: kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class C2 {
@kotlin.js.JsName(name = "JsNameProvided") public constructor C2(/*0*/ x: kotlin.Int)
public constructor C2(/*0*/ x: kotlin.String)
public final val x: kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -413,12 +413,24 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiers.kt");
}
@Test
@TestMetadata("nonConsumableIdentifiersInExportedFile.kt")
public void testNonConsumableIdentifiersInExportedFile() throws Exception {
runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt");
}
@Test
@TestMetadata("secondaryConstructorWithoutJsName.kt")
public void testSecondaryConstructorWithoutJsName() throws Exception {
runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsName.kt");
}
@Test
@TestMetadata("secondaryConstructorWithoutJsNameInExportedFile.kt")
public void testSecondaryConstructorWithoutJsNameInExportedFile() throws Exception {
runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt");
}
@Test
@TestMetadata("unexportableTypesInSignature.kt")
public void testUnexportableTypesInSignature() throws Exception {