[K/JS] Introduce v2015 target

This commit is contained in:
Artem Kobzar
2024-03-06 12:21:38 +00:00
committed by Space Team
parent e989e6d397
commit 77f0cba23f
19 changed files with 115 additions and 84 deletions
@@ -33,6 +33,7 @@ annotation class GradleOption(
enum class DefaultValue {
BOOLEAN_FALSE_DEFAULT,
BOOLEAN_TRUE_DEFAULT,
BOOLEAN_NULL_DEFAULT,
STRING_NULL_DEFAULT,
EMPTY_STRING_LIST_DEFAULT,
EMPTY_STRING_ARRAY_DEFAULT,
@@ -166,7 +166,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
gradleInputType = GradleInputTypes.INPUT,
shouldGenerateDeprecatedKotlinOptions = true,
)
@Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for the specified ECMA version.")
@Argument(value = "-target", valueDescription = "{ es5, es2015 }", description = "Generate JS files for the specified ECMA version.")
var target: String? = null
set(value) {
checkFrozen()
@@ -192,12 +192,12 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@Argument(
value = "-module-kind",
valueDescription = "{plain|amd|commonjs|umd|es}",
description = "The kind of JS module generated by the compiler."
description = "The kind of JS module generated by the compiler. ES modules are enabled by default in case of ES2015 target usage"
)
var moduleKind: String? = MODULE_PLAIN
var moduleKind: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) MODULE_PLAIN else value
field = value
}
@GradleOption(
@@ -460,15 +460,15 @@ In combination with '-meta-info', this generates both IR and pre-IR versions of
}
@GradleOption(
value = DefaultValue.BOOLEAN_FALSE_DEFAULT,
value = DefaultValue.BOOLEAN_NULL_DEFAULT,
gradleInputType = GradleInputTypes.INPUT,
shouldGenerateDeprecatedKotlinOptions = true,
)
@Argument(
value = "-Xes-classes",
description = "Let generated JavaScript code use ES2015 classes."
description = "Let generated JavaScript code use ES2015 classes. Enabled by default in case of ES2015 target usage"
)
var useEsClasses = false
var useEsClasses: Boolean? = null
set(value) {
checkFrozen()
field = value
@@ -486,9 +486,9 @@ In combination with '-meta-info', this generates both IR and pre-IR versions of
@Argument(
value = "-Xes-generators",
description = "Enable ES2015 generator functions usage inside the compiled code"
description = "Enable ES2015 generator functions usage inside the compiled code. Enabled by default in case of ES2015 target usage"
)
var useEsGenerators = false
var useEsGenerators: Boolean? = null
set(value) {
checkFrozen()
field = value
@@ -657,7 +657,7 @@ In combination with '-meta-info', this generates both IR and pre-IR versions of
collector.deprecationWarn(irBaseClassInMetadata, false, "-Xir-base-class-in-metadata")
collector.deprecationWarn(irNewIr2Js, true, "-Xir-new-ir2js")
if (irPerFile && moduleKind != MODULE_ES) {
if (irPerFile && (moduleKind != MODULE_ES && target != ES_2015)) {
collector.report(
CompilerMessageSeverity.ERROR,
"Per-file compilation can't be used with any `moduleKind` except `es` (ECMAScript Modules)"
@@ -26,6 +26,8 @@ public interface K2JsArgumentConstants {
String MODULE_UMD = "umd";
String MODULE_ES = "es";
String ES_2015 = "es2015";
String GRANULARITY_WHOLE_PROGRAM = "whole-program";
String GRANULARITY_PER_MODULE = "per-module";
String GRANULARITY_PER_FILE = "per-file";
@@ -145,6 +145,15 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
}
private val K2JSCompilerArguments.targetVersion: EcmaVersion?
get() {
val targetString = target
return when {
targetString != null -> EcmaVersion.entries.firstOrNull { it.name == targetString }
else -> EcmaVersion.defaultVersion()
}
}
override fun doExecute(
arguments: K2JSCompilerArguments,
configuration: CompilerConfiguration,
@@ -153,6 +162,15 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
): ExitCode {
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
val targetVersion = arguments.targetVersion?.also {
configuration.put(JSConfigurationKeys.TARGET, it)
}
if (targetVersion == null) {
messageCollector.report(ERROR, "Unsupported ECMA version: ${arguments.target}")
return COMPILATION_ERROR
}
val pluginLoadResult = loadPlugins(paths, arguments, configuration)
if (pluginLoadResult != OK) return pluginLoadResult
@@ -182,7 +200,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
configuration.put(JSConfigurationKeys.WASM_USE_TRAPS_INSTEAD_OF_EXCEPTIONS, arguments.wasmUseTrapsInsteadOfExceptions)
configuration.putIfNotNull(JSConfigurationKeys.WASM_TARGET, arguments.wasmTarget?.let(WasmTarget::fromName))
configuration.put(JSConfigurationKeys.USE_ES6_CLASSES, arguments.useEsClasses)
configuration.put(JSConfigurationKeys.OPTIMIZE_GENERATED_JS, arguments.optimizeGeneratedJs)
val commonSourcesArray = arguments.commonSources
@@ -206,14 +223,21 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
val projectJs = environmentForJS.project
val configurationJs = environmentForJS.configuration
val sourcesFiles = environmentForJS.getSourceFiles()
val isES2015 = targetVersion == EcmaVersion.es2015
val moduleKind = configuration[JSConfigurationKeys.MODULE_KIND]
?: moduleKindMap[arguments.moduleKind]
?: ModuleKind.ES.takeIf { isES2015 }
?: ModuleKind.UMD
configurationJs.put(JSConfigurationKeys.MODULE_KIND, moduleKind)
configurationJs.put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
configurationJs.put(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME, arguments.renderInternalDiagnosticNames)
configurationJs.put(JSConfigurationKeys.PROPERTY_LAZY_INITIALIZATION, arguments.irPropertyLazyInitialization)
configurationJs.put(JSConfigurationKeys.GENERATE_POLYFILLS, arguments.generatePolyfills)
configurationJs.put(JSConfigurationKeys.GENERATE_DTS, arguments.generateDts)
configurationJs.put(JSConfigurationKeys.COMPILE_SUSPEND_AS_JS_GENERATOR, arguments.useEsGenerators)
configurationJs.put(JSConfigurationKeys.GENERATE_INLINE_ANONYMOUS_FUNCTIONS, arguments.irGenerateInlineAnonymousFunctions)
configurationJs.put(JSConfigurationKeys.USE_ES6_CLASSES, arguments.useEsClasses ?: isES2015)
configurationJs.put(JSConfigurationKeys.COMPILE_SUSPEND_AS_JS_GENERATOR, arguments.useEsGenerators ?: isES2015)
arguments.platformArgumentsProviderJsExpression?.let {
configurationJs.put(JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS, it)
@@ -294,8 +318,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
}
if (arguments.irProduceJs) {
val moduleKind = configurationJs[JSConfigurationKeys.MODULE_KIND] ?: error("cannot get 'module kind' from configuration")
messageCollector.report(INFO, "Produce executable: $outputDirPath")
messageCollector.report(INFO, "Cache directory: ${arguments.cacheDirectory}")
@@ -686,11 +708,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
) {
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
if (arguments.target != null) {
assert("v5" == arguments.target) { "Unsupported ECMA version: " + arguments.target!! }
}
configuration.put(JSConfigurationKeys.TARGET, EcmaVersion.defaultVersion())
if (arguments.sourceMap) {
configuration.put(JSConfigurationKeys.SOURCE_MAP, true)
if (arguments.sourceMapPrefix != null) {
@@ -733,19 +750,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
configuration.put(JSConfigurationKeys.FRIEND_PATHS, friendPaths)
}
val moduleKindName = arguments.moduleKind
var moduleKind: ModuleKind? = if (moduleKindName != null) moduleKindMap[moduleKindName] else ModuleKind.PLAIN
if (moduleKind == null) {
messageCollector.report(
ERROR, "Unknown module kind: $moduleKindName. Valid values are: plain, amd, commonjs, umd, es", null
)
moduleKind = ModuleKind.PLAIN
}
if (arguments.wasm) {
// K/Wasm support ES modules only.
moduleKind = ModuleKind.ES
configuration.put(JSConfigurationKeys.MODULE_KIND, ModuleKind.ES)
}
configuration.put(JSConfigurationKeys.MODULE_KIND, moduleKind)
configuration.putIfNotNull(JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER, services[IncrementalDataProvider::class.java])
configuration.putIfNotNull(JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER, services[IncrementalResultsConsumer::class.java])
+2 -2
View File
@@ -50,8 +50,8 @@ where advanced options include:
JS expression that will be executed in runtime and be put as an Array<String> parameter of the main function
-Xstrict-implicit-export-types Generate strict types for implicitly exported entities inside d.ts files. This is available in the IR backend only.
-Xtyped-arrays Translate primitive arrays into JS typed arrays.
-Xes-classes Let generated JavaScript code use ES2015 classes.
-Xes-generators Enable ES2015 generator functions usage inside the compiled code
-Xes-classes Let generated JavaScript code use ES2015 classes. Enabled by default in case of ES2015 target usage
-Xes-generators Enable ES2015 generator functions usage inside the compiled code. Enabled by default in case of ES2015 target usage
-Xwasm Use the experimental WebAssembly compiler backend.
-Xwasm-debug-info Add debug info to the compiled WebAssembly module.
-Xwasm-enable-array-range-checks
+2 -2
View File
@@ -4,7 +4,7 @@ where possible options include:
-main {call|noCall} Specify whether the 'main' function should be called upon execution.
-meta-info Generate .meta.js and .kjsm files with metadata. Use this to create a library.
-module-kind {plain|amd|commonjs|umd|es}
The kind of JS module generated by the compiler.
The kind of JS module generated by the compiler. ES modules are enabled by default in case of ES2015 target usage
-ir-output-name Base name of generated files.
-no-stdlib Don't automatically include the default Kotlin/JS stdlib in compilation dependencies.
-ir-output-dir <directory> Destination for generated files.
@@ -16,7 +16,7 @@ where possible options include:
-source-map-names-policy {no|simple-names|fully-qualified-names}
Mode for mapping generated names to original names (IR backend only).
-source-map-prefix Add the specified prefix to the paths in the source map.
-target { v5 } Generate JS files for the specified ECMA version.
-target { es5, es2015 } Generate JS files for the specified ECMA version.
-Werror Report an error if there are any warnings.
-api-version <version> Allow using declarations from only the specified version of bundled libraries.
-X Print a synopsis of advanced options.
@@ -217,7 +217,7 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
configuration.put(JSConfigurationKeys.FRIEND_PATHS, friends)
configuration.put(CommonConfigurationKeys.MODULE_NAME, module.name.removeSuffix(OLD_MODULE_SUFFIX))
configuration.put(JSConfigurationKeys.TARGET, EcmaVersion.v5)
configuration.put(JSConfigurationKeys.TARGET, EcmaVersion.es5)
val errorIgnorancePolicy = registeredDirectives[ERROR_POLICY].singleOrNull() ?: ErrorTolerancePolicy.DEFAULT
configuration.put(JSConfigurationKeys.ERROR_TOLERANCE_POLICY, errorIgnorancePolicy)
@@ -35,6 +35,8 @@ open class DefaultValues(
object BooleanTrueDefault : DefaultBoolean(true)
object BooleanNullDefault : DefaultValues("null", typeOf<Boolean?>(), typeOf<Boolean?>())
object StringNullDefault : DefaultValues("null", typeOf<String?>(), typeOf<String?>())
object EmptyStringListDefault : DefaultValues("emptyList<String>()", typeOf<List<String>>(), typeOf<List<String>>())
@@ -91,22 +93,22 @@ open class DefaultValues(
)
object JsEcmaVersions : DefaultValues(
"\"v5\"",
"\"es5\"",
typeOf<String>(),
typeOf<String>(),
possibleValues = listOf("\"v5\"")
possibleValues = listOf("\"es5\"", "\"es2015\"")
)
object JsModuleKinds : DefaultValues(
"${typeOf<JsModuleKind>()}.${JsModuleKind.MODULE_PLAIN.name}",
typeOf<JsModuleKind>(),
typeOf<String>(),
"null",
typeOf<JsModuleKind?>(),
typeOf<String?>(),
possibleValues = listOf("\"plain\"", "\"amd\"", "\"commonjs\"", "\"umd\""),
fromKotlinOptionConverterProp = """
${typeOf<JsModuleKind>()}.fromKind(this)
this?.let { ${typeOf<JsModuleKind>()}.fromKind(it) }
""".trimIndent(),
toKotlinOptionConverterProp = """
this.kind
this?.kind
""".trimIndent()
)
@@ -952,6 +952,7 @@ private val KProperty1<*, *>.gradleValues: DefaultValues
when (this) {
DefaultValue.BOOLEAN_FALSE_DEFAULT -> DefaultValues.BooleanFalseDefault
DefaultValue.BOOLEAN_TRUE_DEFAULT -> DefaultValues.BooleanTrueDefault
DefaultValue.BOOLEAN_NULL_DEFAULT -> DefaultValues.BooleanNullDefault
DefaultValue.STRING_NULL_DEFAULT -> DefaultValues.StringNullDefault
DefaultValue.EMPTY_STRING_LIST_DEFAULT -> DefaultValues.EmptyStringListDefault
DefaultValue.EMPTY_STRING_ARRAY_DEFAULT -> DefaultValues.EmptyStringArrayDefault
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.js.config;
import org.jetbrains.annotations.NotNull;
public enum EcmaVersion {
v3, v5;
es5, es2015;
@NotNull
public static EcmaVersion defaultVersion() {
return v5;
return es5;
}
}
@@ -36,7 +36,7 @@ public final class JsTestUtils {
@NotNull
public static EnumSet<EcmaVersion> successOnEcmaV5() {
return EnumSet.of(EcmaVersion.v5);
return EnumSet.of(EcmaVersion.es5);
}
@NotNull
@@ -336,7 +336,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 getUseEsClasses ()Ljava/lang/Boolean;
public abstract fun setFriendModulesDisabled (Z)V
public abstract fun setMain (Ljava/lang/String;)V
public abstract fun setMetaInfo (Z)V
@@ -349,7 +349,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 abstract fun setUseEsClasses (Ljava/lang/Boolean;)V
}
public final class org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions$DefaultImpls {
@@ -370,7 +370,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 getUseEsClasses (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;)Ljava/lang/Boolean;
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
@@ -390,7 +390,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 setUseEsClasses (Lorg/jetbrains/kotlin/gradle/dsl/KotlinJsOptions;Ljava/lang/Boolean;)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
}
@@ -38,12 +38,13 @@ interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommon
val metaInfo: org.gradle.api.provider.Property<kotlin.Boolean>
/**
* The kind of JS module generated by the compiler.
* The kind of JS module generated by the compiler. ES modules are enabled by default in case of ES2015 target usage
*
* Possible values: "plain", "amd", "commonjs", "umd"
*
* Default value: JsModuleKind.MODULE_PLAIN
* Default value: null
*/
@get:org.gradle.api.tasks.Optional
@get:org.gradle.api.tasks.Input
val moduleKind: org.gradle.api.provider.Property<org.jetbrains.kotlin.gradle.dsl.JsModuleKind>
@@ -107,9 +108,9 @@ interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommon
/**
* Generate JS files for the specified ECMA version.
*
* Possible values: "v5"
* Possible values: "es5", "es2015"
*
* Default value: "v5"
* Default value: "es5"
*/
@get:org.gradle.api.tasks.Input
val target: org.gradle.api.provider.Property<kotlin.String>
@@ -123,10 +124,11 @@ interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommon
val typedArrays: org.gradle.api.provider.Property<kotlin.Boolean>
/**
* Let generated JavaScript code use ES2015 classes.
* Let generated JavaScript code use ES2015 classes. Enabled by default in case of ES2015 target usage
*
* Default value: false
* Default value: null
*/
@get:org.gradle.api.tasks.Optional
@get:org.gradle.api.tasks.Input
val useEsClasses: org.gradle.api.provider.Property<kotlin.Boolean>
}
@@ -51,19 +51,19 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
get() = options.metaInfo.get()
set(value) = options.metaInfo.set(value)
private val kotlin.String.moduleKindCompilerOption get() = org.jetbrains.kotlin.gradle.dsl.JsModuleKind.fromKind(this)
private val kotlin.String?.moduleKindCompilerOption get() = this?.let { org.jetbrains.kotlin.gradle.dsl.JsModuleKind.fromKind(it) }
private val org.jetbrains.kotlin.gradle.dsl.JsModuleKind.moduleKindKotlinOption get() = this.kind
private val org.jetbrains.kotlin.gradle.dsl.JsModuleKind?.moduleKindKotlinOption get() = this?.kind
/**
* The kind of JS module generated by the compiler.
* The kind of JS module generated by the compiler. ES modules are enabled by default in case of ES2015 target usage
*
* Possible values: "plain", "amd", "commonjs", "umd"
*
* Default value: JsModuleKind.MODULE_PLAIN
* Default value: null
*/
var moduleKind: kotlin.String
get() = options.moduleKind.get().moduleKindKotlinOption
var moduleKind: kotlin.String?
get() = options.moduleKind.orNull.moduleKindKotlinOption
set(value) = options.moduleKind.set(value.moduleKindCompilerOption)
/**
@@ -136,9 +136,9 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
/**
* Generate JS files for the specified ECMA version.
*
* Possible values: "v5"
* Possible values: "es5", "es2015"
*
* Default value: "v5"
* Default value: "es5"
*/
var target: kotlin.String
get() = options.target.get()
@@ -154,11 +154,11 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
set(value) = options.typedArrays.set(value)
/**
* Let generated JavaScript code use ES2015 classes.
* Let generated JavaScript code use ES2015 classes. Enabled by default in case of ES2015 target usage
*
* Default value: false
* Default value: null
*/
var useEsClasses: kotlin.Boolean
get() = options.useEsClasses.get()
var useEsClasses: kotlin.Boolean?
get() = options.useEsClasses.orNull
set(value) = options.useEsClasses.set(value)
}
@@ -20,7 +20,7 @@ internal abstract class KotlinJsCompilerOptionsDefault @javax.inject.Inject cons
objectFactory.property(kotlin.Boolean::class.java).convention(true)
override val moduleKind: org.gradle.api.provider.Property<org.jetbrains.kotlin.gradle.dsl.JsModuleKind> =
objectFactory.property(org.jetbrains.kotlin.gradle.dsl.JsModuleKind::class.java).convention(org.jetbrains.kotlin.gradle.dsl.JsModuleKind.MODULE_PLAIN)
objectFactory.property(org.jetbrains.kotlin.gradle.dsl.JsModuleKind::class.java)
override val moduleName: org.gradle.api.provider.Property<kotlin.String> =
objectFactory.property(kotlin.String::class.java)
@@ -42,11 +42,11 @@ internal abstract class KotlinJsCompilerOptionsDefault @javax.inject.Inject cons
objectFactory.property(kotlin.String::class.java)
override val target: org.gradle.api.provider.Property<kotlin.String> =
objectFactory.property(kotlin.String::class.java).convention("v5")
objectFactory.property(kotlin.String::class.java).convention("es5")
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)
objectFactory.property(kotlin.Boolean::class.java)
}
@@ -15,7 +15,7 @@ internal object KotlinJsCompilerOptionsHelper {
args.friendModulesDisabled = from.friendModulesDisabled.get()
args.main = from.main.get().mode
args.metaInfo = from.metaInfo.get()
args.moduleKind = from.moduleKind.get().kind
args.moduleKind = from.moduleKind.orNull?.kind
args.moduleName = from.moduleName.orNull
args.noStdlib = from.noStdlib.get()
args.sourceMap = from.sourceMap.get()
@@ -24,7 +24,7 @@ internal object KotlinJsCompilerOptionsHelper {
args.sourceMapPrefix = from.sourceMapPrefix.orNull
args.target = from.target.get()
args.typedArrays = from.typedArrays.get()
args.useEsClasses = from.useEsClasses.get()
args.useEsClasses = from.useEsClasses.orNull
}
internal fun syncOptionsAsConvention(
@@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("PackageDirectoryMismatch")
@file:Suppress("PackageDirectoryMismatch", "DEPRECATION", "TYPEALIAS_EXPANSION_DEPRECATION")
// Old package for compatibility
package org.jetbrains.kotlin.gradle.plugin.mpp
@@ -13,8 +13,12 @@ import org.gradle.api.Action
import org.gradle.api.attributes.AttributeContainer
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
import org.jetbrains.kotlin.gradle.plugin.DeprecatedHasCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
@@ -23,7 +27,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import javax.inject.Inject
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION", "DEPRECATION")
open class KotlinJsCompilation @Inject internal constructor(
compilation: KotlinCompilationImpl,
) : DeprecatedAbstractKotlinCompilationToRunnableFiles<KotlinJsOptions>(compilation),
@@ -102,7 +105,15 @@ val KotlinJsCompilation.fileExtension: Provider<String>
get() {
val isWasm = platformType == KotlinPlatformType.wasm
@Suppress("DEPRECATION")
return compilerOptions.options.moduleKind.map { moduleKind ->
return compilerOptions.options.moduleKind
.orElse(
compilerOptions.options.target.map {
if (it == K2JsArgumentConstants.ES_2015) {
JsModuleKind.MODULE_ES
} else JsModuleKind.MODULE_UMD
}
)
.map { moduleKind ->
if (isWasm || moduleKind == JsModuleKind.MODULE_ES) {
"mjs"
} else {
@@ -13,6 +13,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.ES_2015
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
@@ -34,6 +35,7 @@ import org.jetbrains.kotlin.gradle.utils.doNotTrackStateCompat
import org.jetbrains.kotlin.gradle.utils.domainObjectSet
import org.jetbrains.kotlin.gradle.utils.relativeOrAbsolute
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
import org.jetbrains.kotlin.utils.addToStdlib.runIf
import javax.inject.Inject
abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
@@ -274,7 +276,11 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
this.inputFilesDirectory.set(inputFilesDirectory)
val platformType = binary.compilation.platformType
val moduleKind = binary.linkTask.flatMap { it.compilerOptions.moduleKind }
val moduleKind = binary.linkTask.flatMap { task ->
task.compilerOptions.moduleKind.orElse(task.compilerOptions.target.map {
if (it == ES_2015) JsModuleKind.MODULE_ES else JsModuleKind.MODULE_UMD
})
}
this.entryModuleName.set(entryModuleName)
this.esModules.convention(
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.gradle.targets.js.ir
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
@@ -15,7 +14,6 @@ open class KotlinJsIrTargetConfigurator :
internal companion object {
internal fun KotlinJsCompilerOptions.configureJsDefaultOptions() {
moduleKind.convention(JsModuleKind.MODULE_UMD)
sourceMap.convention(true)
sourceMapEmbedSources.convention(JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_NEVER)
}