[JS IR] Generate main method call only for main module
This commit is contained in:
+9
-6
@@ -96,7 +96,8 @@ class IrModuleToJsTransformer(
|
||||
others,
|
||||
exportedModule,
|
||||
namer,
|
||||
refInfo
|
||||
refInfo,
|
||||
generateMainCall = true
|
||||
)
|
||||
|
||||
val dependencies = others.mapIndexed { index, module ->
|
||||
@@ -109,7 +110,8 @@ class IrModuleToJsTransformer(
|
||||
others.drop(index + 1),
|
||||
ExportedModule(moduleName, exportedModule.moduleKind, exportedDeclarations),
|
||||
namer,
|
||||
refInfo
|
||||
refInfo,
|
||||
generateMainCall = false
|
||||
)
|
||||
}.reversed()
|
||||
|
||||
@@ -130,7 +132,8 @@ class IrModuleToJsTransformer(
|
||||
dependencies: Iterable<IrModuleFragment>,
|
||||
exportedModule: ExportedModule,
|
||||
namer: NameTables,
|
||||
refInfo: CrossModuleReferenceInfo
|
||||
refInfo: CrossModuleReferenceInfo,
|
||||
generateMainCall: Boolean = true
|
||||
): CompilationOutputs {
|
||||
|
||||
val nameGenerator = refInfo.withReferenceTracking(
|
||||
@@ -161,8 +164,6 @@ class IrModuleToJsTransformer(
|
||||
val globalNames = NameTable<String>(namer.globalNames)
|
||||
val exportStatements = ExportModelToJsStatements(internalModuleName, nameGenerator, { globalNames.declareFreshName(it, it)}).generateModuleExport(exportedModule)
|
||||
|
||||
val callToMain = generateCallToMain(modules, rootContext)
|
||||
|
||||
val (crossModuleImports, importedKotlinModules) = generateCrossModuleImports(nameGenerator, modules, dependencies, { JsName(sanitizeName(it)) })
|
||||
val crossModuleExports = generateCrossModuleExports(modules, refInfo, internalModuleName)
|
||||
|
||||
@@ -181,7 +182,9 @@ class IrModuleToJsTransformer(
|
||||
statements.addWithComment("block: imports", importStatements + crossModuleImports)
|
||||
statements += moduleBody
|
||||
statements.addWithComment("block: exports", exportStatements + crossModuleExports)
|
||||
statements += callToMain
|
||||
if (generateMainCall) {
|
||||
statements += generateCallToMain(modules, rootContext)
|
||||
}
|
||||
statements += JsReturn(internalModuleName.makeRef())
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+5
@@ -880,6 +880,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/objectIsObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("onlyMainModuleCall.kt")
|
||||
public void testOnlyMainModuleCall() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/onlyMainModuleCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelExtension.kt")
|
||||
public void testTopLevelExtension() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/topLevelExtension.kt");
|
||||
|
||||
+5
@@ -880,6 +880,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/objectIsObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("onlyMainModuleCall.kt")
|
||||
public void testOnlyMainModuleCall() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/onlyMainModuleCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelExtension.kt")
|
||||
public void testTopLevelExtension() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/topLevelExtension.kt");
|
||||
|
||||
+5
@@ -880,6 +880,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/objectIsObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("onlyMainModuleCall.kt")
|
||||
public void testOnlyMainModuleCall() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/onlyMainModuleCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelExtension.kt")
|
||||
public void testTopLevelExtension() throws Exception {
|
||||
runTest("js/js.translator/testData/box/crossModuleRefIR/topLevelExtension.kt");
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// SPLIT_PER_MODULE
|
||||
// CALL_MAIN
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package lib
|
||||
|
||||
var log: String = ""
|
||||
|
||||
val hack = ::main
|
||||
|
||||
fun main() {
|
||||
log += "fail"
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
package main
|
||||
|
||||
import lib.*
|
||||
|
||||
fun main() {
|
||||
log += "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return log
|
||||
}
|
||||
Reference in New Issue
Block a user