Skip to content

Commit

Permalink
Export deserialization constructor from JS module
Browse files Browse the repository at this point in the history
  • Loading branch information
sandwwraith committed Jul 1, 2019
1 parent fa9edf0 commit ffc4096
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.CompilationException
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.js.backend.ast.*
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
import org.jetbrains.kotlin.js.translate.context.Namer
Expand Down Expand Up @@ -121,6 +121,7 @@ class SerializableJsTranslator(

f.name = context.getInnerNameForDescriptor(constructorDescriptor)
context.addDeclarationStatement(f.makeStmt())
context.export(constructorDescriptor)
}

private fun JsBlockBuilder.generateSuperNonSerializableCall(superClass: ClassDescriptor, thisParameter: JsExpression) {
Expand All @@ -139,7 +140,7 @@ class SerializableJsTranslator(
thisParameter: JsExpression,
propertiesStart: Int
): Int {
val constrDesc = KSerializerDescriptorResolver.createLoadConstructorDescriptor(superClass, context.bindingContext())
val constrDesc = superClass.constructors.single(ClassConstructorDescriptor::isSerializationCtor)
val constrRef = context.getInnerNameForDescriptor(constrDesc).makeRef()
val superProperties = SerializableProperties(superClass, bindingContext).serializableProperties
val superSlots = superProperties.bitMaskSlotCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory

internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean =
kind == CallableMemberDescriptor.Kind.SYNTHESIZED && valueParameters.lastOrNull()?.name == SerialEntityNames.dummyParamName
internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean {
/*kind == CallableMemberDescriptor.Kind.SYNTHESIZED does not work because DeserializedClassConstructorDescriptor loses its kind*/
return valueParameters.lastOrNull()?.run {
name == SerialEntityNames.dummyParamName && type.constructor.declarationDescriptor?.classId == ClassId(
SerializationPackages.packageFqName,
SerialEntityNames.SERIAL_CTOR_MARKER_NAME
)
} == true
}

// finds constructor (KSerializer<T0>, KSerializer<T1>...) on a KSerializer<T<T0, T1...>>
internal fun findSerializerConstructorForTypeArgumentsSerializers(
Expand Down

0 comments on commit ffc4096

Please sign in to comment.