Edoardo Luppi
07/03/2023, 11:09 AMEdoardo Luppi
07/03/2023, 8:58 PMpublic expect fun ZSocket(charset: String): ZSocket
`jsMain`:
@JsExport
public actual fun ZSocket(charset: String): ZSocket { ... }
Notice I'm exporting a function with same name as an interface
.
No warnings emitted.
Resulting ES JS code: see screenshot.
So this breaks at runtime when importing via TS declaration:
export declare interface ZSocket {
...
export declare function ZSocket(charset: string): ZSocket;
Edoardo Luppi
07/04/2023, 10:52 AMtasks.withType<Kotlin2JsCompile>().configureEach {
kotlinOptions {
sourceMap = true
sourceMapEmbedSources = "always"
sourceMapNamesPolicy = "fully-qualified-names"
}
}
The generated source map file is as following:
{
"version": 3,
"sources": [
"../../../../../../src/commonMain/kotlin/...",
"../../../../../../src/jsMain/kotlin/...",
...
],
"sourcesContent": [ ... ], // here I can see my source code
"names": [ ... ],
"mappings": "..."
}
In the VS Code side I've configured the launch.json
task file as following:
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
"sourceMaps": true,
"pauseForSourceMap": true
}
But yet I can't get source maps to work. I still debug and see the compiled JS.Adam S
07/04/2023, 12:47 PMEdoardo Luppi
07/04/2023, 8:06 PMAdam S
07/04/2023, 9:07 PMawait
, which is only possible inside async
functions. This is incongruous with JVM and Native, where it’s always possible to block the thread, and no async function
keyword is required.
So, I was thinking. would it be possible for a Kotlin compiler plugin to edit the Kotlin/JS compiler so it generates a async function
instead of a regular function wherever runBlocking {}
is used in a Kotlin/JS function?Edoardo Luppi
07/05/2023, 1:03 PMAny?
type, but the API is not explicit anymore.
- https://youtrack.jetbrains.com/issue/KT-60140
Fix the naming ourselves, just be more careful at the moment.
- https://youtrack.jetbrains.com/issue/KT-60141
Can't do anything about it, but it's only inside IntelliJ IDEA, so we should be safe.
- No equivalent of @JvmStatic
, to avoid dealing with MyObject.getInstance().MY_CONST
in TypeScript.
We'd like <http://MyObject.MY|MyObject.MY>_CONST
or MyObject.myMethod()
.
- https://youtrack.jetbrains.com/issue/KT-53993
We want to be able to customize the outputted JS code if necessary (especially if the Kotlin team cannot release a fix in a timeframe that works for us).
Should never happen, but better safe than sorry.Seth Madison
07/06/2023, 6:14 AMtoString()
methods are huge and do not minify or compress well at all. Tree shaking can’t get rid of them because they’re member functions. It would be awesome if there were a compiler flag to disable toString()
generation for production builds. I realize some code might break, but I think that by-and-large folks use the nice toString()
methods for debugging and don’t need them in prod bundles. Anybody have any other clever ideas?Albin Theander
07/06/2023, 11:41 AMAndreiBogdan
07/06/2023, 2:10 PMclass SharedBookService {
private val bookRepository = BookRepository()
/**
* @return an array of book permanent ids
*/
fun getAssignedBooks(): SingleWrapper<List<String>> {
return singleFromCoroutine {
bookRepository.callAssignedBooks()
}
.subscribeOn(ioScheduler)
.observeOn(mainScheduler)
.onErrorReturn { t ->
Console.apiError.log("getAssignedBooks :: " + t.message)
listOf()
}
.wrap()
}
}
Donny
07/06/2023, 3:58 PMDonny
07/06/2023, 11:09 PM@JsExport.Ignore
val Double.const: KslValueFloat1
get() = KslValueFloat1(this.toFloat())
@JsExport.Ignore
val Float.const: KslValueFloat1
get() = KslValueFloat1(this)
@JsExport.Ignore
val Float.const2: KslValueFloat2
get() = KslValueFloat2(this, this)
@JsExport.Ignore
val Float.const3: KslValueFloat3
get() = KslValueFloat3(this, this, this)
@JsExport.Ignore
val Float.const4: KslValueFloat4
get() = KslValueFloat4(this, this, this, this)
The error is "JavaScript name (<get-const>) generated for this declaration clashes with another declaration: fun Vec4i.`<get-const>`(): KslValueInt4". I've tried to ignore. How can I get past this without changing the code?Tuna
07/07/2023, 8:22 AMAndreiBogdan
07/07/2023, 10:09 AMenum class QuizSearchType {
WITH_QUIZ,
WITH_NO_QUIZ
}
@Suppress("NON_EXPORTABLE_TYPE")
@JsExport
object QuizSearchTypeJs {
val with_quiz = QuizSearchType.WITH_QUIZ
val with_no_quiz = QuizSearchType.WITH_NO_QUIZ
}
List<QuizSearchType>
, so I guess I'll need to use Array<QuizSearchTypeJs>
but ... is that right ?! It's an object class with 2 fields inside it ... they're data type is not QuizSearchTypeJs
... I'm a bit confused.Edoardo Luppi
07/07/2023, 10:25 AMcommonMain
. Weren't enum exports prohibited?Ivan Cagle (IvanEOD)
07/07/2023, 2:27 PMexternal class JavascriptComponent // -- properly defined elsewhere
// declare var Root : JavascriptComponent | any;
external var Root: RootUnion
sealed external class RootUnion
fun RootUnion.asJavascriptComponent(): JavascriptComponent = asDynamic().unsafeCast<JavascriptComponent>()
fun RootUnion.asAny(): Any = asDynamic().unsafeCast<Any>()
Donny
07/07/2023, 3:16 PM: java.lang.NullPointerException
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportClass(ExportModelGenerator.kt:449)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportOrdinaryClass(ExportModelGenerator.kt:253)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportClass(ExportModelGenerator.kt:73)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportDeclaration(ExportModelGenerator.kt:61)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.generateExport(ExportModelGenerator.kt:37)
at org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer.generateExportWithExternals(IrModuleToJsTransformer.kt:192)
at org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer.associateIrAndExport(IrModuleToJsTransformer.kt:123)
at org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer.makeJsCodeGenerator(IrModuleToJsTransformer.kt:168)
at org.jetbrains.kotlin.cli.js.K2JsIrCompiler$Ir2JsTransformer.makeJsCodeGenerator(K2JsIrCompiler.kt:156)
at org.jetbrains.kotlin.cli.js.K2JsIrCompiler$Ir2JsTransformer.compileAndTransformIrNew(K2JsIrCompiler.kt:160)
at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:403)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:181)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:72)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1486)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1589)
Tóth István Zoltán
07/08/2023, 4:08 AMDonny
07/09/2023, 2:05 PMAndreiBogdan
07/10/2023, 6:20 AMjs(IR) {
moduleName = "kmm-lib"
nodejs {
binaries.library()
}
useCommonJs()
generateTypeScriptDefinitions()
}
but i'm getting Unresolved reference: generateTypeScriptDefinitions
when compiling it.
Why would that be ? 😞 Is there something else that also needs to be configured ?!Tóth István Zoltán
07/11/2023, 4:29 AMPiotr Krzemiński
07/11/2023, 7:10 PMEugene Maksymenko
07/11/2023, 9:39 PMDonny
07/12/2023, 7:43 AMAssets
that inherits from CoroutineScope
. It has a number of suspend functions. I @JsExport.Ignore
them. However, they appear to still be defined in the built Javascript:
var $de = <http://_.de|_.de> || (<http://_.de|_.de> = {});
var $de$fabmax = $de.fabmax || ($de.fabmax = {});
var $de$fabmax$kool = $de$fabmax.kool || ($de$fabmax.kool = {});
defineProp($de$fabmax$kool, 'Assets', Assets_getInstance, VOID);
$de$fabmax$kool.Assets.$loadBlobAssetCOROUTINE$1 = $loadBlobAssetCOROUTINE$1;
$de$fabmax$kool.Assets.$loadTextureDataCOROUTINE$2 = $loadTextureDataCOROUTINE$2;
$de$fabmax$kool.Assets.$loadTextureAtlasDataCOROUTINE$3 = $loadTextureAtlasDataCOROUTINE$3;
$de$fabmax$kool.Assets.$loadCubeMapTextureDataCOROUTINE$4 = $loadCubeMapTextureDataCOROUTINE$4;
$de$fabmax$kool.Assets.$loadTexture1dCOROUTINE$5 = $loadTexture1dCOROUTINE$5;
$de$fabmax$kool.Assets.$loadTexture2dCOROUTINE$6 = $loadTexture2dCOROUTINE$6;
$de$fabmax$kool.Assets.$loadTexture2dCOROUTINE$7 = $loadTexture2dCOROUTINE$7;
$de$fabmax$kool.Assets.$loadTexture3dCOROUTINE$8 = $loadTexture3dCOROUTINE$8;
$de$fabmax$kool.Assets.$loadTexture3dCOROUTINE$9 = $loadTexture3dCOROUTINE$9;
$de$fabmax$kool.Assets.$loadCubeMapCOROUTINE$10 = $loadCubeMapCOROUTINE$10;
$de$fabmax$kool.Assets.$loadCubeMapCOROUTINE$11 = $loadCubeMapCOROUTINE$11;
Somehow, I don't know why, the first COROUTINE assignment seems to cause the Assets object to be initialized (lazy instantiation at first reference), which leads to errors for me since it expects a number of things to be defined before that initialization. Is this the expected behavior?msoulatre
07/12/2023, 1:32 PMpackage.json
of my multiplatform project with compilations["main"].packageJson
.
Not sure if this should be considered a bug and if there are alternatives. More details in thread.
edit: turned out to be an issue with gradle caching/serialization so some data was not available in the packageJson closure, see thread.Donny
07/12/2023, 8:53 PMimport kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.js.JsExport
sealed class DeferredClass(val successful: Boolean)
@JsExport
object SingletonWithCoroutine : CoroutineScope {
@JsExport.Ignore
internal val job = Job()
@JsExport.Ignore
private const val NUM_LOAD_WORKERS = 8
@JsExport.Ignore
override val coroutineContext: CoroutineContext
get() = job
@JsExport.Ignore
suspend fun testSuspend(assetPath: String): Unit {
val deferred = Deferred()
val loaded = deferred.awaiting.await()
}
@JsExport.Ignore
private class Deferred(val awaiting: CompletableDeferred<DeferredClass> = CompletableDeferred(job))
@JsExport.Ignore
var test = myFun()
private fun myFun() {
throw Exception("This should only be thrown the first time this is referenced")
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="node_modules/singleton/kotlin-kotlin-stdlib-js-ir.js"></script>
<script src="node_modules/singleton/88b0986a7186d029-atomicfu-js-ir.js"></script>
<script src="node_modules/singleton/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js"></script>
<script src="node_modules/singleton/singleton.js"></script>
</head>
<body>
</body>
</html>
manoj s
07/14/2023, 12:01 PMPavel Pristalov
07/14/2023, 3:59 PMdiv {
css {
margin = 30.px
display = Display.inlineBlock
}
div {
// first component
}
div {
// second component
}
}
georgi
07/14/2023, 11:01 PM@file:JsModule("@google-cloud/pubsub")
@file:JsNonModule
@JsName("PubSub")
external class GoogleCloudPubSub {
fun topic(name: String): GoogleCloudPubSubTopic
}
external class GoogleCloudPubSubTopic {
fun exists(): Promise<Boolean>
}
Elsewhere I'm using this as
launch {
val topic = GoogleCloudPubSub().topic("blah-blah")
val result = topic.exists().await()
println(result)
if (result) { println("Exists") } else { println("Doesn't exist") }
}
The first print correctly shows true
| false
for the result of exists()
. However, the if
statement never runs even if result
is true
- if I do something like this val result = topic.exists().await().toString()._toBoolean_()
it works fine.
Any ideas as to why it's happening? Thanks in advance 🙏Ahmed na
07/15/2023, 3:58 AM* What went wrong:
Failed to query the value of task ':annotations:jsPackageJson' property 'npmResolutionManager'.
> Could not isolate value org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager$Parameters_Decorated@64029766 of type KotlinNpmResolutionManager.Parameters
> Could not serialize value of type Build_gradle...