Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit ea24266

Browse files
Gregory Lureauglureau
authored andcommitted
Sealed class: generate an abstract class instead.
1 parent 9e9ad66 commit ea24266

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

compiler/src/main/kotlin/deezer/kustomexport/compiler/js/pattern/class/SealedClassTransformer.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.squareup.kotlinpoet.TypeSpec
3030
import deezer.kustomexport.compiler.js.SealedClassDescriptor
3131
import deezer.kustomexport.compiler.js.jsExport
3232
import deezer.kustomexport.compiler.js.jsPackage
33+
import deezer.kustomexport.compiler.js.mapping.INDENTATION
3334

3435
fun SealedClassDescriptor.transform() = transformSealedClass(this)
3536

@@ -85,8 +86,9 @@ fun transformSealedClass(origin: SealedClassDescriptor): FileSpec {
8586
.beginControlFlow("return·when·(this)")
8687
.also {
8788
origin.subClasses.forEach { subClass ->
88-
it.addStatement("is %T -> export${subClass.classSimpleName}()", subClass.asClassName)
89+
it.addStatement("$INDENTATION${INDENTATION}is %T -> export${subClass.classSimpleName}()", subClass.asClassName)
8990
}
91+
it.addStatement("$INDENTATION${INDENTATION}else -> error(\"Cannot export \$this\")")
9092
if (origin.subClasses.isEmpty()) {
9193
it.addComment("TODO: no subclasses found, bad configuration?")
9294
}
@@ -101,8 +103,9 @@ fun transformSealedClass(origin: SealedClassDescriptor): FileSpec {
101103
.also {
102104
origin.subClasses.forEach { subClass ->
103105
val exportedSubClass = ClassName(subClass.packageName.jsPackage(), subClass.classSimpleName)
104-
it.addStatement("is %T -> import${subClass.classSimpleName}()", exportedSubClass)
106+
it.addStatement("$INDENTATION${INDENTATION}is %T -> import${subClass.classSimpleName}()", exportedSubClass)
105107
}
108+
it.addStatement("$INDENTATION${INDENTATION}else -> error(\"Cannot export \$this\")")
106109
if (origin.subClasses.isEmpty()) {
107110
it.addComment("TODO: no subclasses found, bad configuration?")
108111
}
@@ -120,7 +123,7 @@ fun transformSealedClass(origin: SealedClassDescriptor): FileSpec {
120123
.addType(
121124
TypeSpec.classBuilder(origin.classSimpleName)
122125
.addAnnotation(jsExport)
123-
.addModifiers(KModifier.SEALED)
126+
.addModifiers(KModifier.ABSTRACT) // Not SEALED, because https://youtrack.jetbrains.com/issue/KT-39193
124127
.also { b ->
125128
origin.supers.forEach { supr ->
126129
if (supr.parameters == null) {

samples/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"compilerOptions": {
3-
"moduleResolution": "node"
3+
"moduleResolution": "node",
4+
"strict": true,
5+
"noEmitOnError": true
46
}
57
}

0 commit comments

Comments
 (0)