https://kotlinlang.org logo
#javascript
Title
# javascript
e

Edoardo Luppi

03/14/2024, 4:21 PM
I'm curious, why was
-Xir-generate-inline-anonymous-functions
introduced? I can't find resources on it on the internet.
a

Artem Kobzar

03/14/2024, 5:36 PM
From the commit that introduced this flag: Previously we always generated factories for contextful lambdas like this:
Copy code
fun foo(a: Int) = { a }
Copy code
function foo(a_38) {
  return foo$lambda(a_38);
}

// factory!
function foo$lambda($a) {
  return function () {
    return $a;
  };
}
After this patch, the generated code for
foo
is more concise:
Copy code
function foo(a) {
  return function() { return a; };
}
t

turansky

03/14/2024, 5:38 PM
Is it available in Kotlin
1.9.23
?
a

Artem Kobzar

03/14/2024, 5:38 PM
Yes, it should be available since
1.9.20
👍 1
t

turansky

03/14/2024, 5:42 PM
Is there
-Xir-generate-js-arrow-functions-please
option? 🙂
😆 1
e

Edoardo Luppi

03/14/2024, 5:43 PM
Thank you!
Btw, it seems it's not enabled by default. I wonder why not if it gives us a benefit.
t

turansky

03/14/2024, 5:47 PM
It can be assumption of Gradle plugins, which process js-file before Webpack for example
I had such plugins before
@Artem Kobzar It works fine for parameters, but doesn't work for variables - is it expected?
e

Edoardo Luppi

03/14/2024, 6:16 PM
Mmm interesting. You mean it doesn't capture local variables?
t

turansky

03/14/2024, 6:17 PM
Copy code
fun fn1() {
    doCall {} // works fine, local function created

    val fn2 = {} // top-level function created
}
✔️ 1