diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt index ca8ad59c6c0..805e6bedab6 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt @@ -15,5 +15,6 @@ object JsLoweredDeclarationOrigin : IrDeclarationOrigin { object BRIDGE_WITHOUT_STABLE_NAME : IrDeclarationOriginImpl("BRIDGE_WITHOUT_STABLE_NAME") object OBJECT_GET_INSTANCE_FUNCTION : IrDeclarationOriginImpl("OBJECT_GET_INSTANCE_FUNCTION") object JS_SHADOWED_EXPORT : IrDeclarationOriginImpl("JS_SHADOWED_EXPORT") + object JS_SHADOWED_DEFAULT_PARAMETER : IrDeclarationOriginImpl("JS_SHADOWED_DEFAULT_PARAMETER") object ENUM_GET_INSTANCE_FUNCTION : IrDeclarationOriginImpl("ENUM_GET_INSTANCE_FUNCTION") } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModel.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModel.kt index b4419df4d7f..5b72f668bcb 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModel.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModel.kt @@ -80,7 +80,8 @@ data class ExportedClass( class ExportedParameter( val name: String, - val type: ExportedType + val type: ExportedType, + val hasDefaultValue: Boolean = false ) sealed class ExportedType { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt index 8a001c934ad..6d7002d1f7f 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt @@ -110,7 +110,11 @@ class ExportModelGenerator( if (parameterName in allReservedWords) parameterName = "_$parameterName" - return ExportedParameter(parameterName, exportType(parameter.type)) + return ExportedParameter( + parameterName, + exportType(parameter.type), + parameter.origin == JsLoweredDeclarationOrigin.JS_SHADOWED_DEFAULT_PARAMETER + ) } private fun exportProperty(property: IrProperty): ExportedDeclaration? { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelToTsDeclarations.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelToTsDeclarations.kt index beb4f53656f..c63e09e89ca 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelToTsDeclarations.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelToTsDeclarations.kt @@ -268,8 +268,12 @@ fun ExportedClass.toReadonlyProperty(): ExportedProperty { ) } -fun ExportedParameter.toTypeScript(indent: String): String = - "${sanitizeName(name, withHash = false)}: ${type.toTypeScript(indent)}" +fun ExportedParameter.toTypeScript(indent: String): String { + val name = sanitizeName(name, withHash = false) + val type = type.toTypeScript(indent) + val questionMark = if (hasDefaultValue) "?" else "" + return "$name$questionMark: $type" +} fun ExportedType.toTypeScript(indent: String): String = when (this) { is ExportedType.Primitive -> typescript diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExportedDefaultParameterStub.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExportedDefaultParameterStub.kt index 76172115acf..3621318af4c 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExportedDefaultParameterStub.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExportedDefaultParameterStub.kt @@ -112,7 +112,10 @@ class ExportedDefaultParameterStub(val context: JsIrBackendContext) : Declaratio exportedDefaultStubFun.parent = declaration.parent exportedDefaultStubFun.copyParameterDeclarationsFrom(declaration) exportedDefaultStubFun.returnType = declaration.returnType.remapTypeParameters(declaration, exportedDefaultStubFun) - exportedDefaultStubFun.valueParameters.forEach { it.defaultValue = null } + exportedDefaultStubFun.valueParameters.forEach { + it.defaultValue = null + it.origin = JsLoweredDeclarationOrigin.JS_SHADOWED_DEFAULT_PARAMETER + } declaration.origin = JsLoweredDeclarationOrigin.JS_SHADOWED_EXPORT