[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 ?: "")
|
update(importedModule.relativeRequirePath ?: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
updateForEach(transitiveJsExportFrom) { exportFrom ->
|
updateForEach(transitiveJsExportFrom) { transitiveExport ->
|
||||||
update(exportFrom.toString())
|
update(transitiveExport.internalName.toString())
|
||||||
|
update(transitiveExport.externalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateForEach(exports.keys.sorted()) { tag ->
|
updateForEach(exports.keys.sorted()) { tag ->
|
||||||
|
|||||||
+4
-2
@@ -161,7 +161,7 @@ private class JsIrModuleCrossModuleReferecenceBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val transitiveExport = transitiveJsExportFrom.mapNotNull {
|
val transitiveExport = transitiveJsExportFrom.mapNotNull {
|
||||||
if (it.hasJsExports) import(it) else null
|
if (!it.hasJsExports) null else CrossModuleTransitiveExport(import(it), it.externalModuleName)
|
||||||
}
|
}
|
||||||
return CrossModuleReferences(
|
return CrossModuleReferences(
|
||||||
moduleKind,
|
moduleKind,
|
||||||
@@ -190,10 +190,12 @@ private class JsIrModuleCrossModuleReferecenceBuilder(
|
|||||||
|
|
||||||
class CrossModuleImport(val exportedAs: String, val moduleExporter: JsName)
|
class CrossModuleImport(val exportedAs: String, val moduleExporter: JsName)
|
||||||
|
|
||||||
|
class CrossModuleTransitiveExport(val internalName: JsName, val externalName: String)
|
||||||
|
|
||||||
class CrossModuleReferences(
|
class CrossModuleReferences(
|
||||||
val moduleKind: ModuleKind,
|
val moduleKind: ModuleKind,
|
||||||
val importedModules: List<JsImportedModule>, // additional Kotlin imported modules
|
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 exports: Map<String, String>, // tag -> index
|
||||||
val imports: Map<String, CrossModuleImport>, // tag -> import statement
|
val imports: Map<String, CrossModuleImport>, // tag -> import statement
|
||||||
) {
|
) {
|
||||||
|
|||||||
+14
-4
@@ -173,10 +173,20 @@ class Merger(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun transitiveJsExport(): List<JsStatement> {
|
private fun transitiveJsExport(): List<JsStatement> {
|
||||||
val internalModuleName = ReservedJsNames.makeInternalModuleName()
|
return if (isEsModules) {
|
||||||
val exporterName = ReservedJsNames.makeJsExporterName()
|
crossModuleReferences.transitiveJsExportFrom.map {
|
||||||
return crossModuleReferences.transitiveJsExportFrom.map {
|
JsExport(JsExport.Subject.All, it.externalName)
|
||||||
JsInvocation(JsNameRef(exporterName, it.makeRef()), internalModuleName.makeRef()).makeStmt()
|
}
|
||||||
|
} 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");
|
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
|
@Test
|
||||||
@TestMetadata("reservedModuleName.kt")
|
@TestMetadata("reservedModuleName.kt")
|
||||||
public void testReservedModuleName() throws Exception {
|
public void testReservedModuleName() throws Exception {
|
||||||
@@ -2920,6 +2926,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
|
|||||||
runTest("js/js.translator/testData/box/export/overridenMethod.kt");
|
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
|
@Test
|
||||||
@TestMetadata("reservedModuleName.kt")
|
@TestMetadata("reservedModuleName.kt")
|
||||||
public void testReservedModuleName() throws Exception {
|
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");
|
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
|
@Test
|
||||||
@TestMetadata("reservedModuleName.kt")
|
@TestMetadata("reservedModuleName.kt")
|
||||||
public void testReservedModuleName() throws Exception {
|
public void testReservedModuleName() throws Exception {
|
||||||
@@ -2920,6 +2926,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/export/overridenMethod.kt");
|
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
|
@Test
|
||||||
@TestMetadata("reservedModuleName.kt")
|
@TestMetadata("reservedModuleName.kt")
|
||||||
public void testReservedModuleName() throws Exception {
|
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