Hi, I was using `inline` functions in Kotlin JS, a...
# javascript
p
Hi, I was using
inline
functions in Kotlin JS, and I saw that they are not really compiled as-is and that
defineInlineFunction
is used instead. Therefore, I am wondering, what's the purpose of
defineInlineFunction
? And is there any way to have a real
inline
in Kotlin JS (with an annotation for instance) ? PS: I am using the legacy JS compiler, is this behavior different in IR ?
K 1
r
In IR inline functions seem to work as expected.
👍 1
b
It should work for the old compiler too.
defineInlineFunction
is a marker to help compiler to find function for inline to use-site.
p
Thanks @Robert Jaros I will test it ASAP with IR. It's great if it's working as expected.
@bashor Thanks for your answer. I am not sure if it's my sepcific use case which is not working, but I am having issue with inline with the legacy compiler. I created an example on Kotlin playground https://pl.kotl.in/up2-FW2iM. With my code, I end up with
myTestVal = myInlineFun$lambda(myTestVal$lambda);
which is not the behavior I expect. This matters to me because I would like to have react functional components with the right type.name (defined by the JS variable name). And my usage works when I am copy/pasting my code strictly (because the name of the variable is correct) but not when using an inline function. Any idea on what I am doing wrong ? Or misunderstood ?
b
I’m not sure I fully understand what do you expect, but in this example crossinline is not supported in the old JS compiler
p
codeWithInline_kt.kt
Ok so thanks @bashor for precising that crossinline is not supported in the legacy compiler and sorry for not expressing correctly my issue. In fact, my current code uses an anonymous function once compiled with the legacy compiler. Therefore, React identify the component as Anonymous (and I would like it to have the type name of my variable name as in JSX). Support for crossinline should fix this issue for me. Is crossinline supported in IR ?
codeCopyPasted_kt.kt
With the first snippet of code I have a type name
Anonymous
(using React Components) and with the second snippet I have a type name
myReactFunctionalComponent$lambda
(which is easier to work with).
b
Support for crossinline should fix this issue for me. Is crossinline supported in IR ?
yes, but names and layout could be different
👍 1
p
Even in dev mode ?
👌 1