I've noticed an weird behavior with Kotlin/JS's `e...
# javascript
m
I've noticed an weird behavior with Kotlin/JS's
eval
that I haven't seen anyone talking about it before: For some reason, when I include an
eval
call in my code (doesn't matter what the content of the eval is), the production bundle size increases from 1.94 MiB to 2.27 MiB
c
Trying it in the playground, it doesn't make any difference on output size (diff of the generated JS in screenshot) Without evalWith eval
So, it's probably specific to your situation ; if you can reproduce it, it's probably worth reporting it: https://kotl.in/issue
e
Might happen because Kotlin's DCE isn't as effective. But not sure tbh.
t
Instead of
eval
and
js
you can use more strict and flexible
JsFunction
(example)
c
@turansky what's the benefit compared to declaring an
external
? I find JsFunction particularly hard to read
t
what's the benefit compared to declaring an
external
?
Sorry, I don't follow
> I find JsFunction particularly hard to read Yes 🙂 External low-level API 😞
c
Honestly, I don't really understand what JsFunction is nor what it's for. Is there a documentation page for it?
t
JsFunction
- JS Function class
c
Thanks, I'll look into it
t
Also you can create async and generator functions if it's required. Example
m
my use case for eval was just "man I'm too lazy to write the FontFace external declaration so let me just use eval here..." but yeah my theory is the same as @Edoardo Luppi's DCE probably goes crazy with the eval call and doesn't remove some classes
t
Do you mean this FontFace?
m
@turansky yes! :3 wow there is a lot of external declarations in that repo (some of them I had manually written myself for my projects)
t
All stable browser declarations 😜
Also we have coroutines integration - async methods (which return
Promise
) have
suspend
companions