[JS IR] Add a compiler option for generating name entries in sourcemaps
This commit is contained in:
committed by
Space Team
parent
8f237a60f7
commit
227864c6ec
+18
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsMainFunctionExecutionMode
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapNamesPolicy
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion as KotlinVersionDsl
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget as JvmTargetDsl
|
||||
import kotlin.reflect.KType
|
||||
@@ -118,6 +119,23 @@ open class DefaultValues(
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JsSourceMapNamesPolicies : DefaultValues(
|
||||
"null",
|
||||
typeOf<JsSourceMapNamesPolicy?>(),
|
||||
typeOf<String?>(),
|
||||
possibleValues = listOf(
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_NO,
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_SIMPLE_NAMES,
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_FQ_NAMES,
|
||||
).map { "\"$it\"" },
|
||||
fromKotlinOptionConverterProp = """
|
||||
this?.let { ${typeOf<JsSourceMapNamesPolicy>()}.fromPolicy(it) }
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this?.policy
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JsMain : DefaultValues(
|
||||
"${typeOf<JsMainFunctionExecutionMode>()}.${JsMainFunctionExecutionMode.CALL.name}",
|
||||
typeOf<JsMainFunctionExecutionMode>(),
|
||||
|
||||
+11
@@ -96,6 +96,17 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var sourceMapEmbedSources: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValues.JsSourceMapNamesPolicies::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-source-map-names-policy",
|
||||
valueDescription = "{no|simple-names|fully-qualified-names}",
|
||||
description = "How to map generated names to original names (IR backend only)"
|
||||
)
|
||||
var sourceMapNamesPolicy: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanTrueDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
|
||||
+4
@@ -30,6 +30,10 @@ public interface K2JsArgumentConstants {
|
||||
String SOURCE_MAP_SOURCE_CONTENT_NEVER = "never";
|
||||
String SOURCE_MAP_SOURCE_CONTENT_INLINING = "inlining";
|
||||
|
||||
String SOURCE_MAP_NAMES_POLICY_NO = "no";
|
||||
String SOURCE_MAP_NAMES_POLICY_SIMPLE_NAMES = "simple-names";
|
||||
String SOURCE_MAP_NAMES_POLICY_FQ_NAMES = "fully-qualified-names";
|
||||
|
||||
String RUNTIME_DIAGNOSTIC_LOG = "log";
|
||||
String RUNTIME_DIAGNOSTIC_EXCEPTION = "exception";
|
||||
}
|
||||
|
||||
@@ -576,9 +576,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
else
|
||||
SourceMapSourceEmbedding.INLINING
|
||||
if (sourceMapContentEmbedding == null) {
|
||||
val message = "Unknown source map source embedding mode: " + sourceMapEmbedContentString + ". Valid values are: " +
|
||||
StringUtil.join(sourceMapContentEmbeddingMap.keys, ", ")
|
||||
messageCollector.report(ERROR, message, null)
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Unknown source map source embedding mode: $sourceMapEmbedContentString. Valid values are: ${sourceMapContentEmbeddingMap.keys.joinToString()}"
|
||||
)
|
||||
sourceMapContentEmbedding = SourceMapSourceEmbedding.INLINING
|
||||
}
|
||||
configuration.put(JSConfigurationKeys.SOURCE_MAP_EMBED_SOURCES, sourceMapContentEmbedding)
|
||||
@@ -587,6 +588,20 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
messageCollector.report(WARNING, "source-map-embed-sources argument has no effect without source map", null)
|
||||
}
|
||||
|
||||
val sourceMapNamesPolicyString = arguments.sourceMapNamesPolicy
|
||||
var sourceMapNamesPolicy: SourceMapNamesPolicy? = if (sourceMapNamesPolicyString != null)
|
||||
sourceMapNamesPolicyMap[sourceMapNamesPolicyString]
|
||||
else
|
||||
SourceMapNamesPolicy.SIMPLE_NAMES
|
||||
if (sourceMapNamesPolicy == null) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Unknown source map names policy: $sourceMapNamesPolicyString. Valid values are: ${sourceMapNamesPolicyMap.keys.joinToString()}"
|
||||
)
|
||||
sourceMapNamesPolicy = SourceMapNamesPolicy.SIMPLE_NAMES
|
||||
}
|
||||
configuration.put(JSConfigurationKeys.SOURCEMAP_NAMES_POLICY, sourceMapNamesPolicy)
|
||||
|
||||
configuration.put(JSConfigurationKeys.PRINT_REACHABILITY_INFO, arguments.irDcePrintReachabilityInfo)
|
||||
configuration.put(JSConfigurationKeys.FAKE_OVERRIDE_VALIDATOR, arguments.fakeOverrideValidator)
|
||||
}
|
||||
@@ -615,6 +630,12 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING to SourceMapSourceEmbedding.INLINING
|
||||
)
|
||||
|
||||
private val sourceMapNamesPolicyMap = mapOf(
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_NO to SourceMapNamesPolicy.NO,
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_SIMPLE_NAMES to SourceMapNamesPolicy.SIMPLE_NAMES,
|
||||
K2JsArgumentConstants.SOURCE_MAP_NAMES_POLICY_FQ_NAMES to SourceMapNamesPolicy.FULLY_QUALIFIED_NAMES
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
doMain(K2JsIrCompiler(), args)
|
||||
|
||||
Reference in New Issue
Block a user