All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.seskar.compiler.react.value.backend.Hooks.kt Maven / Gradle / Ivy

There is a newer version: 3.32.0
Show newest version
package seskar.compiler.react.value.backend

import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.util.isTopLevel
import org.jetbrains.kotlin.name.Name

internal fun isHookCall(
    expression: IrCall,
): Boolean {
    if (expression.dispatchReceiver != null)
        return false

    val function = expression.symbol.owner

    // are hooks toplevel only? ( potentially namespace / object )
    if (!function.isTopLevel)
        return false

    return isHookName(function.name)
}

internal fun isHookName(
    name: Name,
): Boolean {
    val id = name.identifierOrNullIfSpecial
        ?: return false

    return id.startsWith("use") &&
            id.length > 3 &&
            id[3].isUpperCase()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy