Apparently you can not mark a common class with `@...
# webassembly
a
Apparently you can not mark a common class with
@JsExports
and also have a wasm target. e.g.
commonMain/kotlin/sample/User.kt
Copy code
package sample

import kotlin.js.JsExport

@JsExport
class User
fails with
Copy code
> Task compileKotlinWasm FAILED
e: sample/src/commonMain/kotlin/sample/User.kt This annotation is not applicable to target 'class'
If I move the annotation up, to file level, like so
Copy code
@file:JsExport

@file:JsExport
package koncurrent

import kotlin.js.JsExport

class User
fails with
Copy code
> Task compileKotlinWasm FAILED
e: sample/src/commonMain/kotlin/sample/User.kt This annotation is not applicable to target 'file' and use site target '@file'
Any known workarround?? Some supressions perhaps??
@turansky So sorry for tagging you here. But you are the
Suppress
king that I know about. Any help?
s
Thank you for bringing this up, we need to fix this. A workaround for defining annotation that works only in K/JS:
Copy code
// common:
expect annotation class JsTargetOnlyJsExport() 

@JsTargetOnlyJsExport
class User

// js:
actual typealias JsTargetOnlyJsExport = JsExport  // Real JsExport

// wasm:
actual annotation class JsTargetOnlyJsExport  // Fake JsExport, does nothing
Alternatively you can use experimental @OptionalExpectation on JsTargetOnlyJsExport to avoid defining fake actuals in non-JS platforms.
a
I thought about that, but then I was just adding wasm support to a very large code base. The efforts it would take migrate to the new
JSTargetOnlyJsExport
would be tremendous. If fixing this won't take that much time, I can definitely wait
s
I see. I imagine that suppression via
@Suppress("WRONG_ANNOTATION_TARGET")
would take about the same effort, but it would be a lot more hacky.
a
That's actually a better argument than mine. I think I'll take your approach then. at least for now
Somehow I expected kotlin 1.9.0 will allow
@JsExport
on common main. Is there a ticket I can follow up with?
@Svyatoslav Kuzmich [JB] is this fixed?? or do we still need a workaround?
s
Not fixed yet. Could you please file an issue?
a
👍 3
thank you color 3
👍🏾 1