[JS IR] Fix cross-module import/export in case per-module splitting
This commit is contained in:
committed by
Roman Artemev
parent
8d61e9ba21
commit
136d86e552
+8
-9
@@ -8,17 +8,16 @@ package org.jetbrains.kotlin.ir.backend.js.export
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsAstUtils
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.defineProperty
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.jsAssignment
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTable
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.IrNamer
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
|
||||
|
||||
class ExportModelToJsStatements(
|
||||
private val internalModuleName: JsName,
|
||||
private val nameTables: NameTables
|
||||
private val namer: IrNamer,
|
||||
private val declareNewNamespace: (String) -> String
|
||||
) {
|
||||
private val namespaceToRefMap = mutableMapOf<String, JsNameRef>()
|
||||
private val globalNames = NameTable<String>(nameTables.globalNames)
|
||||
|
||||
fun generateModuleExport(module: ExportedModule): List<JsStatement> {
|
||||
return module.declarations.flatMap { generateDeclarationExport(it, JsNameRef(internalModuleName)) }
|
||||
@@ -34,7 +33,7 @@ class ExportModelToJsStatements(
|
||||
for (element in elements) {
|
||||
val newNamespace = "$currentNamespace$$element"
|
||||
val newNameSpaceRef = namespaceToRefMap.getOrPut(newNamespace) {
|
||||
val varName = globalNames.declareFreshName(newNamespace, newNamespace)
|
||||
val varName = declareNewNamespace(newNamespace)
|
||||
val varRef = JsNameRef(varName)
|
||||
val namespaceRef = JsNameRef(element, currentRef)
|
||||
statements += JsVars(
|
||||
@@ -60,7 +59,7 @@ class ExportModelToJsStatements(
|
||||
listOf(
|
||||
jsAssignment(
|
||||
JsNameRef(declaration.name, namespace),
|
||||
JsNameRef(nameTables.getNameForStaticDeclaration(declaration.ir))
|
||||
JsNameRef(namer.getNameForStaticDeclaration(declaration.ir))
|
||||
).makeStmt()
|
||||
)
|
||||
}
|
||||
@@ -68,8 +67,8 @@ class ExportModelToJsStatements(
|
||||
is ExportedConstructor -> emptyList()
|
||||
|
||||
is ExportedProperty -> {
|
||||
val getter = declaration.irGetter?.let { JsNameRef(nameTables.getNameForStaticDeclaration(it)) }
|
||||
val setter = declaration.irSetter?.let { JsNameRef(nameTables.getNameForStaticDeclaration(it)) }
|
||||
val getter = declaration.irGetter?.let { JsNameRef(namer.getNameForStaticDeclaration(it)) }
|
||||
val setter = declaration.irSetter?.let { JsNameRef(namer.getNameForStaticDeclaration(it)) }
|
||||
listOf(defineProperty(namespace, declaration.name, getter, setter).makeStmt())
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ class ExportModelToJsStatements(
|
||||
val klassExport = jsAssignment(
|
||||
newNameSpace,
|
||||
JsNameRef(
|
||||
nameTables.getNameForStaticDeclaration(
|
||||
namer.getNameForStaticDeclaration(
|
||||
declaration.ir
|
||||
)
|
||||
)
|
||||
|
||||
+2
-1
@@ -149,7 +149,8 @@ class IrModuleToJsTransformer(
|
||||
val moduleBody = generateModuleBody(modules, rootContext)
|
||||
|
||||
val internalModuleName = JsName("_")
|
||||
val exportStatements = ExportModelToJsStatements(internalModuleName, namer).generateModuleExport(exportedModule)
|
||||
val globalNames = NameTable<String>(namer.globalNames)
|
||||
val exportStatements = ExportModelToJsStatements(internalModuleName, nameGenerator, { globalNames.declareFreshName(it, it)}).generateModuleExport(exportedModule)
|
||||
|
||||
val callToMain = generateCallToMain(modules, rootContext)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user