JaniruTEC
11/15/2023, 6:49 PM@JsName
to "Quill" or leaving it out doesn't help.
Imports generated by compiler:
function (_, $module$parchment, $module$quill, kotlin_kotlin) {
'use strict';
//region block: imports
var default_0 = $module$parchment.default;
var default_1 = $module$quill.default;
//snip
}
My wrapper class:
@JsName("default")
external open class Quill : EventEmitter {
constructor(container: String)
//snip
companion object {
//snip
fun import(path: String): Any
}
}
quill.js
import Quill from './core';
//snip
export default Quill;
/core/quill.js
//snip
class Quill {
//snip
static import(name) {
if (this.imports[name] == null) {
debug.error(`Cannot import ${name}. Are you sure it was registered?`);
}
return this.imports[name];
}
//snip
constructor(container, options = {}) {
//snip
}
//snip
}
export { expandConfig, overload, Quill as default };
Artem Kobzar
11/15/2023, 7:03 PMJaniruTEC
11/15/2023, 7:10 PMvar default_1 = $module$quill.default;
Quill.js exposes the "Quill" class/constructor as default export for the Quill module.
So when I use the constructor in kotlin, it tries to access that default using the above import.
$module$quill
is the actual module/constructor/class, the default
property is undefined.
I expect kotlin to point to the actual module (so $module$quill
) instead of the undefined "default" object. According to prior advice given here and on the internet JsName("default")
is supposed to achieve that. If I use no JsName, it generates $module$quill.<Name>
instead, which is equally unhelpful.
The file containing the wrapper class on kotlin was marked with the following by dukat:
@file:JsModule("quill")
@file:JsNonModule
turansky
11/20/2023, 8:49 AM@JsModule("quill")
external object quill
fun main() {
console.log("Quill module", quill)
console.log("Quill module default", quill.asDynamic().default)
}
2. Use commonjs
module kind and repeat step 1JaniruTEC
11/21/2023, 1:39 AMoutput.libraryTarget = "commonjs"
for both - library and main project - as well as useCommonJs()
for the library project. None of those combinations changed anything.
Setting useCommonJs()
for the main project caused issues when loading the kotlin std lib.
Also apart from when I set useCommonJs()
for the main project, I had to use @JsNonModule
or I would get the following compilation error:
> When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModuleturansky
11/21/2023, 2:52 AMQuill module function Quill(container)Looks like class, which you need
JaniruTEC
11/21/2023, 1:43 PMvar default_1 = $module$quill.default;
default_1
as constructor, which is undefined. I can't access the $module$quill
turansky
11/21/2023, 1:44 PM@JsModule("quill")
external class Quill
?JaniruTEC
11/21/2023, 1:47 PM@file:JsModule("quill")
from the file?
If I understood correctly from the prior discussion that I linked, @JsName("default")
should mark the default export, which is exactly what I want.turansky
11/21/2023, 1:48 PMdefault
inside module according your test resultsJaniruTEC
11/21/2023, 1:51 PMJaniruTEC
11/22/2023, 1:07 AM