[K/JS] Introduce the ability to consume platform-specific cli arguments inside the main function ^KT-16981 Fixed

This commit is contained in:
Artem Kobzar
2023-11-18 11:01:34 +00:00
committed by Space Team
parent ceded87a3a
commit 1832f5a3f7
15 changed files with 93 additions and 3 deletions
@@ -105,6 +105,7 @@ class JsIrBackendContext(
val devMode = configuration[JSConfigurationKeys.DEVELOPER_MODE] ?: false
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
override val es6mode = configuration[JSConfigurationKeys.USE_ES6_CLASSES] ?: false
val platformArgumentsProviderJsExpression = configuration[JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS]
val externalPackageFragment = mutableMapOf<IrFileSymbol, IrFile>()
@@ -179,7 +179,13 @@ internal class ICHasher {
hashCalculator.update(value.ordinal)
}
hashCalculator.updateConfigKeys(config, listOf(JSConfigurationKeys.SOURCE_MAP_PREFIX)) { value: String ->
hashCalculator.updateConfigKeys(
config,
listOf(
JSConfigurationKeys.SOURCE_MAP_PREFIX,
JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS
)
) { value: String ->
hashCalculator.update(value)
}
@@ -72,7 +72,11 @@ class MainFunctionCallWrapperLowering(private val context: JsIrBackendContext) :
return listOfNotNull(
runIf(generateArgv) {
JsIrBuilder.buildArray(
context.platformArgumentsProviderJsExpression?.let {
JsIrBuilder.buildCall(context.intrinsics.jsCode).apply {
putValueArgument(0, it.toIrConst(context.irBuiltIns.stringType))
}
} ?: JsIrBuilder.buildArray(
mainFunctionArgs.map { it.toIrConst(context.irBuiltIns.stringType) },
valueParameters.first().type,
context.irBuiltIns.stringType