Hi Everyone, I have a question regarding the es201...
# javascript
m
Hi Everyone, I have a question regarding the es2015 compilation target. I am trying to introduce it into our multiplatform project. I am using the cryptography-kotlin multiplatform library. When I set the Kotlin JS compilation target to es2015, I get this error: https://github.com/whyoleg/cryptography-kotlin/blob/69b77a88b4b81109704475ed02be48[…]cryptography-core/src/commonMain/kotlin/CryptographyProvider.kt I get it when we access the
Cryptographyprovider.Default
companion object property. The following line should register the WebCrypto provider on the JS platform: https://github.com/whyoleg/cryptography-kotlin/blob/69b77a88b4b81109704475ed02be48[…]webcrypto/src/jsMain/kotlin/WebCryptoCryptographyProvider.js.kt Can it happen that the
initHook
variable is optimised out by the compiler during DCE because it is not used in our code? Once I call
CryptographyProvider.WebCrypto
, the error disappears. If this is the case, what shouldn't the
initHook
variable be replaced with a main function or some other alternative? Thank you!
@Oleg Yukhnevich could you maybe help me with this one? 🙂 thank you!
o
Hey! That's an interesting case 🙂 > Can it happen that the
initHook
variable is optimised out by the compiler during DCE Probably this is the reason - I think it's possible to check produced by compiler JS files to check if it's really removed or just not called I will try to investigate this on weekend, but probably it's an issue in Kotlin Compiler regarding handling of
EagerInitialization
m
Thank you very much @Oleg Yukhnevich
a
It's definitely a bug with EagerInitialization in ES2015 mode.
m
Thanks for checking! Where should this be reported?
a
Could you please create a ticket in Kotlin YouTrack?
o
I will create an issue later today with a smaller reproducer based on https://github.com/whyoleg/KT-51626-reproducer But so far, I see that the code isn’t optimized out and present in .mjs file, though, this file is not imported anywhere So this is kind-a the same as https://youtrack.jetbrains.com/issue/KT-51626, but the workaround with ‘@JsExport’ mentioned there doesn’t work anymore
m
Thank you!