[K/JS] Change order of exported properties definition for non ES-classes compilation ^KT-60131 Fixed

This commit is contained in:
Artem Kobzar
2023-07-19 14:33:19 +00:00
committed by Space Team
parent dc5660d98c
commit e4bdd3560c
6 changed files with 106 additions and 1 deletions
@@ -245,7 +245,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
}
)
} else {
classBlock.statements += JsExpressionStatement(
classModel.postDeclarationBlock.statements += JsExpressionStatement(
defineProperty(classPrototypeRef, propertyName.ident, getterForwarder, setterForwarder, context.staticContext)
)
}
@@ -2289,6 +2289,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
runTest("js/js.translator/testData/box/esModules/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/esModules/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -2854,6 +2860,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
runTest("js/js.translator/testData/box/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -2395,6 +2395,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
runTest("js/js.translator/testData/box/esModules/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/esModules/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -2960,6 +2966,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
runTest("js/js.translator/testData/box/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -2289,6 +2289,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/esModules/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/esModules/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -2854,6 +2860,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/export/exportInterface.kt");
}
@Test
@TestMetadata("exportInterfaceWithoutClases.kt")
public void testExportInterfaceWithoutClases() throws Exception {
runTest("js/js.translator/testData/box/export/exportInterfaceWithoutClases.kt");
}
@Test
@TestMetadata("exportNestedClass.kt")
public void testExportNestedClass() throws Exception {
@@ -0,0 +1,36 @@
// KT-60131
// IGNORE_BACKEND: JS
// RUN_PLAIN_BOX_FUNCTION
// DONT_TARGET_EXACT_BACKEND: JS
// ES_MODULES
// MODULE: export_interface
// FILE: lib.kt
@JsExport
interface BaseInterface {
val prop: String
}
class Impl : BaseClass("foobar")
open class BaseClass(private val _prop: String) : BaseInterface {
final override val prop: String get() = _prop
}
@JsExport
fun getImpl(): BaseInterface = Impl()
@JsExport
fun getBase(): BaseInterface = BaseClass("base")
// FILE: main.mjs
// ENTRY_ES_MODULE
import { getBase, getImpl } from "./exportInterfaceWithoutClases-export_interface_v5.mjs"
export function box() {
if (getBase().prop != "base") return "fail 1";
if (getImpl().prop != "foobar") return "fail 2";
return "OK"
}
@@ -0,0 +1,33 @@
// KT-60131
// IGNORE_BACKEND: JS
// RUN_PLAIN_BOX_FUNCTION
// INFER_MAIN_MODULE
// SKIP_DCE_DRIVEN
// MODULE: export_interface
// FILE: lib.kt
@JsExport
interface BaseInterface {
val prop: String
}
class Impl : BaseClass("foobar")
open class BaseClass(private val _prop: String) : BaseInterface {
final override val prop: String get() = _prop
}
@JsExport
fun getImpl(): BaseInterface = Impl()
@JsExport
fun getBase(): BaseInterface = BaseClass("base")
// FILE: test.js
function box() {
if (this["export_interface"].getBase().prop != "base") return "fail 1";
if (this["export_interface"].getImpl().prop != "foobar") return "fail 2";
return "OK"
}