[K/JS] Make available transitive reexport for ES modules
This commit is contained in:
+3
-2
@@ -139,8 +139,9 @@ internal fun CrossModuleReferences.crossModuleReferencesHashForIC() = HashCalcul
|
||||
update(importedModule.relativeRequirePath ?: "")
|
||||
}
|
||||
|
||||
updateForEach(transitiveJsExportFrom) { exportFrom ->
|
||||
update(exportFrom.toString())
|
||||
updateForEach(transitiveJsExportFrom) { transitiveExport ->
|
||||
update(transitiveExport.internalName.toString())
|
||||
update(transitiveExport.externalName)
|
||||
}
|
||||
|
||||
updateForEach(exports.keys.sorted()) { tag ->
|
||||
|
||||
+4
-2
@@ -161,7 +161,7 @@ private class JsIrModuleCrossModuleReferecenceBuilder(
|
||||
}
|
||||
|
||||
val transitiveExport = transitiveJsExportFrom.mapNotNull {
|
||||
if (it.hasJsExports) import(it) else null
|
||||
if (!it.hasJsExports) null else CrossModuleTransitiveExport(import(it), it.externalModuleName)
|
||||
}
|
||||
return CrossModuleReferences(
|
||||
moduleKind,
|
||||
@@ -190,10 +190,12 @@ private class JsIrModuleCrossModuleReferecenceBuilder(
|
||||
|
||||
class CrossModuleImport(val exportedAs: String, val moduleExporter: JsName)
|
||||
|
||||
class CrossModuleTransitiveExport(val internalName: JsName, val externalName: String)
|
||||
|
||||
class CrossModuleReferences(
|
||||
val moduleKind: ModuleKind,
|
||||
val importedModules: List<JsImportedModule>, // additional Kotlin imported modules
|
||||
val transitiveJsExportFrom: List<JsName>, // the list of modules which provide their js exports for transitive export
|
||||
val transitiveJsExportFrom: List<CrossModuleTransitiveExport>, // the list of modules which provide their js exports for transitive export
|
||||
val exports: Map<String, String>, // tag -> index
|
||||
val imports: Map<String, CrossModuleImport>, // tag -> import statement
|
||||
) {
|
||||
|
||||
+14
-4
@@ -173,10 +173,20 @@ class Merger(
|
||||
}
|
||||
|
||||
private fun transitiveJsExport(): List<JsStatement> {
|
||||
val internalModuleName = ReservedJsNames.makeInternalModuleName()
|
||||
val exporterName = ReservedJsNames.makeJsExporterName()
|
||||
return crossModuleReferences.transitiveJsExportFrom.map {
|
||||
JsInvocation(JsNameRef(exporterName, it.makeRef()), internalModuleName.makeRef()).makeStmt()
|
||||
return if (isEsModules) {
|
||||
crossModuleReferences.transitiveJsExportFrom.map {
|
||||
JsExport(JsExport.Subject.All, it.externalName)
|
||||
}
|
||||
} else {
|
||||
val internalModuleName = ReservedJsNames.makeInternalModuleName()
|
||||
val exporterName = ReservedJsNames.makeJsExporterName()
|
||||
|
||||
crossModuleReferences.transitiveJsExportFrom.map {
|
||||
JsInvocation(
|
||||
JsNameRef(exporterName, it.internalName.makeRef()),
|
||||
internalModuleName.makeRef()
|
||||
).makeStmt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -2367,6 +2367,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/esModules/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reexport.kt")
|
||||
public void testReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/box/esModules/export/reexport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedModuleName.kt")
|
||||
public void testReservedModuleName() throws Exception {
|
||||
@@ -2920,6 +2926,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/export/overridenMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reexport.kt")
|
||||
public void testReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/reexport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedModuleName.kt")
|
||||
public void testReservedModuleName() throws Exception {
|
||||
|
||||
+12
@@ -2367,6 +2367,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/esModules/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reexport.kt")
|
||||
public void testReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/box/esModules/export/reexport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedModuleName.kt")
|
||||
public void testReservedModuleName() throws Exception {
|
||||
@@ -2920,6 +2926,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/export/overridenMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reexport.kt")
|
||||
public void testReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/reexport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedModuleName.kt")
|
||||
public void testReservedModuleName() throws Exception {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// IGNORE_FIR
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// ES_MODULES
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
|
||||
// MODULE: lib1
|
||||
// FILE: lib1.kt
|
||||
@JsExport
|
||||
fun bar() = "O"
|
||||
|
||||
// MODULE: lib2(lib1)
|
||||
// FILE: lib2.kt
|
||||
|
||||
@JsExport
|
||||
fun baz() = "K"
|
||||
|
||||
// MODULE: main(lib2)
|
||||
// FILE: main.kt
|
||||
|
||||
@JsExport
|
||||
fun result(o: String, k: String) = o + k
|
||||
|
||||
// FILE: entry.mjs
|
||||
// ENTRY_ES_MODULE
|
||||
import { bar, baz, result } from "./reexport_v5.mjs";
|
||||
|
||||
export function box() {
|
||||
const o = bar();
|
||||
const k = baz();
|
||||
return result(o, k);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// IGNORE_FIR
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
// INFER_MAIN_MODULE
|
||||
|
||||
// MODULE: lib1
|
||||
// FILE: lib1.kt
|
||||
@JsExport
|
||||
fun bar() = "O"
|
||||
|
||||
// MODULE: lib2(lib1)
|
||||
// FILE: lib2.kt
|
||||
|
||||
@JsExport
|
||||
fun baz() = "K"
|
||||
|
||||
// MODULE: main(lib2)
|
||||
// FILE: main.kt
|
||||
|
||||
@JsExport
|
||||
fun result(o: String, k: String) = o + k
|
||||
|
||||
// FILE: test.js
|
||||
function box() {
|
||||
const { bar, baz, result } = this.main;
|
||||
const o = bar();
|
||||
const k = baz();
|
||||
return result(o, k);
|
||||
}
|
||||
Reference in New Issue
Block a user