[K/JS] Add support of compilation with ES-classes
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -252,6 +252,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinJsCompiler
|
||||
public abstract fun getSourceMapPrefix ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getTarget ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getTypedArrays ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getUseEsClasses ()Lorg/gradle/api/provider/Property;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinJsDceCompilerToolOptions : org/jetbrains/kotlin/gradle/dsl/KotlinCommonCompilerToolOptions {
|
||||
@@ -297,6 +298,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions
|
||||
public abstract fun getSourceMapPrefix ()Ljava/lang/String;
|
||||
public abstract fun getTarget ()Ljava/lang/String;
|
||||
public abstract fun getTypedArrays ()Z
|
||||
public abstract fun getUseEsClasses ()Z
|
||||
public abstract fun setFriendModulesDisabled (Z)V
|
||||
public abstract fun setMain (Ljava/lang/String;)V
|
||||
public abstract fun setMetaInfo (Z)V
|
||||
@@ -310,6 +312,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions
|
||||
public abstract fun setSourceMapPrefix (Ljava/lang/String;)V
|
||||
public abstract fun setTarget (Ljava/lang/String;)V
|
||||
public abstract fun setTypedArrays (Z)V
|
||||
public abstract fun setUseEsClasses (Z)V
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions$DefaultImpls {
|
||||
@@ -331,6 +334,7 @@ public final class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions$DefaultImpls
|
||||
public static fun getSuppressWarnings (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Z
|
||||
public static fun getTarget (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Ljava/lang/String;
|
||||
public static fun getTypedArrays (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Z
|
||||
public static fun getUseEsClasses (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Z
|
||||
public static fun getUseK2 (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Z
|
||||
public static fun getVerbose (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Z
|
||||
public static fun setAllWarningsAsErrors (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
@@ -351,6 +355,7 @@ public final class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions$DefaultImpls
|
||||
public static fun setSuppressWarnings (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
public static fun setTarget (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Ljava/lang/String;)V
|
||||
public static fun setTypedArrays (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
public static fun setUseEsClasses (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
public static fun setUseK2 (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
public static fun setVerbose (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Z)V
|
||||
}
|
||||
|
||||
+7
@@ -107,4 +107,11 @@ interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommon
|
||||
*/
|
||||
@get:org.gradle.api.tasks.Input
|
||||
val typedArrays: org.gradle.api.provider.Property<kotlin.Boolean>
|
||||
|
||||
/**
|
||||
* Generated JavaScript will use ES2015 classes.
|
||||
* Default value: false
|
||||
*/
|
||||
@get:org.gradle.api.tasks.Input
|
||||
val useEsClasses: org.gradle.api.provider.Property<kotlin.Boolean>
|
||||
}
|
||||
|
||||
+8
@@ -133,4 +133,12 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
var typedArrays: kotlin.Boolean
|
||||
get() = options.typedArrays.get()
|
||||
set(value) = options.typedArrays.set(value)
|
||||
|
||||
/**
|
||||
* Generated JavaScript will use ES2015 classes.
|
||||
* Default value: false
|
||||
*/
|
||||
var useEsClasses: kotlin.Boolean
|
||||
get() = options.useEsClasses.get()
|
||||
set(value) = options.useEsClasses.set(value)
|
||||
}
|
||||
|
||||
+5
@@ -49,6 +49,9 @@ internal abstract class KotlinJsCompilerOptionsDefault @javax.inject.Inject cons
|
||||
override val typedArrays: org.gradle.api.provider.Property<kotlin.Boolean> =
|
||||
objectFactory.property(kotlin.Boolean::class.java).convention(true)
|
||||
|
||||
override val useEsClasses: org.gradle.api.provider.Property<kotlin.Boolean> =
|
||||
objectFactory.property(kotlin.Boolean::class.java).convention(false)
|
||||
|
||||
internal fun fillCompilerArguments(args: org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments) {
|
||||
super.fillCompilerArguments(args)
|
||||
args.friendModulesDisabled = friendModulesDisabled.get()
|
||||
@@ -64,6 +67,7 @@ internal abstract class KotlinJsCompilerOptionsDefault @javax.inject.Inject cons
|
||||
args.sourceMapPrefix = sourceMapPrefix.orNull
|
||||
args.target = target.get()
|
||||
args.typedArrays = typedArrays.get()
|
||||
args.useEsClasses = useEsClasses.get()
|
||||
}
|
||||
|
||||
internal fun fillDefaultValues(args: org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments) {
|
||||
@@ -81,5 +85,6 @@ internal abstract class KotlinJsCompilerOptionsDefault @javax.inject.Inject cons
|
||||
args.sourceMapPrefix = null
|
||||
args.target = "v5"
|
||||
args.typedArrays = true
|
||||
args.useEsClasses = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user