[K/JS] Add support of compilation with ES-classes

This commit is contained in:
Artem Kobzar
2023-01-17 18:14:17 +00:00
committed by Space Team
parent 8d728d4f53
commit 71486a321c
239 changed files with 57567 additions and 1658 deletions
+32 -1
View File
@@ -148,6 +148,37 @@ internal fun protoOf(constructor: Any) =
internal fun <T> objectCreate(proto: T?) =
js("Object.create(proto)")
@Suppress("UNUSED_PARAMETER")
internal fun createThis(ctor: Ctor, box: dynamic): dynamic {
val self = js("Object.create(ctor.prototype)")
boxApply(self, box)
return self
}
@Suppress("UNUSED_PARAMETER")
internal fun boxApply(self: dynamic, box: dynamic) {
if (box !== VOID) js("Object.assign(self, box)")
}
@OptIn(JsIntrinsic::class)
@Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE", "REIFIED_TYPE_PARAMETER_NO_INLINE")
internal fun <reified T : Any> createExternalThis(
ctor: JsClass<T>,
superExternalCtor: JsClass<T>,
parameters: Array<Any?>,
box: dynamic
): T {
val selfCtor = if (box === VOID) {
ctor
} else {
val newCtor: dynamic = jsNewAnonymousClass(ctor)
js("Object.assign(newCtor.prototype, box)")
newCtor.constructor = ctor
newCtor
}
return js("Reflect.construct(superExternalCtor, parameters, selfCtor)")
}
@Suppress("UNUSED_PARAMETER")
internal fun defineProp(obj: Any, name: String, getter: Any?, setter: Any?) =
js("Object.defineProperty(obj, name, { configurable: true, get: getter, set: setter })")
js("Object.defineProperty(obj, name, { configurable: true, get: getter, set: setter })")
@@ -211,6 +211,10 @@ internal fun unreachable(): Nothing
@JsIntrinsic
internal fun jsArguments(): Any?
@JsIntrinsic
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
internal fun <reified T : Any> jsNewAnonymousClass(superClass: JsClass<T>): JsClass<T>
@JsIntrinsic
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") // TODO: mark `inline` and skip in inliner
internal fun <reified T : Any> jsClassIntrinsic(): JsClass<T>
@@ -5,8 +5,6 @@
package kotlin.js
import kotlin.reflect.KClass
@PublishedApi
internal fun <T : Enum<T>> enumValuesIntrinsic(): Array<T> =
throw IllegalStateException("Should be replaced by compiler")
@@ -52,7 +50,4 @@ internal annotation class JsFun(val code: String)
* This information is used for generating special tagged types inside d.ts files, for more strict usage of implicitly exported entities
*/
@Target(AnnotationTarget.CLASS)
internal annotation class JsImplicitExport()
@Target(AnnotationTarget.CLASS)
internal annotation class JsSubtypeCheckable(vararg val implements: KClass<*>)
internal annotation class JsImplicitExport
@@ -22,7 +22,7 @@ internal fun setMetadataFor(
""")
}
val metadata = metadataConstructor(name, associatedObjectKey, associatedObjects, suspendArity)
val metadata = metadataConstructor(name, associatedObjectKey, associatedObjects, suspendArity ?: js("[]"))
ctor.`$metadata$` = metadata
if (interfaces != null) {