Skip to content

Commit

Permalink
Module handle. Update transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
turansky committed Nov 23, 2024
1 parent df75f40 commit a73fda8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package seskar.compiler.module.backend

import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.isTopLevel
import org.jetbrains.kotlin.name.FqName

internal const val MODULE_HANDLE_DELIMITER = "$$"

private val MODULE_HANDLE = FqName("js.module.JsModuleHandle")

internal fun IrProperty.isModuleHandle(): Boolean =
isTopLevel && hasAnnotation(MODULE_HANDLE)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package seskar.compiler.module.backend
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.name
import org.jetbrains.kotlin.ir.util.file
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import seskar.compiler.common.backend.JsFileName
import seskar.compiler.common.backend.JsName
Expand All @@ -13,21 +13,14 @@ internal class ModuleHandleTransformer(
private val context: IrPluginContext,
) : IrElementTransformerVoid() {
override fun visitProperty(declaration: IrProperty): IrStatement {
if (!declaration.isWorkerFactory())
if (!declaration.isModuleHandle())
return declaration

val fileName = declaration.file.name.removeSuffix(".kt")
declaration.file.annotations += JsFileName(context, "${fileName}__worker__factory")

val jsName = sequenceOf(
fileName,
declaration.name.identifier,
).joinToString(
separator = WORKER_DELIMITER,
prefix = WORKER_DELIMITER,
postfix = WORKER_DELIMITER,
)
val moduleId = declaration.fqNameWhenAvailable!!.asString()
val fileName = moduleId.replace('.', '_') + "__module__handle"
declaration.file.annotations += JsFileName(context, fileName)

val jsName = MODULE_HANDLE_DELIMITER + fileName + MODULE_HANDLE_DELIMITER
declaration.annotations += JsName(context, jsName)

return super.visitProperty(declaration)
Expand Down

This file was deleted.

0 comments on commit a73fda8

Please sign in to comment.